Skip to content

refactor(auth): remove ROLE_PERMISSIONS fallback, fail closed instead - #15

Merged
zumbrunn merged 10 commits into
mainfrom
refactor/drop-role-permissions-fallback
Aug 31, 2026
Merged

refactor(auth): remove ROLE_PERMISSIONS fallback, fail closed instead#15
zumbrunn merged 10 commits into
mainfrom
refactor/drop-role-permissions-fallback

Conversation

@zumbrunn

@zumbrunn zumbrunn commented Aug 29, 2026

Copy link
Copy Markdown
Member

dec-identity-unification Phase 5c's second half: checkInlineEditPermission() and runPluginResponseTransforms()'s pages.update gate both fell back to a flat ROLE_PERMISSIONS table when authz was undefined — authz creation failing at startup, an in-process object construction that essentially never fails in practice. Every other admin permission check already treats authz.check() as the sole authority; this closes the same gap in these last two call sites. Both now fail closed (deny) instead of silently degrading to a separate, less-audited mechanism.

The one place that genuinely can't call the real async authz.check()ResponseTransformContext.auth.hasPermission(), a published synchronous hook API plugin-inline-edit already depends on — now reads roleHasPermission() (new, src/auth/authz-schema.ts), a synchronous lookup against the same canonical actionToRelations schema authz.check() itself uses, instead of consulting plugin-admin's hand-maintained mirror. This is the one legitimate reason a role-only fallback ever needed to exist, now sourced from a single canonical definition instead of two tables that had to be kept in sync by hand.

Companion change to @dune/plugin-admin's 3.0.0: duneorg/plugin-admin#3, which removes ROLE_PERMISSIONS/hasPermission() entirely now that nothing in core consults them. Merge either order.

dec-identity-unification Phase 5c's second half: checkInlineEditPermission()
and runPluginResponseTransforms()'s pages.update gate both fell back to a
flat ROLE_PERMISSIONS table when authz was undefined -- authz creation
failing at startup, an in-process object construction that essentially
never fails in practice. Every other admin permission check already
treats authz.check() as the sole authority; this closes the same gap in
these last two call sites. Both now fail closed (deny) instead of
silently degrading to a separate, less-audited mechanism.

The one place that genuinely can't call the real async authz.check() --
ResponseTransformContext.auth.hasPermission(), a published synchronous
hook API plugin-inline-edit already depends on -- now reads
roleHasPermission() (new, src/auth/authz-schema.ts), a synchronous lookup
against the same canonical actionToRelations schema authz.check() itself
uses, instead of consulting plugin-admin's hand-maintained mirror. This
is the one legitimate reason a role-only fallback ever needed to exist,
now sourced from a single canonical definition instead of two tables that
had to be kept in sync by hand.

Companion change to @dune/plugin-admin's 3.0.0, which removes
ROLE_PERMISSIONS/hasPermission() entirely now that nothing in core
consults them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
zumbrunn and others added 8 commits August 30, 2026 23:13
checkInlineEditPermissionForSiteUser() still degraded to a raw roles[]
check (editor/admin string match) when authz was undefined — the same
parallel, less-audited mechanism PR #15 removed everywhere else. Since
authz.check() is async and this function is already async, nothing
prevents failing closed here too. authz.check() is now the sole
authority for every core-side permission decision, no exceptions.

Found during security audit of #15 (Finding 1).
…th.hasPermission() against misuse

roleHasPermission() is exported from @dune/core/auth/authz-schema, which
invites third-party plugins to reintroduce role-table authorization
anywhere. Its answer is a synchronous role-only approximation that can
diverge from authz.check() (revoked tuples, direct grants, group
membership are invisible to it). It stays exported — the published
synchronous hook API genuinely needs it — but both its doc and the
ResponseTransformContext.auth.hasPermission() contract now state loudly
that it is not for access decisions: use authz.check().

Found during security audit of #15 (Finding 2).
…st admin-tier role

roles[0] is not necessarily an admin role: the merged User type mixes
admin-tier roles with content-gating tags (e.g. ["member", "admin"]) in
no guaranteed order. An admin whose tag came first passed the real
pages.update authz.check() gate but got auth.role === "member", so the
published synchronous hasPermission() under-privileged relative to what
the sole authority had just decided (fail-closed direction, but a silent
contract regression for the published hook API vs the old
highestValidRole() behavior).

New highestAdminRole() in @dune/core/auth/authz-schema picks the
highest-ranked admin-tier role (admin > editor > author), ignoring tags
and unknown roles; arrays with no admin-tier role yield "" as before.

Found during security audit of #15 (Finding 3).
…hema

Remove "admin.access" from VALID_PERMISSIONS — it never had a
corresponding action in the canonical actionToRelations schema (it only
ever existed in the removed ROLE_PERMISSIONS table) and is now flagged
as unknown, same as any other nonexistent permission. Update the
hasPermission() lint pattern from the removed two-argument
(authResult, "perm") form to the current single-argument hook API form
(auth.hasPermission("perm")).

Found during security audit of #15 (nits).
highestAdminRole() (added in bdeb897 to fix roles[0] under-privileging
ResponseTransformContext) had its rank table private to authz-schema.ts,
and authz-schema.ts itself had no export map entry at all -- nothing
outside this package could import roleHasPermission()/highestAdminRole()
despite roleHasPermission()'s own doc already describing them as
importable.

Exported ADMIN_ROLE_RANK as the canonical rank table highestAdminRole()
itself now reads from, and added the missing "./auth/authz-schema" entry
to deno.json's exports map. This lets @dune/plugin-admin's role-utils.ts
(companion change, that repo) derive its own ROLE_RANK/highestValidRole()
from this instead of keeping a second, hand-maintained copy of the same
three numbers -- the exact "two tables kept in sync by convention"
pattern the ROLE_PERMISSIONS removal (PR #15) was about eliminating,
caught a second time during review of that same PR's follow-up commits.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
It never had an actionToRelations entry — panel access is canThey: "access"
on app:admin — and validate.ts already flags it as unknown.

Co-authored-by: Cursor <cursoragent@cursor.com>
requirePermission() is authz.check() only (missing authz denies). Update
the authz skill, plugin-authoring guards note, admin.authzStore comment,
and the authorization doc so operators do not debug a fallback that
cannot fire.

Co-authored-by: Cursor <cursoragent@cursor.com>
3.0.0 removes hasPermission(); this core no longer calls it. Keep the
pins aligned so a site that upgrades the built-in admin plugin does not
hit a TypeError on cookie-bearing content requests. deno.lock still
resolves 2.x until 3.0.0 is on JSR.

Co-authored-by: Cursor <cursoragent@cursor.com>
…commit

91d1efb bumped this to 2155d6e, a commit that only ever existed inside
this checkout's own docs/content working tree -- it was never pushed to
(or even present in) duneorg/dune-docs, because it was made by editing
the submodule checkout directly instead of the canonical
/Users/xrs/claude/dune-docs repo. Reverted the pointer back to 7601861
(dune-docs' actual current main tip) and reapplied the same doc edit
properly: duneorg/dune-docs#3, not yet merged. Bump the pointer again
once that lands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zumbrunn
zumbrunn merged commit 74e231f into main Aug 31, 2026
4 checks passed
zumbrunn added a commit that referenced this pull request Aug 31, 2026
Defers the @dune/plugin-admin@^3.0 pin bump to a follow-up release —
see the CHANGELOG entry for why bumping it now would break every site
with the admin panel enabled. Also fixes two stale users.manage test
assertions left over from PR #15's own branch (predated the removal
in 3336468, never reconciled during merge), and drops the version
number from ROADMAP.md's header so it stops going stale every release
(the thing #13 just fixed once already).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant