Posting JSON with an HTML Form (2016)
systemoverlord.com
systemoverlord.com
(A good HTTP framework, IMO, should come with this built into its API, on requesting the payload as a JSON object. Some frameworks … try. A lot do leave it up to the user, which is hideously error prone. Also, this isn't to defend that cross-origin POST is sort-of allowed. I wish we could remove that historical wart.)
It's been plagued initially be slow adoption and later by inconsistent support like the example in this article and others[1], but as a general spec. it should fix CSRF if implemented consistently and correctly by browser vendors.
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simpl...
The only time the request is made by default is when it falls in to the "simple" category, which as far as I'm aware, is limited to
- GET requests
- That only include known header fields
In all other cases, you fall into the other bucket. In that case the browser will make a preflight options request (without any data) to check the CORS response headers configured by the server. Only then, if allowed by the response headers, will the browser actually make the POST.
---
Ok, I went and looked, apparently you can send POSTS, you just can't send application/json, only one of the default form content types (text/plain is one, though).
So I'm wrong - At least for Firefox, this would likely be the same request with the same behavior.
Well, the form post returns the response, which opens up more csrf problems.
Edit: uh, nope. Not sure where my head was. See below.