Skip to content

fix(databases): enforce transaction-staging permissions; accept documents.read on legacy transaction reads - #14754

Merged
ArnabChatterjee20k merged 5 commits into
mainfrom
security/db-transaction-authz
Oct 22, 2026
Merged

ArnabChatterjee20k merged 5 commits into
mainfrom
security/db-transaction-authz

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

Two authorization fixes on the Databases transaction surface, each with a regression that fails before the change and passes after.

Transaction staging permission bypass

Transactions/Operations/Create role-checked the raw $permissions before aggregating. The direct create/update/upsert endpoints call Permission::aggregate() first, so a write(...) aggregate expands to update+delete and every role is checked. Staging did not: write("<role you don't hold>") matched none of read/create/update/delete and was staged and persisted at commit unvalidated — a bypass of the "users may only grant roles they hold" control (and a latent escalation if any path later expands stored aggregates). This path is shared by the Databases, TablesDB, DocumentsDB and VectorsDB surfaces.

Fix: validate with Permissions([Read, Update, Delete, Write]), aggregate to [Read, Update, Delete], role-check the expanded set, and stage the canonical permissions.

Legacy transaction read scope

/v1/databases/transactions Get and XList were labeled rows.read (a TablesDB scope). A documents.read key — which can create/stage/commit transactions via documents.write — could not read its own transactions, while a rows.read-only key could. Fix: accept ['documents.read', 'rows.read'], matching the TablesDB variants.

Tests

  • TransactionPermissionsBase::testCannotStageUnauthorizedAggregatePermissions (Legacy + DocumentsDB): staging write(team:adminTeam) is 401 (was 201); write(user:self) stays 201.
  • LegacyTransactionsCustomServerTest::testLegacyTransactionReadsAcceptDocumentsReadScope: a documents.read key reads its own legacy transaction, 401 → 200.

🤖 Generated with Claude Code

…egacy transaction read scope

Transaction staging (Transactions/Operations/Create) role-checked the raw
$permissions without aggregating first, so a write() aggregate for a role the
caller does not hold slipped past the check and was persisted at commit. Validate
and aggregate (as the direct document endpoints do) before the role check, and
stage the canonical expanded permissions.

The legacy /v1/databases/transactions Get and XList routes were labeled rows.read
(a TablesDB scope); a documents.read key could not read its own transactions.
Accept ['documents.read','rows.read'] to match the TablesDB variants.

Refs appwrite-labs/cloud#6748, appwrite-labs/cloud#6751, appwrite-labs/cloud#6754

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR aligns the legacy Databases transaction surface with the TablesDB one: the transaction read routes now authorize callers holding either legacy documents.read or rows.read scope, and staged transaction operations validate their $permissions before commit, storing the expanded permission form exactly as the direct document endpoints do.

Files Change
Transactions/Get.php, Transactions/XList.php Scope label widened to ['documents.read', 'rows.read'] so legacy clients keep working alongside TablesDB callers.
Transactions/Operations/Create.php Staged document permissions are validated with the standard Permissions validator and expanded via Permission::aggregate before persisting, matching direct document-endpoint behavior; the bulk path keeps its permission-free fast path.
tests/e2e/.../TransactionPermissionsBase.php, LegacyTransactionsCustomServerTest.php New e2e trait and legacy-server test covering permission validation, expanded persisted form, and scope acceptance on both surfaces.

All scanned candidates were adjudicated as pre-existing or false positives, so no findings are reported.

Reviewed commit: fc94564

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changes follow the existing permission aggregation and TablesDB scope patterns, with regressions covering the reported behaviors.

Transaction operation staging now validates and expands aggregate permissions before persisting staged data, including bulk-operation payloads. The legacy transaction Get and List endpoints accept both documents.read and rows.read, with regression coverage for permission enforcement, aggregate expansion, and the legacy read scope.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php Validates staged permission values, expands write aggregates, and checks roles for non-privileged callers.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php Accepts either legacy documents.read or rows.read scope for transaction reads.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php Accepts either legacy documents.read or rows.read scope for transaction listing.
tests/e2e/Services/Databases/Transactions/LegacyTransactionsCustomServerTest.php Adds coverage that documents.read-scoped keys can get and list legacy transactions.
tests/e2e/Services/Databases/Transactions/TransactionPermissionsBase.php Adds coverage for unauthorized aggregate permission grants, canonical expansion, and malformed permission values across staged operations.

Reviewed c297f4e · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → security/db-transaction-authz (after).

Metric Before After Change
🚀 Requests/sec 211.37 214.54 ⚪ +1.5%
⏱️ Latency P50 80.54 ms 80.48 ms ⚪ -0.1%
⏱️ Latency P95 186.1 ms 191.17 ms ⚪ +2.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 80.48 191.17 13,680 214.54 +5.07
Account 147.82 283.24 720 12.04 +18.17
TablesDB 76.06 136.82 7,440 120.27 -3.98
Storage 78.47 184.73 3,600 59.27 -6.86
Functions 119.83 239.54 1,920 32.33 +29.59

Top API waits (after)

API request Max wait (ms)
functions.variables.update 503.5
storage.buckets.create 406.49
account.name.update 406.35
account.prefs.update 398.48
functions.create 381.14

…ller

Aggregation ran only in the non-privileged branch, so API keys and privileged
users staged a raw write(...) that the commit handler persisted unexpanded,
unlike the direct document endpoints. Validate and aggregate permissions for all
callers; keep the "roles you hold" check scoped to non-privileged callers.

Adds a regression that a key staging write(user:x) commits as update+delete(user:x).

Addresses review on #14754.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ArnabChatterjee20k

Copy link
Copy Markdown
Member Author

Addressed the review: validation + Permission::aggregate now run for every caller, so a privileged caller's staged write(...) is expanded to update+delete just like the direct document endpoints; the "roles you hold" check stays scoped to non-privileged callers. Added testStagingExpandsAggregatePermissionsForPrivilegedCallers — a key stages write(user:x), commits, and the document stores update/delete(user:x), not a raw write. (f8c0245)

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ArnabChatterjee20k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

…s too

The normalization only ran in the non-bulk branch, so staged bulkCreate/bulkUpsert
documents (and bulkUpdate data) kept raw write(...) aggregates that the commit
handler persisted verbatim, unlike the direct bulk endpoints. Extract a
normalizePermissions() helper and apply it to per-document bulk permissions.

Adds a bulkCreate regression that a staged write(user:x) commits as update+delete.

Addresses review on #14754.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ArnabChatterjee20k

Copy link
Copy Markdown
Member Author

Fixed in the latest push: extracted a normalizePermissions() helper and applied it to bulk payloads too — per-document permissions on bulkCreate/bulkUpsert and the bulkUpdate data block now have write(...) expanded to update+delete, matching the direct bulk endpoints. Added testStagingExpandsAggregatePermissionsForBulkCreate (a key stages bulkCreate with write(user:x), commits, and the row stores update/delete, not a raw write).

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

…psert

Extends the staging regressions beyond bulkCreate: bulkUpsert (per-document
permissions) and bulkUpdate (the data block's permissions) now also assert a
staged write(user:x) commits as update+delete, catching any shape mismatch that
would leave the raw aggregate unexpanded.

Addresses review on #14754.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ArnabChatterjee20k

Copy link
Copy Markdown
Member Author

Added testStagingExpandsAggregatePermissionsForBulkUpsert and testStagingExpandsAggregatePermissionsForBulkUpdate — both commit through the transaction and assert the persisted permissions have write(user:x) expanded to update+delete (bulkUpsert via per-document $permissions, bulkUpdate via the data block). Factored the shared collection/transaction setup into small helpers. All bulk paths (create/upsert/update) are now covered.

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

normalizePermissions() declared an array parameter, so a scalar $permissions value
in a staged operation raised a TypeError (500) before the Permissions validator
could return a clean 400. Accept mixed and reject a non-array value with
GENERAL_BAD_REQUEST. Adds a regression staging data.$permissions as a string.

Addresses review on #14754.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@ArnabChatterjee20k

Copy link
Copy Markdown
Member Author

Fixed: normalizePermissions() now takes mixed and rejects a non-array $permissions with GENERAL_BAD_REQUEST (400) instead of raising a TypeError (500). Added testStagingRejectsScalarPermissions (stages data.$permissions as a string, asserts 400).

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ArnabChatterjee20k
ArnabChatterjee20k merged commit d2d54bf into main Oct 22, 2026
39 checks passed
ChiragAgg5k pushed a commit that referenced this pull request Oct 24, 2026
)

Staging role-checked the raw permissions before aggregating, so write("<role not held>") was staged and committed unvalidated. Permissions are now validated, aggregated, role-checked and staged in canonical form. Legacy transaction Get and List also accept documents.read.

(cherry picked from commit d2d54bf)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…on-authz

fix(databases): enforce transaction-staging permissions; accept documents.read on legacy transaction reads

(cherry picked from commit d2d54bf)
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