in the AMP Docs, the following snippet is given:
If the
Originheader is set:
If the origin does not match one of the following values, stop and return an error response:
<publisher's domain>.cdn.ampproject.orgthe publisher's origin (aka yours)
where * represents a wildcard match, and not an actual asterisk ( * ).
Otherwise, process the request.
If the
Originheader is NOT set:
- Verify that the request contains the
AMP-Same-Origin: trueheader. If the request does not contain this header, stop and return an error response.- Otherwise, process the request.
What I don't understand is how the AMP-Same-Origin header provides a form of security.
TLDR:
Couldn't anyone provide an AMP-Same-Origin: true header in a browser missing the Origin header and skip CSRF protection even if it's not on a trusted AMP CDN?
AMP-Same-Originheader on a request using a browser they know doesn't sent theOriginheader. At the least, the docs saying to respond with the source origin ifAMP-Same-Originis there, but I don't see the point of even checking a header that anyone can add just to respond with same-origin as the response anyways – Sampson Crowley Aug 24 '20 at 22:35AMP-Same-Originand noOriginis given; so I don't see what the point is of even checking for the header instead of just responding to the request with your origin set as the "allow" value and letting it fail on its own; since the requests will fail CORS checks anyways if it's not from the same origin – Sampson Crowley Aug 24 '20 at 22:59evil.comand make a xhr request on*.cdn.ampproject.organd considering that ampproject.org doesn't have a CORS policy (akaAccess-Control-Allow-Origin: *andAccess-Control-Allow-Headers: AMP-Same-Origin), then you cannot set theAMP-Same-Originheader. The browser will forbid it when you will try to send the request. – Xavier59 Aug 25 '20 at 10:06*.cdn.ampproject.orgdoesn't send back the headerAccess-Control-Allow-Origin: *. The only thing you can do is make aGETorPOSTrequest via an image or a form. But you cannot trick the browser into addingAMP-Same-Origin– Xavier59 Aug 25 '20 at 10:09Access-Control-Allow-Originis a response header, it has absolutely nothing to do with the CDN servers for the AMP project. theOriginheader allows your server to respond to*.cdn.ampproject.orgsafely; the instructions forAMP-Same-Origintell you only to respond to your own origin. So again, I don't see the point of looking for the header when you're not responding withAccess-Control-Allow-Origin: *, you're responding withAccess-Control-Allow-Origin: mydomain.com– Sampson Crowley Aug 25 '20 at 15:46AMP-Same-Originif AMP doesn't send you the response headers I mentionned. I am not sure to get what you fail to understand here and I'd like to help. Come over to chat https://chat.stackexchange.com/rooms/112273/csrf – Xavier59 Aug 25 '20 at 19:10cdn.ampproject.org.cdn.ampproject.orgis a CDN that serves static caches of pre-rendered pages for instant delivery on mobile devices. it is theOriginnot the endpoint/source server – Sampson Crowley Aug 25 '20 at 20:51