-
-
Notifications
You must be signed in to change notification settings - Fork 44
fix: enforce first-party popup cap for ads #114
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
Open
AlejandroAkbal
wants to merge
27
commits into
main
Choose a base branch
from
fix/ad-popup-cap-30m
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1c4ea14
fix: enforce first-party popup cap for ads
AlejandroAkbal a83dc82
refactor: add popup guard debug instrumentation
AlejandroAkbal 6734b52
refactor: expose popup guard match reasons
AlejandroAkbal 6c9ec6e
fix: harden popup cap state handling
AlejandroAkbal 8c1dfa8
fix: prefer latest popup timestamp across tabs
AlejandroAkbal 2e02ceb
fix: spend popup cap on first vendor attempt
AlejandroAkbal 91eba7f
fix: exempt in-page push opens from popup cap
AlejandroAkbal 85d891e
fix: defer ad arming until after first click
AlejandroAkbal e37699d
fix: ignore capped vendor click handlers
AlejandroAkbal e2b542b
chore: enable popup guard debug in development
AlejandroAkbal b5a0607
refactor: simplify popup cap guard
AlejandroAkbal beb5218
Revert "fix: defer ad arming until after first click"
AlejandroAkbal 6edda36
fix: bypass popup guard for trusted app opens
AlejandroAkbal 90820bf
chore: restore dev popup guard logs
AlejandroAkbal 0cace6b
fix: exempt push provider opens from popup cap
AlejandroAkbal fe6d0a0
fix: treat hotsoz push redirects as in-page opens
AlejandroAkbal 06177ee
chore: log skipped ad scripts while capped
AlejandroAkbal 19cca55
refactor: centralize ad provider metadata
AlejandroAkbal db4bfe8
refactor: restore ad provider notes
AlejandroAkbal 94bf27c
test: cover popup guard decisions
AlejandroAkbal 92c9fda
fix: correct popunder provider URL
AlejandroAkbal f42c131
test: assert required popup cap duration
AlejandroAkbal 3e88a92
fix: abort blocked ad popup fallbacks
AlejandroAkbal 6644249
Merge remote-tracking branch 'origin/main' into fix/ad-popup-cap-30m
AlejandroAkbal 6b4ffbb
test: cover popup guard browser flow
AlejandroAkbal 38697f0
test: tighten capped popup browser assertions
AlejandroAkbal 031a706
refactor: simplify ad provider flattening
AlejandroAkbal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| export const AD_POPUP_CAP_DURATION_MS = 20 * 60 * 1000 | ||
| export const IN_PAGE_PUSH_SEARCH_PARAM_PREFIXES = ['inpage.'] as const | ||
|
|
||
| export type PopupOpenKind = 'popunder' | 'in-page-push' | ||
| export type PopupClassification = { | ||
| kind: PopupOpenKind | ||
| hostnames?: string[] | ||
| searchParamPrefixes?: readonly string[] | ||
| } | ||
|
|
||
| export type AdPopupCapLogDetails = { | ||
| lastPopupAt: number | null | ||
| cappedUntil: number | null | ||
| remainingMs: number | null | ||
| } | ||
|
|
||
| export type PopupGuardDecision = { | ||
| event: 'allow-in-page-push' | 'allow-popunder' | 'block-capped-popunder' | ||
| shouldAllow: boolean | ||
| shouldRecordPopupAt: boolean | ||
| capLogDetails?: AdPopupCapLogDetails | ||
| cappedUntil?: number | ||
| } | ||
|
|
||
| export type TrustedPopupBypassDecision = { | ||
| shouldBypassCurrentOpen: boolean | ||
| nextShouldBypass: boolean | ||
| } | ||
|
|
||
| function hostnameMatches(hostname: string, allowedHostnames: string[]): boolean { | ||
| return allowedHostnames.some(allowedHostname => { | ||
| return hostname === allowedHostname || hostname.endsWith(`.${allowedHostname}`) | ||
| }) | ||
| } | ||
|
|
||
| function hasMatchingSearchParamPrefix(parsedUrl: URL, searchParamPrefixes: readonly string[]): boolean { | ||
| for (const searchParamKey of parsedUrl.searchParams.keys()) { | ||
| if (searchParamPrefixes.some(prefix => searchParamKey.startsWith(prefix))) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| function matchesPopupClassification(parsedUrl: URL, popupClassification: PopupClassification): boolean { | ||
| if (popupClassification.hostnames && hostnameMatches(parsedUrl.hostname, popupClassification.hostnames)) { | ||
| return true | ||
| } | ||
|
|
||
| if (popupClassification.searchParamPrefixes && hasMatchingSearchParamPrefix(parsedUrl, popupClassification.searchParamPrefixes)) { | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| export function getTrustedPopupBypassDecision(shouldBypassNextWindowOpenGuard: boolean): TrustedPopupBypassDecision { | ||
| return { | ||
| shouldBypassCurrentOpen: shouldBypassNextWindowOpenGuard, | ||
| nextShouldBypass: false | ||
| } | ||
| } | ||
|
|
||
| export function getPopupOpenKind( | ||
| requestedUrl: string | null, | ||
| { | ||
| baseUrl, | ||
| popupClassifications | ||
| }: { | ||
| baseUrl: string | ||
| popupClassifications: readonly PopupClassification[] | ||
| } | ||
| ): PopupOpenKind { | ||
| if (!requestedUrl) { | ||
| return 'popunder' | ||
| } | ||
|
|
||
| try { | ||
| const parsedUrl = new URL(requestedUrl, baseUrl) | ||
|
|
||
| for (const popupClassification of popupClassifications) { | ||
| if (matchesPopupClassification(parsedUrl, popupClassification)) { | ||
| return popupClassification.kind | ||
| } | ||
| } | ||
| } catch { | ||
| // Ignore malformed vendor URLs and keep the default popunder classification. | ||
| } | ||
|
|
||
| return 'popunder' | ||
| } | ||
|
|
||
| export function isAdPopupCapActive( | ||
| lastPopupAt: number | null, | ||
| now: number, | ||
| capDurationMs = AD_POPUP_CAP_DURATION_MS | ||
| ): boolean { | ||
| return lastPopupAt !== null && now - lastPopupAt < capDurationMs | ||
| } | ||
|
|
||
| export function getAdPopupCapLogDetails( | ||
| lastPopupAt: number | null, | ||
| now: number, | ||
| capDurationMs = AD_POPUP_CAP_DURATION_MS | ||
| ): AdPopupCapLogDetails { | ||
| if (lastPopupAt === null) { | ||
| return { | ||
| lastPopupAt: null, | ||
| cappedUntil: null, | ||
| remainingMs: null | ||
| } | ||
| } | ||
|
|
||
| const cappedUntil = lastPopupAt + capDurationMs | ||
|
|
||
| return { | ||
| lastPopupAt, | ||
| cappedUntil, | ||
| remainingMs: Math.max(0, cappedUntil - now) | ||
| } | ||
| } | ||
|
|
||
| export function getPopupGuardDecision({ | ||
| popupOpenKind, | ||
| lastPopupAt, | ||
| now, | ||
| capDurationMs = AD_POPUP_CAP_DURATION_MS | ||
| }: { | ||
| popupOpenKind: PopupOpenKind | ||
| lastPopupAt: number | null | ||
| now: number | ||
| capDurationMs?: number | ||
| }): PopupGuardDecision { | ||
| if (popupOpenKind === 'in-page-push') { | ||
| return { | ||
| event: 'allow-in-page-push', | ||
| shouldAllow: true, | ||
| shouldRecordPopupAt: false | ||
| } | ||
| } | ||
|
|
||
| if (isAdPopupCapActive(lastPopupAt, now, capDurationMs)) { | ||
| return { | ||
| event: 'block-capped-popunder', | ||
| shouldAllow: false, | ||
| shouldRecordPopupAt: false, | ||
| capLogDetails: getAdPopupCapLogDetails(lastPopupAt, now, capDurationMs) | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| event: 'allow-popunder', | ||
| shouldAllow: true, | ||
| shouldRecordPopupAt: true, | ||
| cappedUntil: now + capDurationMs | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,7 @@ | |
| return | ||
| } | ||
|
|
||
| window.open(url, '_blank') | ||
| openTrustedWindow(url, '_blank') | ||
| } | ||
|
|
||
| function onMenuOpen() { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use a 30-minute cap, not 20 minutes.
The PR objective is a 30-minute cooldown. Keeping this at 20 minutes shortens the block window, lets ad scripts come back 10 minutes early, and makes the guard enforce the wrong contract.
🔧 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents