ABAC Attribute Policy Engine
Evaluate attribute-based access control policies over subject resource and action attributes for fine-grained authorization.
Code
export function abacEngine(policies){function matchAttr(rule,actual){if(!rule)return true;for(const[k,v]of Object.entries(rule))if(actual[k]!==v)return false;return true;}function evaluate(policy,ctx){for(const rule of policy.rules){if(matchAttr(rule.subject,ctx.subject)&&matchAttr(rule.resource,ctx.resource)&&matchAttr(rule.action,ctx.action))return rule.effect==='allow';}return policy.defaultEffect==='allow';}return{evaluate};}Checking attributes against policies
Count the functions abacEngine, matchAttr and evaluate as the entire surface area of ABAC Attribute Policy Engine.
What to watch for
- The guard
!ruleshort-circuits the flow with an earlyreturnwhen its condition holds.
Applying it
Entry signature: export function abacEngine(policies)
abacEngine is what another module would consume; nothing else here is load-bearing for callers.
Interactive Tools for This Topic
Basic & Bearer Auth Header ToolEncode and decode HTTP Authorization Basic and Bearer headers locally with UTF-8 Base64 validation and automatic JWT claim and expiry inspection.JWT Expiry CalculatorDecode a JWT payload and convert its exp, iat, and nbf claims into UTC ISO timestamps, with an expired-or-valid verdict.JWT Token DecoderDecode JSON Web Token (JWT) headers and payloads safely in the browser. Inspect expiration, issuer, and claims without sending tokens to any external server.JWT Signature InspectorInspect a JWT signature: decode the header and payload, show the algorithm and signature bytes, and verify HS256/384/512 HMAC signatures with a secret.
FAQ
- Is there an install step between copy and run?
- No. Between copying and running there is nothing left to do. The file defines `abacEngine`, `matchAttr`, `evaluate` at load time.
Report a problem with this exampleOpens a pre-filled issue on GitHub.