This is not about Foo.com, nor about Bar.com. It's about the user.
There are two things that CORS protects. The first is access to resources behind the firewall. The second is resources that are usually protected if the request is not sent from browsers with authentication or other sensitive data files.
CORS is a server-side browser technology that allows foo to restrict the freedom to call outside your domain. This is a limited hole, punched in the restriction of cross-domain scripts.
Anyone can fake the ORIGIN header and create a CORS preview or a simple request. Of course, anyone can connect directly to the Bar server directly and make requests without using CORS. Any browser can directly connect to bar.com and receive data. But a modern browser does not run a script from foo.com that accesses the bar.com resource. People visiting websites are protected from visiting a site intended for the use of cookies, or the fact that the browser is behind a corporate firewall.
So the accepted answer is WRONG. It is not about bar.com protecting its resources - it does this through authentication and authorization. You do not need to create a proxy to send CORS requests - you create a proxy server to deprive CORS requests (automatically respond to the pre-flight mail request and return the appropriate headers to the browser, but by sending a normal request to the bar. Com). But you still need authentication to get the bar.com resources, and foo.com must still somehow force you to set up a proxy server in order to use the script-through hole that CORS protects.
But the final sentence is correct - foo.com does not control resources - it is a browser, with a quick check on bar.com to ask him if it was something that was intended.
From OP:
If this is really all about protecting bar.com, then why force a browser to enforce policy ?. The only possible situation in which this makes sense is if you have evil.com serving the Y page, which represents foo.com, which is trying to send data to bar.com. But CORS is browser-activated, all you have to do is make evil.com a proxy that sends fake origin requests to bar.com (data goes from Y to evil.com, evil.com sets its fake origin to foo.com and then sends it to bar.com).
evil.com can already contact bar.com - just like any person using a browser can (either curl or wget, etc.). The problem is that evil.com forces your browser to connect to bar.com, which may have IP filters, cookies, firewalls, etc., protecting it, but javascript can connect to your browser. Thus, the browser is what protects the user. Prohibition of cross-domain scripts. But sometimes itβs useful (for example: google apis or a bank connecting to a payment service, etc.) For a cross domain script. CORS tells the browser that everything is fine in this case.
This does not mean that there are no holes, or the standard is the best, or that there are no holes in the browser, or that sites are too permissive. But these are different questions ...