8000 fix(auth)!: require a sign-in to manage API keys by mwoods79 · Pull Request #733 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

fix(auth)!: require a sign-in to manage API keys - #733

Merged
mwoods79 merged 11 commits into
mainfrom
t3/require-signed-in-api-key-management
Dec 1, 2026
Merged

mwoods79 merged 11 commits into
mainfrom
t3/require-signed-in-api-key-management

Conversation

@mwoods79
@mwoods79 mwoods79 commented Nov 30, 2026 •
Copy link
Copy Markdown
Contributor

Summary

Managing API keys requires a sign-in. Owners can create, list and revoke keys from the API keys page or with a JWT from API sign-in. A request authenticated with an API key receives 403 for all three operations. The key continues to record its own use.

An administrator viewing as a member can review and revoke the member’s keys. The API keys page and agent setup guide show that key creation is unavailable during a viewing. The key creation form also ignores repeat submissions once the key is displayed.

Stopping a viewing, signing out and completing authentication now agree on which request closed it. When stop finishes first, the administrator keeps their restored sign-in. When authentication finishes first, a later stop cannot restore the previous identity. A viewing ended elsewhere continues as a signed-out visit, and the next browser request revokes its still-live viewing credential.

Evidence

  • Before: Software holding a key could manage its owner’s keys. After: The API returns 403 for create, list and revoke, including self-revocation. The owner’s sign-in still succeeds for each operation.
  • Before: A key could update a sibling key’s last-used time, and viewing as a member allowed creation of a lasting key. After: Only the authenticating key records use. The member’s key creation control is unavailable throughout the viewing. The before-and-after screenshots are in the PR comments.
  • Before: Overlapping authentication and viewing changes could invalidate the administrator’s restored sign-in. After: Deterministic tests cover sign-in and sign-out in both completion orders. Tests also cover public auth pages, protected mounts and reconnects after a viewing ends.

Merge Danger

Door: Two-way. No schema migration is required.

Blast Radius: Authentication

  • Clients that manage keys must use a sign-in. Existing keys continue to authenticate other permitted API, GraphQL and MCP requests.
  • The first request to close an active viewing determines the saved sign-in’s disposition. Browser response order can still determine which session cookie the browser keeps.

A request authenticated with an API key could create another key with a
later expiry, list the person's keys and revoke them. A key that leaked
was therefore not bounded by its expiry: it could issue its own successor
and remove the owner's other keys.

The ApiKey policies now refuse every action except recording the key's
own use to an actor signed in with a key, so the rule holds wherever keys
are managed. The read is refused outright rather than filtered to nothing,
and /api/auth/api_keys answers 403 with the reason instead of a 404 or an
empty list. A key cannot revoke itself either; nothing relied on it.

BREAKING CHANGE: POST, GET and DELETE on /api/auth/api_keys return 403
when authenticated with an API key. Sign in and send the JWT, or use the
API keys page.
An administrator viewing huddlz as a person could create an API key for
them on the API keys page. The creation was attributed in audit history,
but the key kept working after the impersonation ended.

Key creation is now refused for an actor carrying an impersonation, and
the API keys page says so instead of offering Create key. Listing and
revoking the person's keys still work, since neither outlasts the session.
A browser session keeps the viewed person's token and the id of the
impersonation. When that id stopped resolving, the marking was dropped and
the session carried on as an ordinary sign-in of the viewed person, held
by the administrator, with nothing refused or attributed any more.

Such a session is now nobody's sign-in. The next request revokes both
saved tokens, clears the session and continues signed out; a page already
open is sent to sign in when it next mounts, and that request ends the
session.
Recording a key's use was allowed to the key's owner, so a request
authenticated with one key could mark a sibling key of the same person as
used, and so could a plain sign-in. The policy now compares the key the
request was authenticated with, which is the only caller there is.
The refusal came from the resource, after the request had been validated,
so a key that sent a blank name or a zero expiry was answered 422 and a
malformed id 404. The three key-management endpoints now answer a request
authenticated with an API key 403 before looking at what it sent. The
ApiKey policies stay the rule; the controller no longer translates their
error because no such request reaches them.
The API keys page took `validate` and `create` events in any state. With
no form open, as when listing keys or viewing as someone, the event
crashed the page; with a new key on show, a repeated submit made a second
key. Both events now act only while the form is open.
The MCP guide and ADR-0012 said a key can do anything the JSON API
allows. Both now name the exception: a key cannot create, list or revoke
keys. The agent setup guide also stops offering "Create a key" while an
administrator is viewing as someone, matching the API keys page.
…is ended

Ending a session whose impersonation no longer resolves revoked both
saved tokens. When the viewing had just been stopped in the same
browser, a request already on its way with the old cookie then revoked
the sign-in the stop had restored. The viewing's token is still
revoked and the session emptied, but the administrator's token is only
dropped, and a session with nobody loaded is left as it is.
…mes a viewing

Ending a stale viewing rewrote the session, and a session that named a
viewing with nobody loaded was turned away from every page, public ones
included. A stale viewing now only has its token revoked, and with
nobody loaded the visitor is simply signed out: public pages open, and
signing in or out clears what is left.
@mwoods79
Copy link
Copy Markdown
Contributor Author

Screenshots of /profile/api-keys and /help/agents in a view-as session (an administrator viewing as Jamie Chen), on main and on this branch.
On this branch the Create key button and the guide's Create a key link are gone; both pages say "Keys can't be created while viewing as someone else."

API keys, one existing key

Before (main) After (this branch)
API keys page on main while viewing as someone: Create key button offered API keys page on this branch while viewing as someone: no Create key button, notice in its place

API keys, no keys

Before (main) After (this branch)
Empty API keys page on main while viewing as someone: Create key button offered Empty API keys page on this branch while viewing as someone: "This person has not created a key."

The empty-state box running past the panel's bottom edge is the same on main.

Connect an agent guide, step 1

Before (main) After (this branch)
Agent guide on main while viewing as someone: Create a key link Agent guide on this branch while viewing as someone: notice instead of the link

@mwoods79
mwoods79 merged commit 3ee880f into main Dec 1, 2026
5 checks passed
@mwoods79
mwoods79 deleted the t3/require-signed-in-api-key-management branch December 1, 2026 21:00
mwoods79 added a commit that referenced this pull request Dec 1, 2026
* origin/main:
  fix(social): send huddl details as literal text (#737)
  fix(auth)!: require a sign-in to manage API keys (#733)
mwoods79 added a commit that referenced this pull request Dec 1, 2026
…recipients

* origin/main:
  fix(huddl)!: keep a recurring series within its own group (#724)
  fix(social): send huddl details as literal text (#737)
  fix(auth)!: require a sign-in to manage API keys (#733)
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

0