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

fetch: Referer header is almost never being set #1958

Closed
KhafraDev opened this issue Feb 22, 2023 · 2 comments · Fixed by #1970
Closed

fetch: Referer header is almost never being set #1958

KhafraDev opened this issue Feb 22, 2023 · 2 comments · Fixed by #1970
Labels
bug Something isn't working fetch good first issue Good for newcomers

Comments

@KhafraDev
Copy link
Member

I'll get around to fixing it, but it could be a good first issue for someone who wants to dive into the code but doesn't know where to start. Here's why the bug occurs:

The referrerPolicy is being set to undefined here

undici/lib/fetch/index.js

Lines 557 to 559 in bc8e2b8

if (request.referrerPolicy === '') {
request.referrerPolicy = request.policyContainer.referrerPolicy
}

because we don't implement policyContainers:

undici/lib/fetch/util.js

Lines 328 to 338 in bc8e2b8

// https://html.spec.whatwg.org/multipage/origin.html#policy-container
function makePolicyContainer () {
// TODO
return {}
}
// https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container
function clonePolicyContainer () {
// TODO
return {}
}

which causes this condition to trigger

undici/lib/fetch/util.js

Lines 346 to 348 in bc8e2b8

if (policy == null || policy === '' || policy === 'no-referrer') {
return 'no-referrer'
}

which means the header is never appended here

undici/lib/fetch/index.js

Lines 1333 to 1335 in bc8e2b8

if (httpRequest.referrer instanceof URL) {
httpRequest.headersList.append('referer', isomorphicEncode(httpRequest.referrer.href))
}

The easiest fix is to implement makePolicyContainer and clonePolicyContainer (both are used). Follow the steps in the links above the methods (and include the steps as comments). A "list" is an array.

@KhafraDev KhafraDev added bug Something isn't working good first issue Good for newcomers fetch labels Feb 22, 2023
@Aditya-A-G
Copy link

hey, @KhafraDev I would like to work on this issue. can you please assign this issue to me

@Aditya-A-G Aditya-A-G removed their assignment Feb 23, 2023
@Aditya-A-G
Copy link

sorry due to some reason I will not be able to solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fetch good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants