{"success":true,"name":"configure-cors-deliberately-it-s-an-allowlist-not-an-error-t","description":"Browser calls to your API are blocked by CORS errors","category":"ai-brimind","path":"ai-brimind/configure-cors-deliberately-it-s-an-allowlist-not-an-error-t/SKILL.md","file":"SKILL.md","content":"---\nname: configure-cors-deliberately-it-s-an-allowlist-not-an-error-t\ndescription: \"Browser calls to your API are blocked by CORS errors\"\n---\n\n# Configure CORS Deliberately — It's an Allowlist, Not an Error to Silence\n\n## When to use\nA frontend on a different origin gets CORS errors calling your API, and the tempting fix is allowing everything to make the error disappear.\n\n## Example request\nCORS error 'fixed' with allow-origin * plus credentials → any website can now call your API as the logged-in user; the wildcard was the vulnerability. — Error blamed on the frontend code → CORS is enforced by the browser but configured on the server; the fix lives server-side. — Preflight OPTIONS requests failing → the server never handled OPTIONS; preflight is part of the protocol, not noise. — Dev origin allowed in production config → localhost stays whitelisted live; per-environment origin lists are the discipline.\n\n## Instructions\nAct as a browser-security-aware developer who treats CORS as an access control list, not an obstacle. When CORS blocks a call: 1) Understand what's happening before changing config: CORS is the browser protecting users; the server declares which origins may read responses. The fix is a correct server-side declaration, never frontend tricks. 2) Allowlist the exact origins that legitimately need access, per environment — dev origins in dev config, production origins in production config. Never use wildcard origin together with credentials; that combination hands your users' sessions to any website. 3) Use the framework's or gateway's existing CORS mechanism with explicit origins, methods, and headers — check what exists before hand-writing header logic, and make sure preflight (OPTIONS) is handled. 4) Allow only the methods and headers the frontend actually sends — the allowlist mindset applies to every dimension. 5) If the 'frontend' turns out to be server-to-server or a mobile app, stop — CORS is browser-only, and the real issue is elsewhere. Only apply config once you can say which origin needed access and why, and explain how the allowlist permits exactly the legitimate caller rather than making an error message go away.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #913\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}