Skip to content

fetch: Referer header is almost never being set #1958

@KhafraDev

Description

@KhafraDev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions