content icon indicating copy to clipboard operation
content copied to clipboard

Issue with "Forbidden header name": `Referer` header (in the Forbidden list) is actually modifiable in Fetch API

Open damhonglinh opened this issue 5 years ago • 2 comments

MDN URL: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name

What information was incorrect, unhelpful, or incomplete?

Referer shouldn't in the list of forbidden headers in this document article.

If I understand correctly, this document article lists the forbidden headers that cannot be modified by normal JavaScript in browsers.

Referer is in the list of forbidden headers, so it shouldn't be modifiable. However, using Fetch API, it's possible to modify the header (via referrer option).

(On the other hand though, using XMLHttpRequest cannot modify the header.)

Specific section or headline?

Referer in the list of forbidden headers

What did you expect to see?

I expect not to see Referer in the list of forbidden headers. However, I think it's generally expected (at least in some StackOverflow answers) that Referer header is not modifiable.

After digging a bit, it seems the arguments that Fetch API can modify the header is that there are other tri icks (e.g. via pushState()) to do this: https://github.com/whatwg/fetch/issues/80

Did you test this? If so, how?

Using this https://jsfiddle.net/damhonglinh/oteg5fzy/33/. You would need to inspect Network and check for the Referer header

Safari (version 14) doesn't seem to allow this.

MDN Content page report details
  • Folder: en-us/glossary/forbidden_header_name
  • MDN URL: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
  • GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/glossary/forbidden_header_name/index.html
  • Last commit: https://github.com/mdn/content/commit/1fdf7958ea85bab45e1d7ba3634e9381eae937d1
  • Document last modified: 2021-01-27T07:42:45.000Z

damhonglinh avatar Feb 24 '21 14:02 damhonglinh

Referer is in the list of forbidden headers because the Fetch spec defines it as being a forbidden header — https://fetch.spec.whatwg.org/#forbidden-header-name

sideshowbarker avatar Feb 24 '21 19:02 sideshowbarker

I’m gonna go ahead and close this as resolved by https://github.com/mdn/content/issues/2660#issuecomment-785317168 — but if you feel something more should still be done, please comment and we can considering re-opening it.

sideshowbarker avatar Feb 26 '21 22:02 sideshowbarker