From dbcf0630ddea2a371e68eddae14aca306e7ed1bd Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Fri, 14 Jun 2024 21:33:32 +0200 Subject: [PATCH] Guard against empty `REMOTE_ADDR` (#1751) --- src/Integration/RequestIntegration.php | 2 +- tests/Integration/RequestIntegrationTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Integration/RequestIntegration.php b/src/Integration/RequestIntegration.php index 4238b457c..d4ab50ce1 100644 --- a/src/Integration/RequestIntegration.php +++ b/src/Integration/RequestIntegration.php @@ -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']; diff --git a/tests/Integration/RequestIntegrationTest.php b/tests/Integration/RequestIntegrationTest.php index 266405d90..cea34cb57 100644 --- a/tests/Integration/RequestIntegrationTest.php +++ b/tests/Integration/RequestIntegrationTest.php @@ -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,