Changelog - 2026-06-02
Scoped RBAC Authorization
Breaking Change EnhancementIn one line. Casbin authorization now runs on a generic, configuration-driven adapter with role, resource, action and domain hierarchies, and, once you turn on the scoped model (isScoped, off by default), each request gets its own enforcer, which closes a race on the shared one.
What changed
ScopedCasbinAdapter. A generic read-only adapter that reads a principal's edges and the shared hierarchy from onePolicyDefinitionedge table. Configure it withIScopedCasbinEntities; no subclassing.- Scoped model
CASBIN_RBAC_DOMAIN_SCOPED_MODEL.r = sub, dom, obj, act, default-deny with explicit-deny-wins, and five grouping relations:grole,g2domain membership,g3domain hierarchy,g4resource hierarchy,g5action hierarchy. Domain scoping uses theSYSTEM_WIDEandANY_MEMBERsentinels. - Thin
BaseFilteredAdapter<TFilter>. Subclasses implement onlyloadFilteredPolicy. - Per-request enforcer pool. Each request borrows its own enforcer, loads only that user's lines and enforces. On any error the enforcer is destroyed (fail-closed). Before, concurrent requests could corrupt policy state on one shared enforcer.
- Redis-only line cache. Per-user lines are cached with a TTL, and concurrent misses are deduplicated. A corrupt entry is discarded and refetched instead of causing a 500. Optional
invalidateUserCacheandrebuildUserCacheevict or rebuild a user's lines.
Turn on the scoped model with these ICasbinEnforcerOptions:
| Option | Default | Meaning |
|---|---|---|
isScoped | false | Enables the 4-token scoped model |
poolSize | 16 | Enforcers held in the pool |
poolAcquireTimeoutMs | 5000 | Wait for a pooled enforcer before failing closed |
Who is affected
- Apps that subclassed
DrizzleCasbinAdapter, used the in-memory cache driver, built a customICasbinPolicyFilter, referencedCasbinRuleVariants.GROUPor.POLICY, or usedIAuthorizationCacheInvalidator. Must migrate (see breaking changes). - Apps not using Casbin authorization. No action needed.
Breaking changes
WARNING
See the Scoped RBAC Migration Guide for both supported migration paths with full before/after code.
DrizzleCasbinAdapterremoved.DrizzleCasbinAdapterandIDrizzleCasbinAdapterOptionsare gone. UseScopedCasbinAdapteror subclass the new thinBaseFilteredAdapter.Filter shape changed.
typescript// Before interface ICasbinPolicyFilter { principalType: string; principalValue: string | number; } // After interface ICasbinPolicyFilter { principal: { type: string; id: IdType }; }CasbinRuleVariantstrimmed. Before,GROUP,POLICY,SCHEME_SETandisValidexisted. Now onlyCasbinRuleVariants = { P, G, G2, G3, G4, G5 }. The databasevariantdiscriminator moves toAuthorizationPolicyVariants.*.action(grant,assign_role,join_domain,role_inherits,resource_inherits,action_inherits,domain_inherits).In-memory cache driver removed.
typescript// Before cached: { use: true, driver: CasbinEnforcerCachedDrivers.IN_MEMORY } // After cached: { use: false } | (ICasbinEnforcerCachedRedis & { use: true })Provide Redis for caching, or
{ use: false }for none.IAuthorizationCacheInvalidatorremoved.IAuthorizationCacheInvalidatorandTAuthorizationCacheInvalidatorare gone. Cache management is now the optionalinvalidateUserCache?andrebuildUserCache?members ofIAuthorizationEnforcer.