-
Notifications
You must be signed in to change notification settings - Fork 8
Add Sourcepoint first-party CMP integration #625
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
ChristianPavilonis
wants to merge
18
commits into
main
Choose a base branch
from
feature/sourcepoint-integration
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 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
722eaf3
Add Sourcepoint first-party integration
ChristianPavilonis 494e919
Rewrite Sourcepoint script body so webpack chunks and API calls route…
ChristianPavilonis 16aa02d
Fix 500: request uncompressed content from Sourcepoint CDN before scr…
ChristianPavilonis f8e069d
Inject head script to trap window._sp_ and rewrite Sourcepoint config…
ChristianPavilonis c4b26cb
Address review findings: scope Accept-Encoding, add logging, tighten …
ChristianPavilonis 8594ea6
Fix Prettier formatting in Sourcepoint test file
ChristianPavilonis a211eb0
Remove geo.privacymanager.io support — not used by current publishers
ChristianPavilonis 748fd39
Address blocking review findings: SSRF guard, dead code, Prettier
ChristianPavilonis d7913d5
Harden Sourcepoint proxy: UTF-8 safety, redirects, CORS, quote handling
ChristianPavilonis 6d92a50
Clean up rewrite guard, add docs and validation tests
ChristianPavilonis 205be64
Fix CodeQL URL sanitization alerts, add response body size guard
ChristianPavilonis bd71ea8
Address round-3 review: body-size guard, header preservation, redirec…
ChristianPavilonis e2fdb0c
Align sourcepoint flagging, validation, and rewrite response handling
ChristianPavilonis a4c0b6b
Reject query strings and fragments in sourcepoint CDN origin
ChristianPavilonis 1a40868
Forward Sourcepoint cookies safely and disable caching for cookie res…
ChristianPavilonis e296d62
Merge branch 'main' into feature/sourcepoint-integration
ChristianPavilonis bec43a9
npm format
ChristianPavilonis a6ab10e
Merge branch 'feature/sourcepoint-integration' of github.com:IABTechL…
ChristianPavilonis 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,8 @@ | ||
| import { log } from '../../core/log'; | ||
|
|
||
| import { installSourcepointGuard } from './script_guard'; | ||
|
|
||
| if (typeof window !== 'undefined') { | ||
| installSourcepointGuard(); | ||
| log.info('Sourcepoint integration initialized'); | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
crates/js/lib/src/integrations/sourcepoint/script_guard.ts
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,53 @@ | ||
| import { createScriptGuard } from '../../shared/script_guard'; | ||
|
|
||
| const SOURCEPOINT_CDN_HOST = 'cdn.privacy-mgmt.com'; | ||
|
|
||
| function normalizeSourcepointUrl(url: string): string | null { | ||
| if (!url) return null; | ||
|
|
||
| const trimmed = url.trim(); | ||
| if (!trimmed) return null; | ||
|
|
||
| if (trimmed.startsWith('//')) return `https:${trimmed}`; | ||
| if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) return trimmed; | ||
|
|
||
| // Bare domain or path — attempt to parse as https URL. | ||
| // The host === check in isSourcepointUrl rejects non-matching domains. | ||
| return `https://${trimmed}`; | ||
| } | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
|
|
||
| function parseSourcepointUrl(url: string): URL | null { | ||
| const normalized = normalizeSourcepointUrl(url); | ||
| if (!normalized) return null; | ||
|
|
||
| try { | ||
| return new URL(normalized); | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export function isSourcepointUrl(url: string): boolean { | ||
| const parsed = parseSourcepointUrl(url); | ||
| return parsed?.host === SOURCEPOINT_CDN_HOST; | ||
|
ChristianPavilonis marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| export function rewriteSourcepointUrl(originalUrl: string): string { | ||
| const parsed = parseSourcepointUrl(originalUrl); | ||
| if (!parsed) return originalUrl; | ||
|
|
||
| const query = parsed.search || ''; | ||
|
|
||
| return `${window.location.origin}/integrations/sourcepoint/cdn${parsed.pathname}${query}`; | ||
| } | ||
|
|
||
| const guard = createScriptGuard({ | ||
| displayName: 'Sourcepoint', | ||
| id: 'sourcepoint', | ||
| isTargetUrl: isSourcepointUrl, | ||
| rewriteUrl: rewriteSourcepointUrl, | ||
| }); | ||
|
|
||
| export const installSourcepointGuard = guard.install; | ||
| export const isGuardInstalled = guard.isInstalled; | ||
| export const resetGuardState = guard.reset; | ||
82 changes: 82 additions & 0 deletions
82
crates/js/lib/test/integrations/sourcepoint/script_guard.test.ts
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,82 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| installSourcepointGuard, | ||
| isGuardInstalled, | ||
| isSourcepointUrl, | ||
| resetGuardState, | ||
| rewriteSourcepointUrl, | ||
| } from '../../../src/integrations/sourcepoint/script_guard'; | ||
|
|
||
| describe('Sourcepoint SDK Script Interception Guard', () => { | ||
| let originalAppendChild: typeof Element.prototype.appendChild; | ||
| let originalInsertBefore: typeof Element.prototype.insertBefore; | ||
|
|
||
| beforeEach(() => { | ||
| resetGuardState(); | ||
| originalAppendChild = Element.prototype.appendChild; | ||
| originalInsertBefore = Element.prototype.insertBefore; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| resetGuardState(); | ||
| }); | ||
|
|
||
| it('detects Sourcepoint CDN URLs', () => { | ||
| expect(isSourcepointUrl('https://cdn.privacy-mgmt.com/wrapper/v2/messages')).toBe(true); | ||
| expect(isSourcepointUrl('//cdn.privacy-mgmt.com/mms/v2/get_site_data')).toBe(true); | ||
| expect(isSourcepointUrl('cdn.privacy-mgmt.com/consent/tcfv2')).toBe(true); | ||
| expect(isSourcepointUrl('https://example.com/script.js')).toBe(false); | ||
| expect(isSourcepointUrl('https://geo.privacymanager.io/')).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects subdomain-spoofing URLs', () => { | ||
| expect(isSourcepointUrl('cdn.privacy-mgmt.com.evil.com/script.js')).toBe(false); | ||
| expect(isSourcepointUrl('https://cdn.privacy-mgmt.com.evil.com/')).toBe(false); | ||
| expect(isSourcepointUrl('notcdn.privacy-mgmt.com/path')).toBe(false); | ||
| }); | ||
|
|
||
| it('rewrites CDN URLs to the first-party proxy path', () => { | ||
| expect(rewriteSourcepointUrl('https://cdn.privacy-mgmt.com/wrapper/v2/messages?env=prod')).toBe( | ||
| `${window.location.origin}/integrations/sourcepoint/cdn/wrapper/v2/messages?env=prod` | ||
| ); | ||
| }); | ||
|
|
||
| it('installs and resets the guard', () => { | ||
| expect(isGuardInstalled()).toBe(false); | ||
| installSourcepointGuard(); | ||
| expect(isGuardInstalled()).toBe(true); | ||
| expect(Element.prototype.appendChild).not.toBe(originalAppendChild); | ||
| expect(Element.prototype.insertBefore).not.toBe(originalInsertBefore); | ||
| resetGuardState(); | ||
| expect(Element.prototype.appendChild).toBe(originalAppendChild); | ||
| expect(Element.prototype.insertBefore).toBe(originalInsertBefore); | ||
| }); | ||
|
|
||
| it('rewrites dynamically inserted Sourcepoint scripts', () => { | ||
| installSourcepointGuard(); | ||
|
|
||
| const container = document.createElement('div'); | ||
| const script = document.createElement('script'); | ||
| script.src = 'https://cdn.privacy-mgmt.com/wrapperMessagingWithoutDetection.js'; | ||
|
|
||
| container.appendChild(script); | ||
|
|
||
| expect(script.src).toContain( | ||
| '/integrations/sourcepoint/cdn/wrapperMessagingWithoutDetection.js' | ||
| ); | ||
| expect(script.src).not.toContain('cdn.privacy-mgmt.com'); | ||
| }); | ||
|
|
||
| it('does not rewrite unrelated scripts', () => { | ||
| installSourcepointGuard(); | ||
|
|
||
| const container = document.createElement('div'); | ||
| const script = document.createElement('script'); | ||
| script.src = 'https://example.com/app.js'; | ||
|
|
||
| container.appendChild(script); | ||
|
|
||
| expect(script.src).toBe('https://example.com/app.js'); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.