Skip to content
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

fix: handle opaque origin in sameOrigin #2053

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,9 @@ function tryUpgradeRequestToAPotentiallyTrustworthyURL (request) {
*/
function sameOrigin (A, B) {
// 1. If A and B are the same opaque origin, then return true.
// "opaque origin" is an internal value we cannot access, ignore.
if (A.origin === B.origin && A.origin === 'null') {
return true
}

// 2. If A and B are both tuple origins and their schemes,
// hosts, and port are identical, then return true.
Expand Down
10 changes: 10 additions & 0 deletions test/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ test('sameOrigin', (t) => {
t.end()
})

t.test('file:// urls', (t) => {
// urls with opaque origins should return true

const a = new URL('file:///C:/undici')
const b = new URL('file:///var/undici')

t.ok(util.sameOrigin(a, b))
t.end()
})

t.end()
})

Expand Down