Repository navigation
fix(databases): resolve joins by public table id only - #14535
Conversation
A join named its table either by public ID or by the internal name
database_{dbSeq}_collection_{N}, which the hook resolved through a sequence
lookup. Internal names are never exposed by the API, so accepting them let a
guest count N upwards and tell existing, readable and missing tables apart by
the 200, 401 and 404 responses without knowing a single table ID.
The hook now looks the join up by public ID in the current database's
registry and nothing else, for every caller, API keys included. A table the
caller may not join (disabled, or neither table-level read nor row security)
is refused with the same not-found error as a table that does not exist, so a
non-privileged caller can no longer distinguish "exists but forbidden" from
"missing" through a join. Row-security tables stay joinable without table
read, the database still filters their rows, and privileged callers and
reads that skip authorization keep joining every table.
Every read path that accepts joins (list, POST query, get, transactions, the
legacy documents API and GraphQL) builds its database through
getDatabasesDB, which registers this hook, so the fix covers all of them.
Column references qualified by a table name instead of a join alias were
already rejected by the query validator; E2E now pins that down.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 2 nitpicks below. 🧹 Nitpicks (2) — 🟢 2 low
The PR reworks
Reviewed commit: 1cfc736 |
🟢 Tier S · Ready to merge
Join targets now resolve only through public table or collection IDs in the current database registry, and inaccessible targets are returned as not found for non-privileged callers. Unit and API tests cover public-ID resolution, permissions, internal-name rejection, and the REST, transaction, and GraphQL paths. The qualified-column test now excludes the development error trace, which echoes the submitted query, when checking for returned private data. Latest changes: The newest commit excludes the echoed development trace from the qualified-column test's private-data response assertion.
📂 Walkthrough · 5
Merged |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
…egex GraphQL resolves joins through the same hook as REST, so it needs the same regression: a join by an internal table name must be refused exactly as a missing table, for guests, users and API keys alike. The internal-name lookup moves to a shared InternalTableName trait so both suites build the name the same way, and it checks the sequences with ctype_digit and explode instead of regular expressions, which AGENTS.md bans. Co-Authored-By: Claude Opus 5.5 <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…lumn refusals The development error response carries a trace whose Swoole request args echo the caller's own query string. The filter attempts put the secret marker in their own filter value, so the leak assertion matched the caller's input rather than leaked row data, failing every Legacy and TablesDB variant on the Postgres (dedicated) lane even though each refusal was the expected 400. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Release blocker for the query-lib migration (#11649), found by staging QA of appwrite-labs/cloud#5410.
Problem (security)
Joins accepted the internal table name
database_{seq}_collection_{N}as well as the public ID. A guest could count up through N and tell existing, readable and missing tables apart from the 200, 401 and 404 responses.Fix
src/Appwrite/Utopia/Database/Hook/Joins.phpnow resolves the join target only by public ID, in the current database's registry. The internal-name fallback is gone for every caller.table_not_found/collection_not_found.getDatabasesDB: list,POST /query, single-row GET, transactions, the legacy API and GraphQL.Behaviour change
Joining a table with no table-level read and no rowSecurity used to return 401
user_unauthorized. It now returns 404, so the response can't be used as an oracle. A direct list of such a table still returns 401.Two existing tests were updated:
testDocumentSecurityOffCollectionDenyintests/e2e/Services/Databases/Queries/JoinPermissions.phpand its GraphQL twin.Tests
tests/unit/Utopia/Database/Hook/JoinsTest.phphas 40 tests. 10 of them fail on the old hook.JoinPermissions.php:testJoinByInternalTableNameIsNotFoundtestJoinByInternalTableNameInATransactionReadIsNotFoundtestJoinOfAnUnreadableCollectionIsIndistinguishableFromAMissingOnetestColumnQualifiedByInternalTableNameIsInvalid🤖 Generated with Claude Code