Pick the fix
The SPA at https://app.example.com sends cookies to the API. Which CORS config is right?
Hint 1 of 1
Credentials need an explicit origin.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Allow-Origin: https://app.example.com, Allow-Credentials: true, Vary: Origin
Correct. One explicit origin with credentials; Vary keeps caches honest.
With credentials, the browser only shares the response if Allow-Origin names the exact calling origin and Allow-Credentials is true. Vary: Origin stops a cache handing one origin's answer to another.
Why not the others?
- B Allow-Origin: *, Allow-Credentials: true. Browsers reject this combination.
- C Echo whatever Origin arrives, with credentials. Any website could read your users' data.
- D Disable CORS on the server. There's nothing to disable; without headers the browser blocks reads.