Skip to content

Commit 70a06cf

Browse files
committed
fix
1 parent 9004046 commit 70a06cf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/web/fetch/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ function isOriginPotentiallyTrustworthy (origin) {
641641
}
642642

643643
// origin’s host ends with ".localhost" or ".localhost."
644-
if (origin.hostname === '.localhost' || origin.hostname === '.localhost.') {
644+
if (origin.hostname.endsWith('.localhost') || origin.hostname.endsWith('.localhost.')) {
645645
return true
646646
}
647647

test/fetch/util.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,29 @@ test('sameOrigin', async (t) => {
119119
})
120120

121121
test('isURLPotentiallyTrustworthy', (t) => {
122+
// https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-let-localhost-be-localhost#section-5.2
122123
const valid = [
124+
'http://localhost',
125+
'http://localhost.',
123126
'http://127.0.0.1',
124127
'http://[::1]',
125128
'https://something.com',
126129
'wss://hello.com',
127130
'data:text/plain;base64,randomstring',
128131
'about:blank',
129132
'about:srcdoc',
133+
'http://subdomain.localhost',
134+
'http://subdomain.localhost.',
135+
'http://adb.localhost',
136+
'http://localhost.localhost',
130137
'blob:http://example.com/550e8400-e29b-41d4-a716-446655440000'
131138
]
132139
const invalid = [
140+
'http://localhost.example.com',
141+
'http://subdomain.localhost.example.com',
133142
'file:///link/to/file.txt',
134143
'http://121.3.4.5:55',
135144
'null:8080',
136-
'http://adb.localhost',
137-
'http://localhost.localhost',
138145
'something:8080'
139146
]
140147

0 commit comments

Comments
 (0)