fix(analytics): return false when AnalyticsController state is unreadable#30248
fix(analytics): return false when AnalyticsController state is unreadable#30248tommasini wants to merge 2 commits into
Conversation
…, that means that user had the possibility to opt out and not being opted out in METRICS_OPT_IN storage key value because we never delete it
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 905bbd2. Configure here.
| } | ||
| } catch { | ||
| // Fall through to legacy storage | ||
| return false; |
There was a problem hiding this comment.
Catch block omits cachedConsent update unlike other paths
Medium Severity
The catch block returns false but does not set cachedConsent = false, unlike the other two return paths (lines 572 and 583) which both update the cache before returning. This leaves cachedConsent as null, which per line 551's comment means "not yet loaded." Traces will be silently buffered in memory for the entire session rather than being discardable, since the consent state is never recorded as determined. While getCachedConsent() !== true currently treats null and false the same for buffering, the missing cache update is inconsistent with the function's contract in a privacy-critical path.
Reviewed by Cursor Bugbot for commit 905bbd2. Configure here.
|
| } | ||
| } catch { | ||
| // Fall through to legacy storage | ||
| return false; |
There was a problem hiding this comment.
| return false; | |
| cachedConsent = false; | |
| return false; |





Description
The
hasMetricsConsentfunction previously fell through to the legacyMETRICS_OPT_INstorage key whenever reading fromAnalyticsController's persisted state threw an error. This is incorrect because theMETRICS_OPT_INkey is never deleted (see migration 108) — meaning a staleAGREEDvalue could cause Sentry traces to be emitted even when the user had already opted out via the newer analytics controller.By returning
falseimmediately in thecatchblock, we ensure that Sentry stays disabled whenever the analytics controller state cannot be reliably read, defaulting to the privacy-safe behaviour of treating consent as not given.Changelog
CHANGELOG entry: Fixed Sentry traces being sent when AnalyticsController state was unreadable
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Made with Cursor
Note
Medium Risk
Changes Sentry consent gating behavior when persisted analytics state is unreadable, which could affect whether traces are sent/blocked in some edge cases. Scope is small but touches privacy/telemetry control flow.
Overview
Ensures
hasMetricsConsent()fails privacy-safe by returningfalseif reading/parsing the persistedAnalyticsControllerstate throws, instead of falling back to the legacyMETRICS_OPT_INkey.This prevents stale legacy opt-in values from re-enabling Sentry traces when the newer controller state is corrupted or missing.
Reviewed by Cursor Bugbot for commit 905bbd2. Bugbot is set up for automated code reviews on this repo. Configure here.