Skip to content

OAuth connections act as the person who signed in - #13

Merged
jonradoff merged 2 commits into
mainfrom
security/oauth-identity
Nov 10, 2026
Merged

jonradoff merged 2 commits into
mainfrom
security/oauth-identity

Conversation

@jonradoff

Copy link
Copy Markdown
Collaborator

Why

OAuth access tokens were swapped for one stored admin API key before reaching the MCP tools, so every OAuth connection had admin rights whoever approved it. This is the first of three changes that tie agent access to a person, enforce the agent sandbox on the server, and make merging an agent's own fork an explicit permission.

What changes

Identity

  • A connection is now an OAuth grant naming the person who approved it. Codes and tokens belong to a grant, and each request loads that person's current role, so a role change, a disabled account or a revoked connection takes effect at once.
  • The shared "System (OAuth)" key is gone. At startup the server deletes the key and the stored copy of its value.
  • /mcp calls the REST API in-process as the caller. No credential is held by a session or sent over a socket, and the MCP SDK's session check binds each session to the credential that opened it.

Tokens and endpoints

  • Tokens are issued for this server's /mcp resource only (RFC 8707). A request naming another resource is refused, and one naming none gets /mcp.
  • OAuth tokens are refused at /api/v1, where they already ended in 403. /mcp no longer accepts a browser cookie.
  • Authorization codes and refresh-token rotation are atomic. A used refresh token replayed more than 30 seconds after rotation revokes the connection.
  • /oauth/revoke works (RFC 7009) and requires the client's credentials.
  • Registration is rate limited per address, size-limited, and accepts only https or loopback http redirects. The same rules apply to clients registered earlier.
  • The consent page names the account the app will act as, the role it gets and the host the browser returns to. The approval proof is bound to that account. Accounts still on a temporary password can't connect apps.

Roles hold

  • An API key whose owner is disabled or can't be loaded is refused. Only a key with no owner on record is adopted by an admin, and it keeps its scopes and sandbox flag.
  • Creating, bulk-creating, updating or importing content as published, turning on an import source's auto-publish, triggering one, and merging with publish_new all need content.publish.
  • POST /api/v1/assets no longer reads a file_path on the server. The hosted MCP endpoint's upload_asset no longer reads the server's disk; the stdio binary still reads local files.

Records

  • Changes made through /mcp are recorded as agent changes with a server-generated agent session. The audit log names the API key or connection used.

The /api/v1 route table moves from cmd/server/main.go to internal/handlers/api_routes.go, so tests can walk the real routes.

Upgrade note

Existing OAuth connections have to sign in again once. API keys are unaffected.

Tests

New tests cover the credential resolver, the OAuth grant lifecycle, concurrent code and refresh exchanges, replay, revocation, consent binding, the in-process MCP transport and session binding, publish permission on every path above, and an end-to-end run through /mcp with real tokens. In that run a viewer can read but not write, an editor can't change site configuration, a revoked connection stops mid-session, and changes are attributed to the agent and the connection. go test -p 1 ./... passes.

🤖 Generated with Claude Code

jonradoff and others added 2 commits November 9, 2026 21:11
OAuth tokens used to be swapped for a single stored admin key, so every
connection had admin rights whoever approved it. A connection is now a
grant that names the person; each request loads their current role, and
the shared key is gone (removed from the database at startup).

- /mcp calls the REST API in-process as the caller. No credential is
  held by a session or crosses a socket, and each MCP session is bound
  to the credential that opened it.
- Tokens are bound to this server's /mcp resource. OAuth tokens are no
  longer accepted at /api/v1, and /mcp no longer accepts a cookie.
- Authorization codes and refresh tokens are atomically single-use. A
  replayed refresh token ends the connection. /oauth/revoke works.
- Client registration is rate limited and limited in size; redirects
  must be https or loopback. The consent page says who the app will act
  as and where the browser goes next.
- An API key is refused if its owner is disabled or can't be loaded.
  Only a key with no owner on record is adopted, and it keeps its limits.
- Requests that set `published` now need content.publish.
- Agent work is recorded as agent work with a server-generated session,
  and the audit log names the key or connection.
- Asset uploads no longer read paths on the server's disk.

The /api/v1 route table moves to internal/handlers so tests can walk it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Reverting to a version, or restoring a deleted page, that changes
  whether a live page is published now needs content.publish.
- One active grant per person and client is enforced by a unique
  partial index; a racing second approval reuses the first grant.
- A used refresh token is excused only within 10 seconds of rotation.
- Access tokens never begin with "lc_", which marks an API key.
- The consent page no longer points at a page that doesn't exist yet.
- Session binding is tested for GET and DELETE as well as POST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonradoff

Copy link
Copy Markdown
Collaborator Author

Independent review (a different model) found: version revert and restore could change what is published without content.publish (edit-scoped keys); the consent page pointed at a page this PR doesn't add; two racing approvals could create two grants. All fixed in 65fe5c3, which also shortens the refresh-reuse window to 10 seconds, keeps access tokens from ever starting with lc_, and tests session binding for GET and DELETE. Areas it checked and found sound: no network path to the in-process caller, session binding, the route move, code/refresh atomicity, the consent proof, and compatibility with the stdio binary.

@jonradoff
jonradoff merged commit 76366d3 into main Nov 10, 2026
3 checks passed
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