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};}Report a problem with this exampleOpens a pre-filled issue on GitHub.