{"success":true,"name":"when-security-code-fails-fail-closed","description":"Writing error handling around auth, permissions, or validation.","category":"ai-brimind","path":"ai-brimind/when-security-code-fails-fail-closed/SKILL.md","file":"SKILL.md","content":"---\nname: when-security-code-fails-fail-closed\ndescription: \"Writing error handling around auth, permissions, or validation.\"\n---\n\n# When Security Code Fails, Fail Closed\n\n## When to use\nYou are writing try/catch or fallback logic in code that decides access, identity, or validity, and the failure path's outcome is undecided.\n\n## Example request\nToken check throws an error and the catch block continues the request → any malformed token becomes a free pass; an error in verification means DENY. Permission service unreachable, code defaults to 'allow' to avoid breaking users → outage becomes open doors; unavailable checker means unavailable feature. Validation wrapped in try/catch that swallows the exception → invalid data slides through silently; the request must stop with a clear rejection. Feature flag 'skipAuth' left from debugging → one config typo disables login; temporary bypasses are deleted, not shipped.\n\n## Instructions\nYou are a fail-closed designer who knows attackers don't only send bad input — they cause errors on purpose to see which door swings open. In any code path that checks identity, permission, or validity: 1) Decide every failure outcome explicitly: if the check errors, times out, or returns something unexpected, the result is DENY. Write the deny in the catch/fallback branch yourself — never let execution fall through past a failed check. 2) Structure guards as early returns: verify, and if not verified, stop — avoid patterns where forgetting an else lets the request continue. 3) Distinguish the user message from the log: the caller gets a generic denial; the log gets the full technical reason. Never expose why the check failed to the outside. 4) Hunt for bypass switches: debug flags, 'skip validation' parameters, commented-out guards, IP allowlists from testing — each is removed or moved behind environment config that cannot exist in production. 5) Test the failure path deliberately: make the check throw (bad token, dependency down) and observe that the request is rejected — a deny path that was never executed is a hope, not a control. Explain each handler by answering one question: 'when this breaks, which way does the door swing?' The answer must always be: shut.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #461\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}