Skip to content

Commit

Permalink
test(*): Add file_get_contents host header removal
Browse files Browse the repository at this point in the history
  • Loading branch information
julienloizelet committed Oct 16, 2024
1 parent 255ec6c commit 6092c74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Client/RequestHandler/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private function createContextConfig(Request $request): array
$headers = $request->getValidatedHeaders();
/**
* It's not recommended to set the Host header when using file_get_contents (with follow_location).
*
* @see https://www.php.net/manual/en/context.http.php#context.http.header
* As it was causing issues with PHP 7.2, we are removing it.
* For AppSec requests, original host is sent in the X-Crowdsec-Appsec-Host header.
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/FileGetContentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public function testContextConfigForAppSec()
'X-Crowdsec-Appsec-Method' => 'test-value',
'X-Crowdsec-Appsec-Uri' => 'test-value',
'X-Crowdsec-Appsec-Api-Key' => 'test-value',
'Host' => 'test-value-should-be-removed',
'Custom-Header' => 'test-value-should-be-kept',
];
$rawBody = 'This is a raw body';
$configs = $this->tlsConfigs;
Expand All @@ -198,6 +200,7 @@ public function testContextConfigForAppSec()
X-Crowdsec-Appsec-Method: test-value
X-Crowdsec-Appsec-Uri: test-value
X-Crowdsec-Appsec-Api-Key: test-value
Custom-Header: test-value-should-be-kept
',
'ignore_errors' => true,
'content' => 'This is a raw body',
Expand Down Expand Up @@ -236,6 +239,7 @@ public function testContextConfigForAppSec()
X-Crowdsec-Appsec-Method: test-value
X-Crowdsec-Appsec-Uri: test-value
X-Crowdsec-Appsec-Api-Key: test-value
Custom-Header: test-value-should-be-kept
User-Agent: ' . TestConstants::USER_AGENT_SUFFIX . '
',
'ignore_errors' => true,
Expand Down

0 comments on commit 6092c74

Please sign in to comment.