Skip to content

Commit

Permalink
Use more precise warning when public suffix is used as a destination
Browse files Browse the repository at this point in the history
  • Loading branch information
apasel422 committed Dec 10, 2024
1 parent 7bddb39 commit 0fb771d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 10 additions & 0 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ const testCases: TestCase[] = [
},
],
},
{
name: 'destination-uses-public-suffix',
input: `{"destination": "https://com"}`,
expectedWarnings: [
{
msg: 'com is a public suffix: only triggers from https://com itself will match, not e.g. https://example.com',
path: ['destination'],
},
],
},

{
name: 'filter-data-wrong-type',
Expand Down
16 changes: 10 additions & 6 deletions ts/src/header-validator/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,14 @@ export function suitableOrigin(s: string, ctx: Context): Maybe<string> {
}

export function suitableSite(s: string, ctx: Context): Maybe<string> {
return suitableScope(
s,
ctx,
'site',
(u) => `${u.protocol}//${psl.get(u.hostname)}`
)
return suitableScope(s, ctx, 'site', (u) => {
let site = psl.get(u.hostname)
if (site === null) {
ctx.warning(
`${u.hostname} is a public suffix: only triggers from ${u.protocol}//${u.hostname} itself will match, not e.g. ${u.protocol}//example.${u.hostname}`
)
site = u.hostname
}
return `${u.protocol}//${site}`
})
}

0 comments on commit 0fb771d

Please sign in to comment.