- yes,
cross-originincludes different port numbers. to the IT students everyone pulling their hair out because twolocalhosts on your machine can't talk to each other: we salute you. - what is a simple request?
- one of [
GET,HEAD,POST] -- no side effects. - the ONLY manual (ie, not added by the browser) headers allowed are:
AcceptAccept-LanguageContent-LanguageContent-TypeLast-Event_idDPRSave-DataViewport-WidthWidth
Content-Type: one of [application/x-www-form-urlencoded,multipart/form-data,text/plain]- MUST NOT
- have a listener on the
XMLHttpRequest.upload - be a
ReadableStream
- have a listener on the
- one of [
- at minimum:
- a preflight will have:
Origin: http://some.origin:maybe_portAccess-Control-Request-Method: POSTAccess-Control-Request-Headers: Content-Type, X-Custom-Fancy-Header
- a successful response will have:
- a response code of 200-something
Access-Control-Allow-Origin: http://some.origin:maybe_port(or a wildcard which the URL passes)Access-Control-Allow-Methods: POSTand maybe other methodsAccess-Control-Allow-Headers: Content-Type, X-Custom-Fancy-Headerand once again maybe others
- a preflight will have:
If the preflight fails, the request WILL NOT BE SENT.
If the response headers do not have those, the request WILL NOT BE SENT.
If the server responds with something that is NOT a 200 to the OPTIONS header, the request WILL NOT BE SENT.
preflight: when a pre-emptive HTTP request is made of type OPTIONS
-- direction: the REQUESTER makes a preemptive OPTIONS request to the target resource, the server.
the BROWSER -- client -- determines whether it should send a preflight request.
the client sends an initial request of OPTIONS, which includes the headers it plans on sending (as labels) and the method
- Access-Control-Request-Method: what the upcoming method will be
- Access-Control-Request-Headers: custom if any headers
the server responds if this is okay -- and responds with usually
- Access-Control-Allow-Origin: allowed host
- Access-Control-Allow-Methods: a list of allowed methods
- Access-Control-Allow-Headers: a list of acceptable headers
- Access-Control-Max-Age: how long this preflight request may be cached for
- authorization header
application/json- any of the following methods:
PUT,DELETE,CONNECT,OPTIONS,TRACE,PATCH - any headers which ARE NOT in this list:
AcceptAccept-LanguageContent-LanguageContent-TypeLast-Event_idDPRSave-DataViewport-WidthWidth
- XMLHttpRequest, Fetch, Request will not send cookies by default
.withCredentialswill send the cookies- if the client says "hey, I'm sending credentials":
- and the server does NOT respond with
Access-Control-Allow-Credentials: true-- the response will be ignored by the browser - and the server DOES respond with
Access-Control-Allow-Credentials: true-- the response will be accepted by the browser
- and the server does NOT respond with
- the server must specify an
Access-Control-Allow-Originwhose value is NOT a wildcard for credentialed requests - to repeat: if you need cookies OR Http Auth, a cross-site response MAY NOT
Allow-Access-Control-Origin: *
What returned resource, from the server, would send back.
think like radioing a tower -- 'access control, allow origin http://some_url.org'
- `Access-Control-Allow-Origin: | * | null
- what URI origin is allowed
Access-Control-Expose-Headers: X-My-Custom-Header, X-Another-Custom-Header- which RESPONSE headers may be exposed in the response
- how long, in seconds, a result may be cached
- in preflight, says whether the real request may have credentials
- GET does not get preflighted by default, so if you GET with credentials and the server does not explicitly allow it, it will fail
- allowed method(s) in the actual request
- allowed headers in the actual request
These are set by the user-agent.
user-agent : usually the browser -- what makes the request on behalf of the user. These headers may only be set by the user-agent so they can remain in control of the request.
Accept-CharsetAccept-EncodingAccess-Control-Request-HeadersAccess-Control-Request-MethodConnectionContent-LengthCookieCookie2DateDNTExpectKeep-AliveOriginReferer[sic]TETrailerTransfer-EncodingUpgradeVia
sources:
- https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS (as always)
- https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe/43881141#43881141
- https://tools.ietf.org/html/rfc6454#ref-CORS (RFC spec)
make a filter!
- hit the endpoint first of the proxy by literally gluing the urls together
proxy_url/original_urlas your endpoint- the proxy send the request to
original_url - the proxy gets the response
- the proxy adds
Access-Control-Allow-Origin: original_url - the proxy passes that response back
- if you control the server -- make the
Access-Control-Allow-Originvalue be that of theOrigin
POSTis expected to have side effects, I'm guessing the reason it chooses these is that there's some way to send these without using JS? Maybe they can all be specified as aform's method or something?Oh, super glad I read this, there's like 3 huge landmines in here that I'm pretty sure I'd have stepped on.
Not sure I understand the notation here, does the first star mean "0 or more" (a Kleene star) and the second one mean "wildcard" or "all domains"?
Hmmmmmm... 🤔 the star seems more sensible given that multiple origins are allowed. I didn't realize this was the case, where did you find this? The one I'm looking at (https://fetch.spec.whatwg.org/#http-new-header-syntax) makes it seem like I can only have a single origin.
Okay, I looked at the MDN resource you linked, and it also says this: (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin)
But I'm like 90% confident that I have seen a site send down a giant list of origins. I specifically remember going to some website and pasting in a giant list of domains and it parsed them for me, and I submitted that in a bug report, pointing out that the broken domain wasn't in the list. But I can't remember how long ago it was or what site it was or...
Figured it out! It was the content security policy header:
$ curl -I 'https://www.customink.com/fundraising'So then I think this one can only have a single origin.
Interesting! This is to get visibility into the requests and responses?
Yeah, good call, I'm going to have to check mine.