Repository navigation
Require an administering credential for cross-account actions, and key rate limits on the connection address - #393
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
|
Same thing needed for copia? |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 toolsrestore_project,restore_clipandpurge_clip, which call them), the instance-wide part of issue reports (/api/report?instance=1,report_issue, the capabilities inme.get), the uploader details infonts.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.adminProcedurealready 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_PROXYwas 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:X-Forwarded-Foron each request and get a new limit bucket every time.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)inauth.tsis now the single rule: admin role andcanAdminister.actorOf,reportCapabilities/createReportZip,fonts.listand/api/healthuse it.reportCapabilitiesandcreateReportZiptake the requester rather than a bare role, so a caller cannot pass the role alone.test/admin-authority.test.tsscans 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 (inadminProcedure, and creating an admin key from a browser session) and carry arole-ok:comment.clientIp(headers, peer, trust)now gets the connection's address through Hono'sgetConnInfoand falls back to it whenever the header is not trusted, missing, or shorter thanTRUSTED_PROXY_HOPS. A network request therefore always has an address.::ffff:IPv4-mapped addresses are normalised.TRUST_PROXYnow defaults tofalse.TRUSTED_PROXIES, a list of addresses or CIDR ranges checked at boot. When set, the header is believed only on connections from those addresses.withClientIpalready resolved, instead of resolving it a second time.TRUST_PROXYis off, the app logs one warning per process. That covers installs behind a proxy that relied on the old default.install.sh,install.ps1) writeTRUST_PROXY=false, with a note on what to set behind a proxy.TRUST_PROXY=true, because the sign-up guard tests name each client inX-Forwarded-For.How it was tested
test/admin-authority-stack.test.ts(Postgres only, throughlifecycle-harness, calling the real router in-process): with a limited API key,deleted.purge/deleted.restore/projects.restoreon another account's deleted project return NOT_FOUND. With an OAuth caller,clips.purge/clips.restoredo the same. The admin's own session still restores. Againstorigin/main'ssrc, the two refusal cases and the guard test fail; on this branch they pass.test/abuse.test.tsgains cases for the fallback to the connection address, for one rate-limit key across different forwarded values, for the IPv4-mapped form and forTRUSTED_PROXIES(inside and outside the list, unknown peer, invalid entries). The tests that expectednullwithout a trusted proxy now expect the connection's address, which is the intended change.pnpm typecheck,pnpm exec biome ci(0 errors, 512 warnings, unchanged),pnpm guards, bothi18n:check,pnpm docs:check: pass.test:unitwithANTHROPIC_*unset: 1596 tests, 1593 pass. The 3 failures also fail onorigin/mainon this machine and are environmental (bumper crossfade with the local ffmpeg, theresources.test.tsdisk-lease figure, and theytdlp-proxyranking test, which is timing-flaky).admin-authority-stack,deleted,project-edits,projects-bulk,lifecycle-order,uow-atomic,stage-seq,render-gen): 50 of 50 pass.abuse-stack,signup-rules-stackand the rest). CI's stack workflow runs them withTRUST_PROXY=true.For the reviewer to decide or check
TRUST_PROXYwill now key every client on the proxy's address untilTRUST_PROXY=trueis set. The changeset isminor, says so in bold, and the app logs a warning. The other option is to keep the default on and rely on the installers writingfalse. That leaves the spoofing open for hand-written compose installs, so I did not take it.TRUST_PROXY=true, an emptyTRUSTED_PROXIESstill 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.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: