{"success":true,"name":"fail-closed-when-a-security-check-errors-deny-by-default","description":"Writing error handling around login, permissions, tokens, or payments","category":"ai-brimind","path":"ai-brimind/fail-closed-when-a-security-check-errors-deny-by-default/SKILL.md","file":"SKILL.md","content":"---\nname: fail-closed-when-a-security-check-errors-deny-by-default\ndescription: \"Writing error handling around login, permissions, tokens, or payments\"\n---\n\n# Fail Closed: When a Security Check Errors, Deny by Default\n\n## When to use\nYou are writing try/catch or fallback logic around any check that decides access, identity, or money, and choosing what happens when the check fails or crashes.\n\n## Example request\nToken verification throws, so the catch block just continues → an invalid token now acts like a valid one; errors in auth must end in denial (fail closed vs fail open). The permission service is down, so the code temporarily allows everyone → outages become free-access windows; unavailable means denied, with a clear error (availability is not authorization). A payment webhook that can't be verified is processed anyway 'to not lose orders' → forged requests get treated as paid; unverifiable events go to a retry or review queue (verify then trust). An empty role field defaults to 'admin' because it was the first enum value → missing data silently grants top power; defaults must be the least privilege (safe defaults).\n\n## Instructions\nAct like an engineer who knows attackers hunt for the error paths, because that is where developers stop thinking. For every security-relevant check you write — token validation, permission lookup, signature verification, payment confirmation — explicitly decide the failure behavior, and make it denial: exceptions, timeouts, missing data, or unreachable services must all lead to 'no access', a logged event, and a clear error, never to a silent pass-through. Audit your catch blocks and fallbacks: any branch that continues the privileged action after a failed or skipped check is a fail-open hole. Set defaults to the weakest option (no role, no access, unverified) so missing values cannot grant power by accident. When a dependency needed for a decision is down, return an honest 'temporarily unavailable' instead of guessing generously; queue work for retry if the business needs it. Only finish once every check has a named failure outcome you chose on purpose, and explain why each one denies safely (fails closed) instead of quietly letting the request through when things break.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #533\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}