This is a conceptual question, so most likely I'm missing something. From reading about it, CORS is meant to protect the secondary site, not the primary site. Glossing over, hopefully, unimportant details, the use case seems to go like this: a page loads from a.com
and then attempts to fetch
from b.com
. In order to protect b.com
the browser will follow the CORS spec by asking b.com
if it's okay to share its data with a.com
. This seems odd to me for two reasons:
I can write a program to hit
b.com
directly, with any headers I please and ignoring preflight. Protectingb.com
, it would seem to me, should be its own responsibility and if it's not willing to serve everyone, it should implement authentication.The use case I thought the CORS spec is designed to address, is protecting the origin site
a.com
. Use case: I convince someone to use myhandy-dandy.js
on her site, becausehandy-dandy.js
does something really cool. What it also does is scrape the DOM for interesting data, like credit cards, and send it via a back door to my serverb.com
, which is happy to accept anything from anywhere.
Thanks in advance!
EDIT: As pointed out by daniel f., an earlier ticket subsumes this one.