Skip to content

Commit 9999b82

Browse files
authored
Work around improper site extraction for IP addresses (#1535)
1 parent d583edb commit 9999b82

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

ts/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"author": "",
1717
"license": "Apache-2.0",
1818
"dependencies": {
19+
"ip-regex": "^5.0.0",
1920
"memoizee": "^0.4.17",
2021
"psl": "^1.15.0",
2122
"structured-headers": "^2.0.1",

ts/src/header-validator/source.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const testCases: TestCase[] = [
2828
"aggregation_keys": {"a": "0xf"},
2929
"debug_key": "1",
3030
"debug_reporting": true,
31-
"destination": "https://a.test",
31+
"destination": ["https://a.test", "https://1.2.3.4"],
3232
"destination_limit_priority": "1",
3333
"event_report_window": "3601",
3434
"expiry": "86400",
@@ -61,7 +61,7 @@ const testCases: TestCase[] = [
6161
aggregationKeys: new Map([['a', 15n]]),
6262
debugKey: 1n,
6363
debugReporting: true,
64-
destination: new Set(['https://a.test']),
64+
destination: new Set(['https://a.test', 'https://1.2.3.4']),
6565
destinationLimitPriority: 1n,
6666
eventLevelEpsilon: 14,
6767
expiry: 86400,
@@ -116,7 +116,7 @@ const testCases: TestCase[] = [
116116
},
117117
{
118118
name: 'destination-url-components',
119-
input: `{"destination": ["https://a.test/b?c=d#e", "https://x.Y.test", "https://sub.A.test/z"]}`,
119+
input: `{"destination": ["https://a.test/b?c=d#e", "https://x.Y.test", "https://sub.A.test/z", "https://1.2.3.4/5"]}`,
120120
expectedWarnings: [
121121
{
122122
path: ['destination', 0],
@@ -134,6 +134,10 @@ const testCases: TestCase[] = [
134134
path: ['destination', 2],
135135
msg: 'duplicate value https://a.test',
136136
},
137+
{
138+
msg: 'URL components other than site (https://1.2.3.4) will be ignored',
139+
path: ['destination', 3],
140+
},
137141
],
138142
},
139143

ts/src/header-validator/validate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ipRegex from 'ip-regex'
12
import * as psl from 'psl'
23
import { Context, PathComponent } from './context'
34
import { Maybe } from './maybe'
@@ -376,6 +377,9 @@ export function suitableOrigin(s: string, ctx: Context): Maybe<string> {
376377

377378
export function suitableSite(s: string, ctx: Context): Maybe<string> {
378379
return suitableScope(s, ctx, 'site', (u) => {
380+
if (ipRegex({ exact: true }).test(u.hostname)) {
381+
return `${u.protocol}//${u.hostname}`
382+
}
379383
let site = psl.get(u.hostname)
380384
if (site === null) {
381385
ctx.warning(

0 commit comments

Comments
 (0)