Skip to content

Commit

Permalink
Followed change of trusted_headers and trusted_proxies in Symfony…
Browse files Browse the repository at this point in the history
… 7.2 (#149)
  • Loading branch information
okorneliuk authored Dec 6, 2024
1 parent 025fab9 commit afa9d23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: mbstring,intl,mongodb-mongodb/mongo-php-driver@master
extensions: mbstring,intl,mongodb
tools: composer:v2
- name: Install dependencies
run: |
Expand Down
30 changes: 23 additions & 7 deletions src/Worker/HttpWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class HttpWorker implements WorkerInterface
private HttpFoundationWorkerInterface $httpFoundationWorker;

private array $trustedProxies = [];
private int $trustedHeaders = 0;
private int $trustedHeaderSet = 0;
private bool $shouldRedeclareTrustedProxies = false;

/**
Expand All @@ -52,20 +52,36 @@ public function __construct(
$dependencies = $container->get(HttpDependencies::class);
$this->dependencies = $dependencies;

if ($container->hasParameter('kernel.trusted_proxies') && $container->hasParameter('kernel.trusted_headers')) {
$trustedProxies = $container->getParameter('kernel.trusted_proxies');
if ($container->hasParameter('kernel.trusted_proxies') && $container->hasParameter('kernel.trusted_headers') && $trustedProxies = $container->getParameter('kernel.trusted_proxies')) {
$trustedHeaders = $container->getParameter('kernel.trusted_headers');

if (!\is_int($trustedHeaders)) {
throw new \InvalidArgumentException('Parameter "kernel.trusted_headers" must be an integer');
if (\is_string($trustedHeaders)) {
$trustedHeaders = array_map('trim', explode(',', $trustedHeaders));
}

if (\is_array($trustedHeaders)) {
$trustedHeaderSet = 0;

foreach ($trustedHeaders as $header) {
if (!\defined($const = Request::class.'::HEADER_'.strtr(strtoupper($header), '-', '_'))) {
throw new \InvalidArgumentException(sprintf('The trusted header "%s" is not supported.', $header));
}
$trustedHeaderSet |= \constant($const);
}
} else {
$trustedHeaderSet = $trustedHeaders ?? (Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
}

if (!\is_int($trustedHeaderSet)) {
throw new \UnexpectedValueException(sprintf('Unexpected type "%s" of trusted header', \gettype($trustedHeaderSet)));
}

if (!\is_string($trustedProxies) && !\is_array($trustedProxies)) {
throw new \InvalidArgumentException('Parameter "kernel.trusted_proxies" must be a string or an array');
}

$this->trustedProxies = \is_array($trustedProxies) ? $trustedProxies : array_map('trim', explode(',', $trustedProxies));
$this->trustedHeaders = $trustedHeaders;
$this->trustedHeaderSet = $trustedHeaderSet;
}

$this->shouldRedeclareTrustedProxies = \in_array('REMOTE_ADDR', $this->trustedProxies, true);
Expand All @@ -92,7 +108,7 @@ public function start(): void

while ($request = $this->httpFoundationWorker->waitRequest()) {
if ($this->shouldRedeclareTrustedProxies) {
Request::setTrustedProxies($this->trustedProxies, $this->trustedHeaders);
Request::setTrustedProxies($this->trustedProxies, $this->trustedHeaderSet);

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.

Check failure on line 111 in src/Worker/HttpWorker.php

View workflow job for this annotation

GitHub Actions / Static analysis (PHP 8.2) (stable dependencies)

Parameter #2 $trustedHeaderSet of static method Symfony\Component\HttpFoundation\Request::setTrustedProxies() expects int<0, 63>, int given.
}

$sent = false;
Expand Down

0 comments on commit afa9d23

Please sign in to comment.