Skip to content

Commit

Permalink
Remove sensitive cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Jul 25, 2023
1 parent 9b26cad commit 321013f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Sentry/Laravel/Http/LaravelRequestFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Sentry\Laravel\Http;

use Illuminate\Container\Container;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
use Sentry\Integration\RequestFetcher;
use Sentry\Integration\RequestFetcherInterface;
Expand All @@ -26,9 +28,28 @@ public function fetchRequest(): ?ServerRequestInterface
}

if ($container->bound(self::CONTAINER_PSR7_INSTANCE_KEY)) {
return $container->make(self::CONTAINER_PSR7_INSTANCE_KEY);
$request = $container->make(self::CONTAINER_PSR7_INSTANCE_KEY);
} else {
$request = (new RequestFetcher)->fetchRequest();
}

return (new RequestFetcher)->fetchRequest();
if ($request === null) {
return null;
}

$cookies = new Collection($request->getCookieParams());

// We need to filter out the cookies that are not allowed to be sent to Sentry because they are very sensitive
$forbiddenCookies = [config('session.cookie'), 'remember_*'];

return $request->withCookieParams(
$cookies->map(function ($value, string $key) use ($forbiddenCookies) {
if (Str::is($forbiddenCookies, $key)) {
return '[Filtered]';
}

return $value;
})->all()
);
}
}

0 comments on commit 321013f

Please sign in to comment.