Skip to content

Commit bf407c0

Browse files
authored
Prohibit localhost in simulator (#428)
Corresponding to #421.
1 parent f1e114a commit bf407c0

3 files changed

Lines changed: 140 additions & 1 deletion

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"events": [
3+
{
4+
"seconds": 1,
5+
"site": "localhost",
6+
"event": "measureConversion",
7+
"options": {
8+
"aggregationService": "https://agg-service.example",
9+
"histogramSize": 1
10+
},
11+
"expected": {
12+
"error": "DOMException",
13+
"name": "SyntaxError"
14+
}
15+
},
16+
{
17+
"seconds": 2,
18+
"site": "foo.localhost",
19+
"event": "measureConversion",
20+
"options": {
21+
"aggregationService": "https://agg-service.example",
22+
"histogramSize": 1
23+
},
24+
"expected": {
25+
"error": "DOMException",
26+
"name": "SyntaxError"
27+
}
28+
},
29+
{
30+
"seconds": 3,
31+
"site": "a.example",
32+
"intermediarySite": "localhost",
33+
"event": "measureConversion",
34+
"options": {
35+
"aggregationService": "https://agg-service.example",
36+
"histogramSize": 1
37+
},
38+
"expected": {
39+
"error": "DOMException",
40+
"name": "SyntaxError"
41+
}
42+
},
43+
{
44+
"seconds": 4,
45+
"site": "a.example",
46+
"event": "measureConversion",
47+
"options": {
48+
"aggregationService": "https://agg-service.example",
49+
"histogramSize": 1,
50+
"impressionSites": ["localhost"]
51+
},
52+
"expected": {
53+
"error": "DOMException",
54+
"name": "SyntaxError"
55+
}
56+
},
57+
{
58+
"seconds": 5,
59+
"site": "a.example",
60+
"event": "measureConversion",
61+
"options": {
62+
"aggregationService": "https://agg-service.example",
63+
"histogramSize": 1,
64+
"impressionCallers": ["localhost"]
65+
},
66+
"expected": {
67+
"error": "DOMException",
68+
"name": "SyntaxError"
69+
}
70+
}
71+
]
72+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"events": [
3+
{
4+
"seconds": 1,
5+
"site": "localhost",
6+
"event": "saveImpression",
7+
"options": {
8+
"histogramIndex": 0
9+
},
10+
"expectedError": {
11+
"error": "DOMException",
12+
"name": "SyntaxError"
13+
}
14+
},
15+
{
16+
"seconds": 2,
17+
"site": "foo.localhost",
18+
"event": "saveImpression",
19+
"options": {
20+
"histogramIndex": 0
21+
},
22+
"expectedError": {
23+
"error": "DOMException",
24+
"name": "SyntaxError"
25+
}
26+
},
27+
{
28+
"seconds": 3,
29+
"site": "a.example",
30+
"intermediarySite": "localhost",
31+
"event": "saveImpression",
32+
"options": {
33+
"histogramIndex": 0
34+
},
35+
"expectedError": {
36+
"error": "DOMException",
37+
"name": "SyntaxError"
38+
}
39+
},
40+
{
41+
"seconds": 4,
42+
"site": "a.example",
43+
"event": "saveImpression",
44+
"options": {
45+
"histogramIndex": 0,
46+
"conversionSites": ["localhost"]
47+
},
48+
"expectedError": {
49+
"error": "DOMException",
50+
"name": "SyntaxError"
51+
}
52+
},
53+
{
54+
"seconds": 5,
55+
"site": "a.example",
56+
"event": "saveImpression",
57+
"options": {
58+
"histogramIndex": 0,
59+
"conversionCallers": ["localhost"]
60+
},
61+
"expectedError": {
62+
"error": "DOMException",
63+
"name": "SyntaxError"
64+
}
65+
}
66+
]
67+
}

impl/src/backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function days(days: number): Temporal.Duration {
5858

5959
function parseSite(input: string): string {
6060
const site = getDomain(input, { allowPrivateDomains: true });
61-
if (site === null) {
61+
if (site === null || site === "localhost" || site.endsWith(".localhost")) {
6262
throw new DOMException(`invalid site ${input}`, "SyntaxError");
6363
}
6464
return site;

0 commit comments

Comments
 (0)