Skip to content

Commit

Permalink
Guard against empty REMOTE_ADDR (#1751)
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive authored Jun 14, 2024
1 parent 1ea8e3d commit dbcf063
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Integration/RequestIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function processEvent(Event $event, Options $options): void
if ($options->shouldSendDefaultPii()) {
$serverParams = $request->getServerParams();

if (isset($serverParams['REMOTE_ADDR'])) {
if (!empty($serverParams['REMOTE_ADDR'])) {
$user = $event->getUser();
$requestData['env']['REMOTE_ADDR'] = $serverParams['REMOTE_ADDR'];

Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/RequestIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ public static function invokeDataProvider(): iterable
UserDataBag::createFromUserIpAddress('127.0.0.1'),
];

yield [
[
'send_default_pii' => true,
],
(new ServerRequest('GET', 'http://www.example.com', [], null, '1.1', ['REMOTE_ADDR' => '']))
->withHeader('Host', 'www.example.com'),
[
'url' => 'http://www.example.com',
'method' => 'GET',
'cookies' => [],
'headers' => [
'Host' => ['www.example.com'],
],
],
null,
null,
];

yield [
[
'send_default_pii' => false,
Expand Down

0 comments on commit dbcf063

Please sign in to comment.