-
-
Notifications
You must be signed in to change notification settings - Fork 193
Replace session key in cache integration with placeholder #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@sentry review |
On it! We are reviewing the PR and will provide feedback shortly. |
PR DescriptionThis pull request enhances the privacy of cache telemetry data collected by the Sentry Laravel integration. Its primary goal is to prevent sensitive session identifiers from being inadvertently included in breadcrumbs and spans, which could expose user data. Click to see moreKey Technical ChangesThe key technical change is the introduction of session key masking. This is achieved by:
These changes affect how cache keys are displayed in Sentry's UI, replacing sensitive information with a generic placeholder. Architecture DecisionsThe architectural decision is to perform session key replacement within the Dependencies and InteractionsThis change depends on the Laravel session component. It interacts with the cache event system to intercept cache operations and modify the associated data. It also interacts with the Sentry SDK to add breadcrumbs and create spans. The changes are isolated to the Risk ConsiderationsThe primary risk is that the session key replacement logic might not be comprehensive enough to cover all possible scenarios where session keys could appear in cache keys. For example, if session keys are used as prefixes or embedded within larger strings, the replacement logic might fail. Additionally, there's a performance overhead associated with retrieving the session key and performing the string replacement, although this is expected to be minimal. Error handling in Notable Implementation DetailsA notable implementation detail is the use of a static closure in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that session IDs are anonymized as {sessionKey}
in Sentry breadcrumbs, spans, and Redis command data by replacing any detected session key in cache and Redis integrations.
- Introduces methods to retrieve the current session ID and replace it (and arrays of keys) with a placeholder.
- Updates cache and Redis event handlers to apply the replacement logic to breadcrumb messages, span descriptions, and parameters.
- Adds comprehensive tests to verify placeholder substitution and prevent premature session starts.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
test/Sentry/Features/CacheIntegrationTest.php | Added tests for replacing session keys with {sessionKey} in breadcrumbs and spans, and verifying no premature session start. |
src/Sentry/Laravel/Features/CacheIntegration.php | Added getSessionKey , replaceSessionKey , replaceSessionKeys methods and updated event handlers to use them. |
Comments suppressed due to low confidence (1)
test/Sentry/Features/CacheIntegrationTest.php:196
- There’s no test for session keys stored with a cache prefix. Adding a test case that uses a prefixed session ID (e.g.,
prefix_{$sessionId}
) would ensure the replacement logic covers those scenarios.
public function testCacheSpanReplacesMultipleSessionKeysWithPlaceholder(): void
bugbot run |
A fix was implemented to prevent session keys from appearing as cache keys in Sentry's session overview.
src/Sentry/Laravel/Features/CacheIntegration.php
:isSessionKey(string $key): bool
determines if a given cache key matches the current session ID, handling prefixed keys and ensuring sessions are not prematurely started.replaceSessionKey(string $key): string
replaces a detected session key with the placeholder{sessionKey}
.replaceSessionKeys(array $keys): array
applies the replacement logic to arrays of keys.src/Sentry/Laravel/Features/CacheIntegration.php
were updated to utilize these new methods:handleCacheEventsForBreadcrumbs
now replaces session keys in breadcrumb messages.handleCacheEventsForTracing
replaces session keys in span descriptions andcache.key
data forcache.get
,cache.put
, andcache.remove
operations.handleRedisCommands
also applies the replacement to Redis command descriptions and parameters.test/Sentry/Features/CacheIntegrationTest.php
to verify session key replacement in breadcrumbs and spans, and to confirm that the integration does not prematurely start sessions.This ensures session IDs are consistently anonymized as
{sessionKey}
in Sentry data, improving readability and privacy.