Skip to content

fix(agents): avatar admin gate must load role from DB — req.user has no role on JWT sessions - #1065

Merged
lilyshen0722 merged 2 commits into
mainfrom
fix/agent-avatar-admin-gate-jwt-shape
Aug 21, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
fix/agent-avatar-admin-gate-jwt-shape

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Follow-up to #1061, found during live verification: the admin branch of the avatar-edit gate tested req.user.role, but middleware/auth.ts sets req.user = { id } for JWT (browser) sessions — role exists only on the cm_ API-token path. Net effect: admins without an installation saw no edit affordance (reproduced on fc-verify). Fix loads the caller's role with one indexed read; test suite now pins both req shapes. Installer path was and remains correct (E2E-proven live on codex-impl: PUT → public profile → inline-SVG render, then restored).

🤖 Generated with Claude Code

https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8

middleware/auth.ts populates req.user = { id } for JWT logins — role rides
only on the cm_ API-token branch. So the avatar gate's req.user?.role check
never fired for a human in a browser; the affordance appeared only via the
installer path. Found live on fc-verify (admin, no installation, no button)
minutes after deploy. The gate now loads the caller's role from DB (one
indexed read), keeping the req.user.role fast path for API tokens.
The original admin test injected role onto req.user — the API-token shape —
which is exactly how the bug hid. New case: req.user = { id } only, role
resolved from DB, installation lookup untouched.
@lilyshen0722
lilyshen0722 merged commit 79aabef into main Aug 21, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/agent-avatar-admin-gate-jwt-shape branch August 21, 2026 04:18
lilyshen0722 added a commit that referenced this pull request Aug 21, 2026
ADR-022 Phase 0 (persona plan, docs/plans/2026-08-20-persona-v2-phased-
rollout.md). Measured on production: 31 of 45 active registry rows are smoke
seats (fc-verify, target, alice, bob, one row with an EMPTY name), fleet
internals (fable-lead, ux-lead, sprint-review), and personal wrappers
(xu-claude-code-local, laptop-codex). The verified flag is already the
curation boundary in the data — all 14 verified rows are the deliberate
catalog — so the route now forces verified-only for non-admins REGARDLESS of
query params; ?verified=false cannot reopen the leak. Admins keep the full
view for registry ops. Role loads from the DB, not req.user — JWT sessions
carry { id } only (the #1065 lesson, second application today).
lilyshen0722 added a commit that referenced this pull request Aug 21, 2026
…ADR-022 Phase 0) (#1072)

* fix(registry): seal the catalog leak — non-admins get verified rows only

ADR-022 Phase 0 (persona plan, docs/plans/2026-08-20-persona-v2-phased-
rollout.md). Measured on production: 31 of 45 active registry rows are smoke
seats (fc-verify, target, alice, bob, one row with an EMPTY name), fleet
internals (fable-lead, ux-lead, sprint-review), and personal wrappers
(xu-claude-code-local, laptop-codex). The verified flag is already the
curation boundary in the data — all 14 verified rows are the deliberate
catalog — so the route now forces verified-only for non-admins REGARDLESS of
query params; ?verified=false cannot reopen the leak. Admins keep the full
view for registry ops. Role loads from the DB, not req.user — JWT sessions
carry { id } only (the #1065 lesson, second application today).

* test(registry): pin the verified gate from both sides

Default verified-only; verified=false from a non-admin stays sealed; admin
passthrough works; explicit verified=true skips the role read; parked
moltbot rows stay excluded even when verified.

* fix(registry): rate-limit the catalog router (CodeQL js/missing-rate-limiting)

Same limiter shape as agentProfile: 120 req/min/IP keyed through
cf-connecting-ip, skipped in tests. The gate added a per-request role
lookup, which is what surfaced the route's pre-existing unlimited state.

* test(service): the listable fixture declares verified, as real listings do

The gate hid the unverified fixture from the member — working as designed
against a fixture that predates the rule. The test's actual subject
(ephemeral exclusion) is untouched: that row stays unverified AND ephemeral.
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