-
Notifications
You must be signed in to change notification settings - Fork 265
Update Consent Storage #992
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ export let data: Metadata = null; | |||||
| export let callbacks: MetadataCallbackOptions[] = []; | ||||||
| export let electron = BooleanFlag.False; | ||||||
| let rootDomain = null; | ||||||
| let consentStatus: ConsentState = null; | ||||||
| let consentStatus: ConsentData = null; | ||||||
| let defaultStatus: ConsentState = { source: ConsentSource.API, ad_Storage: Constant.Denied, analytics_Storage: Constant.Denied }; | ||||||
|
|
||||||
| export function start(): void { | ||||||
|
|
@@ -90,12 +90,12 @@ export function start(): void { | |||||
| if (consentStatus === null) { | ||||||
| consentStatus = { | ||||||
| source: ConsentSource.Implicit, | ||||||
| ad_Storage: config.track ? Constant.Granted : Constant.Denied, | ||||||
| analytics_Storage: config.track ? Constant.Granted : Constant.Denied, | ||||||
| ad_Storage: config.track ? BooleanFlag.True : BooleanFlag.False, | ||||||
| analytics_Storage: config.track ? BooleanFlag.True : BooleanFlag.False, | ||||||
| }; | ||||||
| } | ||||||
| const consent = getConsentData(consentStatus); | ||||||
| trackConsent.config(consent); | ||||||
|
|
||||||
| trackConsent.config(consentStatus); | ||||||
| // Track ids using a cookie if configuration allows it | ||||||
| track(u); | ||||||
| } | ||||||
|
|
@@ -127,7 +127,7 @@ export function metadata(cb: MetadataCallback, wait: boolean = true, recall: boo | |||||
| // we go through the upgrading flow. | ||||||
| if (data && (upgraded || wait === false)) { | ||||||
| // Immediately invoke the callback if the caller explicitly doesn't want to wait for the upgrade confirmation | ||||||
| cb(data, !config.lean, consentInfo ? consentStatus : undefined); | ||||||
| cb(data, !config.lean, consentInfo ? getConsentState() : undefined); | ||||||
| called = true; | ||||||
| } | ||||||
| if (recall || !called) { | ||||||
|
|
@@ -147,15 +147,18 @@ export function consent(status = true): void { | |||||
| } | ||||||
|
|
||||||
| consentv2({ ad_Storage: Constant.Granted, analytics_Storage: Constant.Granted }); | ||||||
| trackConsent.consent(); | ||||||
| } | ||||||
|
|
||||||
| export function consentv2(consentState: ConsentState = defaultStatus, source: number = ConsentSource.API): void { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this or later PR change to APIV2 so we know more precisely the source. |
||||||
| const updatedStatus = { | ||||||
|
|
||||||
| const currentState = getConsentState(); | ||||||
| const consentUpdate = { | ||||||
| source: consentState.source ?? source, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this alway mean we keep the last source? Should it not be flipped? |
||||||
| ad_Storage: normalizeConsent(consentState.ad_Storage, consentStatus?.ad_Storage), | ||||||
| analytics_Storage: normalizeConsent(consentState.analytics_Storage, consentStatus?.analytics_Storage), | ||||||
| }; | ||||||
| ad_Storage: normalizeConsent(consentState.ad_Storage, currentState.ad_Storage), | ||||||
| analytics_Storage: normalizeConsent(consentState.analytics_Storage, currentState.analytics_Storage), | ||||||
| } | ||||||
|
||||||
| } | |
| }; |
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.
When can source be null/undefined?
Copilot
AI
Dec 9, 2025
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.
Potential null reference error: consentStatus can be null, but this function accesses its properties without null checking. This function is called from line 154 in consentv2() before consentStatus is guaranteed to be initialized. Consider adding a null check or defaulting to implicit consent values when consentStatus is null:
function getConsentState(): ConsentState {
if (!consentStatus) {
return {
source: ConsentSource.Implicit,
ad_Storage: Constant.Denied,
analytics_Storage: Constant.Denied
};
}
return {
source: consentStatus.source ?? ConsentSource.Implicit,
ad_Storage: consentStatus.ad_Storage === BooleanFlag.True ? Constant.Granted : Constant.Denied,
analytics_Storage: consentStatus.analytics_Storage === BooleanFlag.True ? Constant.Granted : Constant.Denied,
};
}
Copilot
AI
Dec 9, 2025
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.
The new getConsentState() function lacks test coverage. Consider adding unit tests to verify:
- Correct conversion from BooleanFlag to Constant.Granted/Denied
- Proper handling of null
consentStatus - Default source value when
consentStatus.sourceis undefined
This is especially important given this function is used in callback flows (lines 130, 252) and in consentv2() (line 154).
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.
Should this not be ConsentData type? Maybe also consider giving this a unique source as well (the more the better).
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.
ConsentData uses boolean flags, the default status uses strings "granted" | "denied" sent to the API