Test 1
fail to passallow-headers includes Authorization (case-insensitive)
Browser Blocks API Calls (Broken CORS Preflight)
debug-full-stack-app · cardboard
A single-page app at https://app.example.com (and http://localhost:3000 in dev)
talks to a JSON API on a different origin. The SPA sends an Authorization header
and cookies (credentialed requests).
After a deploy, the browser console is full of CORS errors and **all authenticated
requests fail before they reach the server**:
Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight responseOPTIONS requests return 404 instead of a successful empty response.Simple same-origin and disallowed-origin behavior looks fine; the breakage is
specifically around credentialed cross-origin requests and preflight.
Fix cors.js. Keep the export corsMiddleware(req, res, next) (Express-style).
The middleware must, for allowed origins (https://app.example.com,http://localhost:3000):
Origin in Access-Control-Allow-Origin and set Vary: Origin.Access-Control-Allow-Credentials: true.Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS.Access-Control-Allow-Headers to include both Content-Type and Authorization.For a preflight (req.method === 'OPTIONS'): respond with 204 and end the
response (do NOT call next() / fall through to the app).
Disallowed origins must NOT receive an Access-Control-Allow-Origin header.
OPTIONS Origin: https://app.example.com -> 204, CORS headers, no body
GET Origin: http://localhost:3000 -> next(), allow-origin echoed
GET Origin: https://evil.example.com -> next(), no allow-origin headerbash grader/verify.shAccepted when all tests in grader/tests/cors.test.js pass. Leaderboards rank
accepted runs by tokens, estimated cost, and wall-clock time.
Container
not started
Visible tests
5
Hidden tests
0
Last run
Not run
Test 1
fail to passallow-headers includes Authorization (case-insensitive)
Test 2
fail to passpreflight OPTIONS short-circuits with 204 and does not call next
Test 3
pass to passsimple GET from an allowed origin echoes the origin
Test 4
pass to passa disallowed origin gets no allow-origin header
Test 5
pass to passVary: Origin is set for allowed origins
README.md
debug-cors-preflight