fetch icon indicating copy to clipboard operation
fetch copied to clipboard

CORS Content-Type "bypass" 2

Open annevk opened this issue 5 years ago • 3 comments

@MattMenke2 made me think of another "bypass", though it would only affect naïve parsers:

  • text/plain;,application/json
  • text/plain;charset=utf-8,application/json

These would only be successful with a server that splits on , and uses the last value, which isn't compliant per HTTP. An easy fix would be to ban 0x2C ,.

I thought I'd raise it here so it can be considered. I'm sorry for all the recent changes to this and that not everything was considered at once. Hopefully the bugs and tests help mitigate the churn annoyance.

cc @yutakahirano @youennf

annevk avatar Nov 22 '18 13:11 annevk

@whatwg/security thoughts? Shall I make patches for banning ,?

annevk avatar May 28 '19 13:05 annevk

I like the idea of banning ,, meaning we would always issue a preflight in that case.

antosart avatar Sep 23 '21 09:09 antosart

Yeah, that seems by far the most straightforward. I suppose the alternative would be something like this:

In https://fetch.spec.whatwg.org/#cors-safelisted-request-header under content-type, replace step 2-4 with:

  1. Let splitValues be the result of getting, decoding, and splitting Content-Type from « header ». (This syntax is somewhat confusing maybe, but turns header back into a header list, which "getting, decoding, and splitting" needs. An alternative might be to make "decode and split" its own algorithm separate from getting.)
  2. If splitValues is null, then return false.
  3. For each splitValue of splitValues:
    1. Let mimeType be the result of parsing splitValue.
    2. If mimeType is failure, then return false.
    3. If mimeType’s essence is not "application/x-www-form-urlencoded", "multipart/form-data", or "text/plain", then return false.

annevk avatar Sep 23 '21 11:09 annevk