-
Notifications
You must be signed in to change notification settings - Fork 84
Fixed race condition causing gdprApplies to flip during TCF initialization #6895
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
aadcac2 to
a23f75c
Compare
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.
Greptile Overview
Greptile Summary
This PR fixes a race condition in FidesJS TCF initialization where gdprApplies could incorrectly be set to false when it should be true. The bug occurred because fidesTcfGdprApplies could be undefined during initialization, and the check used falsy logic that treated undefined as false.
The fix has two parts:
- Changed the check in
extractTCStringForCmpApifrom falsy (!window.Fides?.options?.fidesTcfGdprApplies) to strict equality (=== false), so only explicitlyfalsevalues trigger the GDPR-does-not-apply behavior - Ensured
fidesTcfGdprAppliesalways has a defined value by defaulting totruein two locations during initialization: when creating the TCF stub and when merging config options
This ensures returning users with existing TCF cookies receive the correct gdprApplies = true value consistently, preventing assets from being served without proper consent checks.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes are surgical and address a specific race condition with clear logic. The fix uses defensive programming (strict equality and default values) to prevent undefined behavior. The changes are well-commented and the logic is sound: defaulting to true for TCF experiences is the correct behavior per GDPR requirements.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| clients/fides-js/src/lib/tcf/events.ts | 5/5 | Changed falsy check to strict equality check (=== false) to prevent undefined from being treated as false, fixing the core race condition bug |
| clients/fides-js/src/fides-tcf.ts | 5/5 | Added default value of true for fidesTcfGdprApplies in two locations to ensure it's always defined during initialization, preventing race condition |
3 files reviewed, no comments
a23f75c to
f3be891
Compare
jpople
left a comment
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.
Tested locally, confirming bug is fixed.
Ticket ENG-1668
Description Of Changes
Fixed a race condition in FidesJS TCF initialization where
gdprAppliescould temporarily beundefined, causing the IAB CMP API to incorrectly report that GDPR does not apply. This could result in assets being served without proper consent checks for returning users with existing TCF cookies.The issue occurred because:
fidesTcfGdprApplieswas not guaranteed to have a default value during initializationundefinedasfalseCode Changes
fides-tcf.tsto ensurefidesTcfGdprAppliesdefaults totruefor TCF experiences during initialization, with proper override handlinglib/tcf/events.tsto use strict equality check (=== false) instead of falsy check, so only explicitlyfalsevalues setgdprApplies = falseSteps to Confirm
fides_tcf_gdpr_appliesgdprApplies = trueconsistentlyfides_tcf_gdpr_applies: falsestill works correctlyPre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works