ABAC Attribute Policy Engine

Evaluate attribute-based access control policies over subject resource and action attributes for fine-grained authorization.

JavascriptAuth Jwt

Code

javascriptsnippet
1 line
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 !rule short-circuits the flow with an early return when 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

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.