Skip to content

Require an administering credential for cross-account actions, and key rate limits on the connection address - #393

Merged
dillonstreator merged 2 commits into
mainfrom
fix/admin-credential-client-ip
Nov 28, 2026
Merged

dillonstreator merged 2 commits into
mainfrom
fix/admin-credential-client-ip

Conversation

@dillonstreator

@dillonstreator dillonstreator commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixes two findings from the 2026-11-28 audit: GAP-AUTHZ-001 (with its Info sibling GAP-HTTP-002) and SEC-001.

What was wrong

Admin authority (GAP-AUTHZ-001, GAP-HTTP-002). A few places decided "may this request reach other accounts?" from the account's admin role alone, and ignored whether the credential is allowed to administer. That covered restore and permanent purge of deleted projects and clips (deleted.restore/deleted.purge, projects.restore, clips.restore/clips.purge, and the MCP tools restore_project, restore_clip and purge_clip, which call them), the instance-wide part of issue reports (/api/report?instance=1, report_issue, the capabilities in me.get), the uploader details in fonts.list, and the resource numbers on /api/health. So an admin's API key made without "instance administration", or an MCP connector signed in through OAuth, could restore or permanently delete other accounts' deleted items and download instance diagnostics. adminProcedure already refuses those credentials.

Client address (SEC-001). The address used for the sign-in/sign-up rate limits, the accounts-per-address cap and the OAuth registration cap came only from a forwarding header, and TRUST_PROXY was on by default. Nothing ever used the connection's own address. On an install with the port published directly, which is what the compose files and installers set up:

  • A client could send a different X-Forwarded-For on each request and get a new limit bucket every time.
  • Ordinary browsers send no such header, so they all shared one bucket, and a few failed sign-ins from anyone locked everybody out for a short time.
  • With TRUST_PROXY=false, the documented setting for this shape, every request went into that shared bucket and the per-address guards were off.

What changed

  • actsAsAdmin(who) in auth.ts is now the single rule: admin role and canAdminister. actorOf, reportCapabilities/createReportZip, fonts.list and /api/health use it. reportCapabilities and createReportZip take the requester rather than a bare role, so a caller cannot pass the role alone.
  • Guard: test/admin-authority.test.ts scans the request paths (trpc/, http.ts, mcp.ts, report/) and fails on any new role-only admin check. The two remaining role checks are about the account itself (in adminProcedure, and creating an admin key from a browser session) and carry a role-ok: comment.
  • clientIp(headers, peer, trust) now gets the connection's address through Hono's getConnInfo and falls back to it whenever the header is not trusted, missing, or shorter than TRUSTED_PROXY_HOPS. A network request therefore always has an address. ::ffff: IPv4-mapped addresses are normalised.
  • TRUST_PROXY now defaults to false.
  • New optional TRUSTED_PROXIES, a list of addresses or CIDR ranges checked at boot. When set, the header is believed only on connections from those addresses.
  • The sign-up guard reads the address withClientIp already resolved, instead of resolving it a second time.
  • When a request carries the proxy header while TRUST_PROXY is off, the app logs one warning per process. That covers installs behind a proxy that relied on the old default.
  • The installers (install.sh, install.ps1) write TRUST_PROXY=false, with a note on what to set behind a proxy.
  • The stack workflow sets TRUST_PROXY=true, because the sign-up guard tests name each client in X-Forwarded-For.
  • Updated docs: README, SECURITY.md, deploy/README.md, EVALS.md, THREAT-MODEL Release #2, and the generated config reference.

How it was tested

  • New test/admin-authority-stack.test.ts (Postgres only, through lifecycle-harness, calling the real router in-process): with a limited API key, deleted.purge/deleted.restore/projects.restore on another account's deleted project return NOT_FOUND. With an OAuth caller, clips.purge/clips.restore do the same. The admin's own session still restores. Against origin/main's src, the two refusal cases and the guard test fail; on this branch they pass.
  • test/abuse.test.ts gains cases for the fallback to the connection address, for one rate-limit key across different forwarded values, for the IPv4-mapped form and for TRUSTED_PROXIES (inside and outside the list, unknown peer, invalid entries). The tests that expected null without a trusted proxy now expect the connection's address, which is the intended change.
  • Run locally:
    • pnpm typecheck, pnpm exec biome ci (0 errors, 512 warnings, unchanged), pnpm guards, both i18n:check, pnpm docs:check: pass.
    • test:unit with ANTHROPIC_* unset: 1596 tests, 1593 pass. The 3 failures also fail on origin/main on this machine and are environmental (bumper crossfade with the local ffmpeg, the resources.test.ts disk-lease figure, and the ytdlp-proxy ranking test, which is timing-flaky).
    • Postgres-only suites against a scratch Postgres 17 migrated to this branch (admin-authority-stack, deleted, project-edits, projects-bulk, lifecycle-order, uow-atomic, stage-seq, render-gen): 50 of 50 pass.
  • Not run locally: the stack tests that need the running app (abuse-stack, signup-rules-stack and the rest). CI's stack workflow runs them with TRUST_PROXY=true.

For the reviewer to decide or check

  • The default change is visible to operators. An instance behind a reverse proxy that never set TRUST_PROXY will now key every client on the proxy's address until TRUST_PROXY=true is set. The changeset is minor, says so in bold, and the app logs a warning. The other option is to keep the default on and rely on the installers writing false. That leaves the spoofing open for hand-written compose installs, so I did not take it.
  • With TRUST_PROXY=true, an empty TRUSTED_PROXIES still trusts the header from any connection, as before. Should the default be loopback plus private ranges instead? I left it empty because Docker's userland proxy can make outside clients appear from the bridge gateway.
  • To check by hand after deploy: behind Caddy or nginx with TRUST_PROXY=true, sign-ups record the visitor's address in Users, not the proxy's.

Findings left out of this PR

The other fixes from the same audit are in the companion PRs, each independent of this one: #394 (install and runtime defaults), #395 (input, render and API hardening) and #396 (accessibility). Their descriptions list what was skipped and why. Not attempted anywhere:

  • GAP-ZAP-001 needs a product decision.
  • Billing beyond GAP-BILL-001 was out of scope. GAP-BILL-001 itself needs a Stripe call that cannot sit inside the owning transaction.
  • CONS-001: Better Auth runs its after-hooks after its own commit.
  • LLM-002, SUP-001 and UX-002 are not small, unambiguous fixes.

…her accounts

Restoring and purging deleted projects and clips, the report's instance
diagnostics, the font uploader details and /api/health details checked only
the account's admin role. An admin's API key made without instance
administration, or an MCP/OAuth connector, could therefore restore or
permanently delete other accounts' deleted items and download instance-wide
diagnostics, which adminProcedure already refuses those credentials.

The class is a role-only admin check outside adminProcedure. actsAsAdmin in
auth.ts is now the one rule (the admin role and canAdminister), read by
actorOf, reportCapabilities, fonts.list and /api/health; MCP builds its caller
with the credential's canAdminister, so restore_project, restore_clip and
purge_clip follow it too. admin-authority.test.ts scans the request paths
(trpc, http.ts, mcp.ts, report) for a role-only check; the two that are about
the account itself carry a role-ok comment. admin-authority-stack.test.ts
runs the procedures in-process against Postgres.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
…y when told to

clientIp read the client address only from a forwarding header, with
TRUST_PROXY on by default, and never from the socket. On an install with the
port published directly (what the compose files and installers set up), a
client chose its address per request with X-Forwarded-For and got a fresh
sign-in and sign-up bucket each time, while browsers that send no header all
shared Better Auth's one no-address bucket. TRUST_PROXY=false, the documented
setting for that shape, turned every per-address guard off.

clientIp now takes the connection's address (requestPeer, Hono's
getConnInfo) and returns it whenever the header is not trusted, missing or
shorter than TRUSTED_PROXY_HOPS, so it is never null on a network request.
TRUST_PROXY defaults to false; TRUSTED_PROXIES (addresses or CIDR ranges,
checked at boot) limits whose header is believed. The sign-up guard reads the
address withClientIp resolved instead of resolving it again. A request that
carries the proxy header while TRUST_PROXY is off logs one warning per
process, for installs behind a proxy that relied on the old default.

The installers write TRUST_PROXY=false with a note on what to set behind a
proxy; the stack workflow sets TRUST_PROXY=true because the sign-up guard
tests name each client in X-Forwarded-For. Docs and generated config
reference updated.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reelsaw-website Ready Ready Preview Nov 28, 2026 7:07pm UTC

Request Review

@adavila0703

Copy link
Copy Markdown
Member

Same thing needed for copia?

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.

2 participants