{"success":true,"name":"lock-down-cors-a-wildcard-is-an-open-door-not-a-fix","description":"Hit a CORS error and about to change server CORS settings","category":"ai-brimind","path":"ai-brimind/lock-down-cors-a-wildcard-is-an-open-door-not-a-fix/SKILL.md","file":"SKILL.md","content":"---\nname: lock-down-cors-a-wildcard-is-an-open-door-not-a-fix\ndescription: \"Hit a CORS error and about to change server CORS settings\"\n---\n\n# Lock Down CORS: A Wildcard Is an Open Door, Not a Fix\n\n## When to use\nThe browser blocked a request with a CORS error, and you are editing the API's CORS configuration to make it work.\n\n## Example request\nSetting Access-Control-Allow-Origin to * to make the error disappear → now any website can call your API from users' browsers; only your own frontend origins belong on the list (origin whitelist). Combining wildcard origin with credentials/cookies → this pairing is exactly how malicious sites act as your logged-in users; credentialed requests require one exact origin (credentials rule). Reflecting whatever Origin header arrives back in the response → that is a wildcard with extra steps; validate against a fixed list instead (origin reflection anti-pattern). Blaming CORS for a server 500 error → CORS only controls browser access; a failing endpoint is a different bug (know what the mechanism does).\n\n## Instructions\nAct like a developer who understands CORS is a browser safety rule you are choosing to relax, not an obstacle to delete. Before touching configuration, understand the model: the browser blocks cross-origin reading by default, and your server's headers declare which foreign origins may read responses — so every origin you allow is a site you trust to act with your users' browsers. Fix errors by listing the exact origins your frontends use (scheme, domain, port) per environment: localhost origins for development, real domains for production, loaded from configuration. Never ship a wildcard on an API that uses cookies or auth headers, and never echo the incoming Origin back as a lazy allow-all; when credentials are involved, the allowed origin must be specific. Use the framework's CORS middleware rather than hand-writing headers, and confirm preflight (OPTIONS) requests are handled with only the methods and headers you actually need. First verify the failing request even needs CORS — a server error or wrong URL is not a CORS problem. Only apply the change once the allowed list names exactly your own frontends, and explain why the restriction protects your users' sessions from hostile websites rather than just silencing the browser console.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #539\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}