Skip to content

CORS: arbitrary blocking of accept header based on length #862

@pietercolpaert

Description

@pietercolpaert

When the accept header is larger than 128 bytes, the request will trigger a preflight request that blocks if the accept header is not explicitly set. This length looks quite arbitrary: is there a reason for this? But even when the preflight request happens, probably the accept header should not explicitly be set?

The length breaks use cases where a browser script is used to query different web resources on the fly.

Asking all open web resource servers to set the Access-Control-Allow-Headers: accept in order to circumvent this seems like much to ask for no real added security?

Reproducing in Chromium

// Test 1: works
fetch('https://graph.irail.be/sncb/connections?departureTime=2019-01-27',
   {  
      headers: new Headers({
          accept: "application/ld+json"
      })
   }).then(async (response)=> { console.log(await response.json())});
// Test 2: fails
fetch('https://graph.irail.be/sncb/connections?departureTime=2019-01-27', 
   {
      headers: new Headers({
          accept: "application/trig;q=1.0,application/n-quads;q=0.7,text/turtle;q=0.6,application/n-triples;q=0.3,application/ld+json;q=0.3,text/n3;q=0.2"
      })
   }).then(async (response)=> { console.log(await response.json())});

In other browsers

Mozilla docs have this to say:

Note that certain headers are always allowed: Accept, Accept-Language, Content-Language,
Content-Type (but only with a MIME type of its parsed value (ignoring parameters) of either
application/x-www-form-urlencoded, multipart/form-data, or text/plain). These are called the simple
headers, and you don't need to specify them explicitly.

Src: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers#Directives

The test cases do work in Firefox.

In the whatwg spec

Question: is this a chromium specific bug, or is this unclear in the whatwg specification and should this be corrected?

Context

We are working on querying open web resources. Setting a long Accept header is therefore quite normal: we can parse a lot of different formats.

Related issue: comunica/comunica#373

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions