@wardenjs/ssr-access
v0.2.0
Published
Authorization for Fetch-API servers: role-based access control, ownership (IDOR) checks and a permission decorator.
Maintainers
Readme
@wardenjs/ssr-access
Part of warden's server track: security controls as decorators for any Fetch-API handler (Next.js route handlers, Hono, Bun, Deno, Workers). Here SSR means server side, not server-side rendering.
Role-based access control and ownership checks.
npm i @wardenjs/ssr @wardenjs/ssr-accessimport { accessControl } from '@wardenjs/ssr-access';
export const access = accessControl({
roles: ['user', 'moderator', 'admin'], // least to most privileged
grants: {
user: ['post:create', 'post:update:own'],
moderator: ['post:create', 'post:update:own', 'post:update:any'],
admin: ['post:create', 'post:update:any', 'user:assign-role'],
},
});
export const POST = chain().use(session.required()).use(access.require('post:create')).handle(create);
// Ownership, inside the handler, with ownerId from the stored record:
access.assertAccess(principal, post.authorId, 'post:update:own', 'post:update:any'); // 404 when denied- Deny by default; anonymous callers get nothing unless
anonymousnames a role. - The table is validated at construction: a typo in a role name throws.
assertAccessanswers 404, not 403, so ids cannot be enumerated.canAssignRoleallows only roles below the actor's, never to themselves.filterapplies the same rules to lists you cannot scope in the query.
