Skip to content
Open
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"ext-mbstring": "*",
"ext-curl": "*",
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
"psr/log": "^1.0|^2.0|^3.0",
"symfony/options-resolver": "^4.4.30|^5.0.11|^6.0|^7.0"
"psr/log": "^1.0|^2.0|^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ parameters:
count: 1
path: src/Dsn.php

-
message: "#^Property Sentry\\\\Integration\\\\RequestIntegration\\:\\:\\$options \\(array\\{pii_sanitize_headers\\: array\\<string\\>\\}\\) does not accept array\\.$#"
count: 1
path: src/Integration/RequestIntegration.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
Expand Down
19 changes: 7 additions & 12 deletions src/Integration/RequestIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
use Sentry\Event;
use Sentry\Exception\JsonException;
use Sentry\Options;
use Sentry\OptionsResolver;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use Sentry\UserDataBag;
use Sentry\Util\JSON;
use Symfony\Component\OptionsResolver\Options as SymfonyOptions;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* This integration collects information from the request and attaches them to
Expand Down Expand Up @@ -68,10 +67,6 @@ final class RequestIntegration implements IntegrationInterface

/**
* @var array<string, mixed> The options
*
* @psalm-var array{
* pii_sanitize_headers: string[]
* }
*/
private $options;

Expand All @@ -80,10 +75,6 @@ final class RequestIntegration implements IntegrationInterface
*
* @param RequestFetcherInterface|null $requestFetcher PSR-7 request fetcher
* @param array<string, mixed> $options The options
*
* @psalm-param array{
* pii_sanitize_headers?: string[]
* } $options
*/
public function __construct(?RequestFetcherInterface $requestFetcher = null, array $options = [])
{
Expand Down Expand Up @@ -178,6 +169,10 @@ private function sanitizeHeaders(array $headers): array
// Cast the header name into a string, to avoid errors on numeric headers
$name = (string) $name;

if (!\is_array($this->options['pii_sanitize_headers'])) {
break;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Header Sanitization Fails When Option Isn't Array

The sanitizeHeaders method's defensive check for pii_sanitize_headers is inside the loop. If the option isn't an array, the break statement exits prematurely, leading to incomplete or no header sanitization and potential PII exposure. This check also runs inefficiently on every iteration.

Fix in Cursor Fix in Web

if (!\in_array(strtolower($name), $this->options['pii_sanitize_headers'], true)) {
continue;
}
Expand Down Expand Up @@ -302,10 +297,10 @@ private function isRequestBodySizeWithinReadBounds(int $requestBodySize, string
*/
private function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefault('pii_sanitize_headers', self::DEFAULT_SENSITIVE_HEADERS);
$resolver->setAllowedTypes('pii_sanitize_headers', 'string[]');
$resolver->setNormalizer('pii_sanitize_headers', static function (SymfonyOptions $options, array $value): array {
$resolver->setNormalizer('pii_sanitize_headers', static function (array $value): array {
return array_map('strtolower', $value);
});
$resolver->setDefault('pii_sanitize_headers', self::DEFAULT_SENSITIVE_HEADERS);
}
}
Loading
Loading