Skip to content

Commit

Permalink
fix: Proxy: do not trust input - always set own value for 'X-Origin-I…
Browse files Browse the repository at this point in the history
…P' (#354)

An external packet received by the proxy can have any value in
'X-Origin-IP' - we can't trust it, it's best to set it on our own

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Aug 7, 2024
1 parent dc7de14 commit 1554fc8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/Controller/ExAppProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,16 @@ private function buildHeadersWithExclude(ExApp $exApp, string $exAppRoute, array
break;
}
}
if (empty($headersToExclude)) {
return $headers;
if (!in_array('x-origin-ip', $headersToExclude)) {
$headersToExclude[] = 'x-origin-ip';
}
$headersToExclude[] = 'authorization-app-api';
foreach ($headers as $key => $value) {
if (in_array(strtolower($key), $headersToExclude)) {
unset($headers[$key]);
}
}
if (!isset($headers['X-Origin-IP'])) {
$headers['X-Origin-IP'] = $this->request->getRemoteAddress();
}
$headers['X-Origin-IP'] = $this->request->getRemoteAddress();
return $headers;
}
}

0 comments on commit 1554fc8

Please sign in to comment.