Repository navigation
Release db 0.7.3, storage 0.4.2, auth 0.7.6 (security fixes) - #90
Merged
Merged
Conversation
readAccess `none` and `owner` were enforced by checkAccess on REST reads,
but three other paths hand rows back without asking it:
- Live subscriptions. authorizeSubscribe special-cased `public` and
otherwise only verified the token, so any valid project token - a
self-minted guest token included, since guests are on by default -
got the snapshot and every later change of a `none` collection or
table, through /realtime and the table's own /subscribe socket. It
now refuses `none` before reading the token, as REST does.
- Raw SQL writes. A batch carrying any write was judged on writeAccess
alone, and every write gets RETURNING over the full row. On the
documented "append-only ingest" shape (read `none`, write `auth`),
`UPDATE t SET c = c` returned every row unchanged, and a SELECT tucked
into a write batch rode past the read mode. Each side a batch touches
is now judged on its own mode, and on a table the caller may not read
writes still land but return no rows - drizzle inserts keep working.
- Typed PUT/PATCH on tables and collections returned the merged stored
record. They now return only { id } when the caller would not pass
the read gate (mayReadBack in the shared access module), and the
OpenAPI document declares that as DbWriteResult.
Both attacks are pinned in db-readonly.api.spec.ts and were confirmed
to fail against the previous code: the socket answered with a snapshot,
and the no-op UPDATE returned another user's rows.
The raw-SQL gate admitted `WITH RECURSIVE`, and a table's /sql and a view's /sql run synchronously inside a single-threaded Durable Object. `WITH RECURSIVE c(x) AS (SELECT 1 UNION ALL SELECT x + 1 FROM c) SELECT count(*) FROM c` never terminates on its own, so any project token - a free guest token is enough - could hold a tenant's table until the runtime's CPU limit, and then do it again. This was reproduced on the local stack: with the old gate, the new e2e case froze the shard and every later SQL test in the run timed out. publicSqlRefusal binds only the public paths; operator SQL (console, copilot) keeps the full dialect. It is the same literal word match the internal-name scan uses, so a literal "recursive" has to be bound as a parameter.
The serve-time allowlist accepted any `video/<subtype>` and
`audio/<subtype>`, and the stored content type is whatever the uploader
sent. `video/x+xml` therefore went out `Content-Disposition: inline` -
and browsers render every `+xml` subtype as an XML document, so an XHTML
body uploaded under that label runs script. On the managed service the
agent object path shares the console's origin, which is exactly the
stored-XSS-against-operators case the allowlist exists to prevent; any
console sign-up could upload one to their own public bucket.
The list moves to src/inline.ts as exact types (common video and audio
spelled out) with a unit test that attacks it; the e2e disposition case
gains the +xml vectors and failed on the old pattern ("inline" served).
AGENTS.md now says why the list must never go back to a pattern.
Registry rows with a null org predate organizations (or were released by a console reset) and were open to ANY operator - "the self-hosted contract, where every operator is the same person". The managed console runs CONSOLE_SIGNUPS=open, where every stranger who registers is an operator, so any such row was full operator access for anyone with an account. The same assumption sat in the dashboard overview: an account with no active org called listProjects with no scope at all, which returns the whole registry - every tenant's project names and ids. Both legitimate holders of an unowned row are the console admin (the first account on a single-operator install is made admin automatically, and so is the owner reclaiming a reset console), so the admin role is now the key whatever the sign-up mode: the guard refuses everyone else, operator lists take an explicit ProjectScope that can never be "unscoped", and a non-admin with no org may not mint an unowned row it could never open. The rule is a pure module pinned by a unit test. Not covered end to end: the e2e stack has no way to create an unowned row through the API, which is the point.
Two redirects were built from request input with checks a browser does not share: - /login?next= kept any value starting with "/" but not "//". Browsers treat "\" as "/" in http(s) URLs, so next=/%5Cevil.example sent a signed-in operator from the console straight to evil.example. - The cloudflarebase.com -> frostbase.dev 301 resolved the raw pathname as a URL reference against the canonical origin, so a request for //evil.example/x answered Location: https://evil.example/x on our domain (if the edge passes the doubled slash through). safeNext now resolves the value the way a browser will and keeps it only if it stayed on the origin; movedLocation appends the path to the fixed canonical origin instead of resolving it. Both live in a pure module with a unit test that walks the bypass spellings.
On a claimed console (the self-host default) sign-up skips email verification, yet a pending invitation admits any sign-up for its address, /console/me listed invitations - ids included - by a bare email match, and Better Auth's accept-invitation only compares the session email with the invited one. Whoever registered an invited address before its owner could read the id and join the org with the invited role, reaching every project it owns. The id is now treated as the credential it is. /console/me lists invitations only for a verified address; an unverified account sees just the one whose id it presents (?invitation=, from the invite link). The console refuses Better Auth's by-email list-user-invitations. The invitation email links to /dashboard?invitation=<id>, and the org page offers "Copy link" so consoles without outbound mail can hand it over. Residual: someone can still register an invited address first and so block its owner from signing up - squatting, no longer a takeover. orgs.api.spec.ts now asserts the unlinked list is empty, the by-email endpoint is closed, and the link resolves; against the old agent the first assertion failed with the invitation listed.
…ter regex ESLint's no-control-regex refuses the character class the previous commit used, which would fail CI. Same rule, spelled as a character-code check.
Ships the security-audit fixes:
- db: readAccess none/owner now hold on live subscriptions and on write
responses (raw SQL RETURNING, typed PATCH/PUT), and public SQL refuses
recursive CTEs. PATCH/PUT answer { id } where the caller may not read
the record back.
- storage: inline rendering is an allowlist of exact types; video/*+xml
and audio/*+xml no longer render inline.
- auth: invitation ids reach only a verified address or the invite link,
and the invitation email now carries that link.
This branch was successfully deployed
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.
Security-audit fixes, released as db 0.7.3, storage 0.4.2, auth 0.7.6.
readAccess: none/ownernow hold on live subscriptions (/realtime,/tables/*/subscribe) and on write responses (raw-SQLRETURNING, typed PATCH/PUT →{ id }when the caller may not read back). Public SQL refuses recursive CTEs, which previously could hold a table shard until the CPU limit.video/*+xml/audio/*+xmlno longer render inline on the console origin./dashboard?invitation=<id>, emailed or copied from the org page); Better Auth's by-emaillist-user-invitationsis closed on the console./login?next=and the cloudflarebase.com 301 cannot redirect off-origin.Each fix ships a test that attacks it; the db, storage and invite tests were confirmed to fail against the previous code. Preview CI (Quality, E2E, all preview deploys, Workers Builds) is green on 4908fde.
Before or after merge: a read-only
SELECT count(*) FROM project WHERE org_id IS NULLon production D1 shows how many rows become admin-only.🤖 Generated with Claude Code