I know exactly how CORS is working, i know it's implemented on browsers, and i know it forbids XMLHTTPRequests to other origins unless the remote origin allows it using the response header Access-Control-Allow-Origin.
And of-course I heard it's because the "security reasons" that it's there.
The thing i don't get is how it's improving security.
So imagine we're in a browser and we have a malicious js file loaded in our page and it wants to send our local storage data or cookies to another origin (hacker origin). so the hacker simply set the "Access-Control-Allow-Origin" to * and he's good to go! so what CORS did exactly here?
Somewhere i read that CORS is there because of "intellectual property" and that makes sense somehow, so some remote servers don't want to answer to requests from other clients. that's ok.. . but for security reasons!? I don't get that part.
I would appreciate if anyone could help me with this.