opyebCorsLab

Simple-request checks: method, headers and Content-Type

Simple request · 6 min

In one line: The Fetch Standard safelist explained value by value, including the byte rules for header values and the Range exception.

A simple request is a cross-origin request sent without a preflight. The conditions are narrower than the name suggests: step slightly outside them and the browser adds an OPTIONS round trip.

1. Method

Only GET, HEAD and POST. Note that OPTIONS itself is not a simple method — sending OPTIONS by hand is a separate thing from the automatic preflight.

2. Request headers

The name must be one of five, and the value has rules too.

HeaderValue rule
Acceptno CORS-unsafe bytes
Accept-Languagesame
Content-Languagesame
Content-Typeessence is one of the three allowed MIME types
Rangea simple bytes= range value

CORS-unsafe bytes are 0x00–0x08, 0x0A–0x1F, 0x7F and the characters "():<>?@[\]{}. So Accept: application/json is fine, but a value containing a parenthesis or colon is not a simple header.

3. Content-Type

If the header is Content-Type, the essence (the part before the semicolon, lower-cased) must be one of:

application/x-www-form-urlencoded
multipart/form-data
text/plain

application/json, application/xml and text/xml are not on the list. Parameters are allowed, so text/plain;charset=UTF-8 passes. This single rule is why JSON APIs almost always come with a preflight.

4. Examples

RequestResult
GET, no headerssimple
POST, content-type: application/jsonpreflight
POST, content-type: text/plain;charset=UTF-8simple
GET, authorization: Bearer …preflight
GET, range: bytes=0-1023simple
DELETEpreflight

5. The temptation to avoid preflights

Because text/plain is safelisted, some clients send JSON with text/plain to dodge the preflight. It works, but if the server does not check Content-Type the CSRF protection weakens, and caches and proxies may treat the body differently. Handling OPTIONS properly is the better fix.

6. Checking it in CorsLab

The simulator shows “simple request” or “preflight required” at the top, and lists the reasons — method, header name or Content-Type value — when a preflight is needed.

Put the same request and response into the simulator to see whether it passes and which header to change.

Open CorsLab

Frequently asked questions

Can Accept hold several values?

A comma-separated list is fine, but if the value contains a CORS-unsafe byte (a parenthesis or colon, for example) it stops being a simple header.

Is Range always a simple header?

Only as a simple range value. Three or more ranges, or another format, trigger a preflight.

Does one custom header always trigger a preflight?

Yes. Even a harmless-looking header such as X-Request-Id is not safelisted, so it brings a preflight.

Sources

Read next

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)