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() ignores RequestInit.referrer #23762

Open
jcayzac opened this issue May 10, 2024 · 3 comments
Open

fetch() ignores RequestInit.referrer #23762

jcayzac opened this issue May 10, 2024 · 3 comments

Comments

@jcayzac
Copy link
Contributor

jcayzac commented May 10, 2024

Version: Deno 1.43.2

Simple repro with the CLI:

Deno 1.43.2
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> void Deno.serve((req) => new Response(JSON.stringify([...req.headers], null, 2)))
Listening on http://localhost:8000/
undefined
> await (await fetch(`http://localhost:8000/`, { referrer: `http://localhost:8000/foo` })).json()
[
  [ "accept", "*/*" ],
  [ "accept-encoding", "gzip, br" ],
  [ "accept-language", "*" ],
  [ "host", "localhost:8000" ],
  [ "user-agent", "Deno/1.43.2" ]
]
>

Current Behavior

Although I passed a value for referrer, it was ignored and fetch() didn't set the referer header on the request.

Adding any value for referrerPolicy makes no difference.

Expected Behavior

I should be getting a referer header.

@jcayzac
Copy link
Contributor Author

jcayzac commented May 10, 2024

It seems something is missing around here, maybe? Request(input, init) never references the field.

// 33.
if (init.headers || ObjectKeys(init).length > 0) {
const headerList = headerListFromHeaders(this[_headers]);
const headers = init.headers ?? ArrayPrototypeSlice(
headerList,
0,
headerList.length,
);
if (headerList.length !== 0) {
ArrayPrototypeSplice(headerList, 0, headerList.length);
}
fillHeaders(this[_headers], headers);
}
// 34.

The ObjectKeys(init).length > 0 test suggests someone intended on looking at the init object for other header-generating fields, but maybe forgot to do so later on.

@jcayzac
Copy link
Contributor Author

jcayzac commented May 10, 2024

The workaround for now is to use the referer request header, although it's forbidden even in WinterCG's spec for fetch() (and ignores any referrer policy, so you have to compute it manually):

> await (await fetch(`http://localhost:8000/`, { headers: { referer: `http://localhost:8000/foo` }})).json()
[
  [ "accept", "*/*" ],
  [ "accept-encoding", "gzip, br" ],
  [ "accept-language", "*" ],
  [ "host", "localhost:8000" ],
  [ "referer", "http://localhost:8000/foo" ],
  [ "user-agent", "Deno/1.43.2" ]
]

@bartlomieju
Copy link
Member

CC @lucacasonato, I recall there's a reason for this but I can't recall what's the particular reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants