Skip to content

test: authorization and input validation e2e coverage - #14064

Merged
abnegate merged 7 commits into
mainfrom
cursor/authz-input-validation-e2e-4968
Oct 8, 2026
Merged

abnegate merged 7 commits into
mainfrom
cursor/authz-input-validation-e2e-4968

Conversation

@abnegate

@abnegate abnegate commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds e2e coverage for authorization and input-validation behaviour across several API surfaces, extending existing suites rather than adding a new framework. Tests only — no runtime changes.

Already covered on main (unchanged here)

  • Account tokens and recovery with a sessions.write key return an empty secret: AccountCustomServerTest::testCreateTokenWithSessionsKey, MockPhonesSessionIntegrationTest::testMockPhoneSessionWithSessionsKey
  • Staged documents in a foreign transaction are not readable: TransactionPermissionsBase::testUserCannotReadAnotherUsersStagedDocuments
  • Related $permissions on one-to-one create/update/upsert and on create staging: DatabasesBase::testCreateRelatedPermissions, TransactionPermissionsBase::testCannotSetUnauthorizedRelatedPermissions, testCannotRecreateRelatedWithUnauthorizedPermissions
  • Screenshot header allowlist (Accept, Accept-Language only), plus unsafe header values: AvatarsBase::testGetScreenshot

Added

Area Test What it asserts
Avatars (REST) AvatarsBase::testGetRemoteURLNotPublic image, favicon and screenshots return 400 general_argument_invalid for loopback, link-local metadata, RFC1918, [::1], [::ffff:127.0.0.1], internal hostnames, numeric hosts, userinfo URLs, file://, gopher://
Avatars (GraphQL) GraphQL\AvatarsTest::testGetRemoteURLNotPublic The same URL validation applies when the routes are called through GraphQL
Users / API keys UsersCustomServerTest::testCreateTokenWithSessionsKey A sessions.write key gets 401 on POST /users/:id/tokens, /jwts, password/email updates, MFA recovery codes, and account-scoped routes. Positive control: a users.write key still receives the token secret and a JWT
Users / sessions UsersCustomServerTest::testListSessionsWithoutSecret GET /users/:id/sessions with a sessions.read key does not return the session secret, and replaying the listed value (raw or store-encoded) as x-appwrite-session returns 401
Transactions TransactionPermissionsBase::testUserCannotStageRecordsInAnotherUsersTransaction A foreign transactionId on record-route create/update/upsert/delete returns 404, the owner's transaction stays at 0 operations, and the document is unchanged. Positive control: staging into your own transaction still works
Transactions TransactionPermissionsBase::testUserCannotStageBulkOperations User sessions get 401 for bulkCreate, bulkUpdate, bulkUpsert, bulkDelete staging
Transactions TransactionPermissionsBase::testCannotStageUnauthorizedRelatedPermissionsOnUpdate Related-document roles are enforced for staged update/upsert operations, and for record-route create/update/upsert that carry a transactionId. Positive control: own roles stage fine
Databases DatabasesBase::testCreateRelatedListPermissions Foreign roles on any item of a one-to-many list, or on a grandchild nested under a related document, return 401 for client sessions (create, update, upsert) and still succeed for server/console. Positive control: unchanged permissions on an existing related document can be sent back
Locale / client IP LocaleCustomClientTest::testGetClientIp Headers outside _APP_TRUSTED_HEADERS (x-real-ip, cf-connecting-ip, true-client-ip, forwarded, …) do not set the client IP; invalid X-Forwarded-For values fall back to the connection address. Positive control: a valid forwarded address from the internal hop is honoured

The transaction and database tests use the shared traits, so they run for Legacy, TablesDB and DocumentsDB. The relationship cases skip on DocumentsDB, which has no relationships. Every test fits the existing CI jobs: Avatars, GraphQL, Users, Locale, Databases, TablesDB. No new @group is needed.

Not in this PR

  • Trusted proxy CIDR list and placeholder signing/installer secrets. Covered by the unit tests in fix: close remaining medium issues #14048 (TrustedProxiesTest, EncryptionKeyTest, SecretTest, RequestTest). Not repeated here. testGetClientIp only uses behaviour that holds before and after that PR (loopback and RFC1918 hops stay trusted by default).
  • Screenshot navigation and redirect destination checks inside the browser. These depend on the browser image bump, which isn't on main. Only first-hop URL validation is asserted here.
  • Reserved project IDs on Cloud. Cloud-only, so it can't be simulated in CE e2e. Follow-up for the Cloud repo.

Test Plan

Pint (--config pint.json), the Rector dry-run (tests/tools/rector.php) and PHPStan (level 4) pass on the changed files.

All new tests were run against a local docker compose stack built from this branch and pass:

Suite Result
Avatars (REST, 3 sides) testGetRemoteURLNotPublic 3 tests, 264 assertions
GraphQL AvatarsTest::testGetRemoteURLNotPublic 1 test, 51 assertions
UsersCustomServerTest (2 new tests) 2 tests, 64 assertions
Transactions permissions, Legacy / TablesDB / DocumentsDB 3 + 3 + 3 tests, all pass (relationship case skips on DocumentsDB)
testCreateRelatedListPermissions on Legacy and TablesDB, client / server / console 6 suites pass
LocaleCustomClientTest::testGetClientIp 1 test, 44 assertions

As a sanity check, validateRelatedPermissions was temporarily short-circuited locally. testCreateRelatedListPermissions then failed with 201 instead of 401. That change was reverted and is not part of this PR.

Run them individually with:

docker compose exec appwrite test tests/e2e/Services/Avatars --filter=testGetRemoteURLNotPublic
docker compose exec appwrite test tests/e2e/Services/GraphQL/AvatarsTest.php --filter=testGetRemoteURLNotPublic
docker compose exec appwrite test tests/e2e/Services/Users/UsersCustomServerTest.php --filter='testCreateTokenWithSessionsKey|testListSessionsWithoutSecret'
docker compose exec appwrite test tests/e2e/Services/Databases/Transactions --filter='testUserCannotStageRecordsInAnotherUsersTransaction|testUserCannotStageBulkOperations|testCannotStageUnauthorizedRelatedPermissionsOnUpdate'
docker compose exec appwrite test tests/e2e/Services/TablesDB/Transactions --filter='testUserCannotStageRecordsInAnotherUsersTransaction|testUserCannotStageBulkOperations|testCannotStageUnauthorizedRelatedPermissionsOnUpdate'
docker compose exec appwrite test tests/e2e/Services/Databases --filter=testCreateRelatedListPermissions
docker compose exec appwrite test tests/e2e/Services/TablesDB --filter=testCreateRelatedListPermissions
docker compose exec appwrite test tests/e2e/Services/Locale/LocaleCustomClientTest.php --filter=testGetClientIp

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (N/A — tests only)
Open in Web Open in Cursor 

cursoragent and others added 5 commits October 2, 2026 03:54
…atar

Covers image, favicon and screenshots over REST and GraphQL: loopback,
link-local metadata, RFC1918, IPv6 loopback and IPv4-mapped literals,
internal hostnames, numeric hosts, userinfo and non-http schemes.

Co-authored-by: Jake Barnby <[email protected]>
A sessions.write key gets 401 on user tokens, JWTs, password/email
updates, MFA recovery codes and account-scoped routes, while a
users.write key still receives token secrets and JWTs. Listing sessions
does not return a secret that can be replayed as a session.

Co-authored-by: Jake Barnby <[email protected]>
A foreign transaction ID cannot be used to stage create, update, upsert
or delete through the record routes, users cannot stage bulk
operations, and related-document permissions are enforced for staged
update/upsert operations and record routes that carry a transactionId.

Co-authored-by: Jake Barnby <[email protected]>
Foreign roles on any item of a one-to-many list, or on a grandchild
nested under a related document, are rejected for client sessions on
create, update and upsert. Unchanged permissions on an existing related
document can still be sent back.

Co-authored-by: Jake Barnby <[email protected]>
…lues

Headers outside _APP_TRUSTED_HEADERS (x-real-ip, cf-connecting-ip,
forwarded, ...) do not set the client IP, and invalid X-Forwarded-For
values fall back to the connection address.

Co-authored-by: Jake Barnby <[email protected]>
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/authz-input-validation-e2e-4968 (after).

Metric Before After Change
🚀 Requests/sec 195.19 198.1 ⚪ +1.5%
⏱️ Latency P50 86.98 ms 89.04 ms ⚪ +2.4%
⏱️ Latency P95 212.82 ms 200.09 ms 🟢 -6%
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 89.04 200.09 12,540 198.1 -12.73
Account 161.46 311.3 660 11.07 -20.41
TablesDB 86.11 159.44 6,820 109.99 +2.83
Storage 81.34 176.11 3,300 54.94 -15.09
Functions 125.63 230.21 1,760 29.9 -44.29

Top API waits (after)

API request Max wait (ms)
account.name.update 484.21
functions.delete 461.55
account.get 351.78
storage.buckets.create 350.86
tablesdb.rows.create 343.96

@abnegate
abnegate marked this pull request as ready for review October 8, 2026 02:16
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 GraphQL SSRF test covers 4 of 13 REST vectors (AvatarsTest.php:150) — The new REST test testGetRemoteURLNotPublic asserts rejection of 13 SSRF vectors, but the GraphQL twin only covers 127.0.0.1, 169.254.169.254, [::1], and localhost (tests/e2e/Services/GraphQL/AvatarsTest.php:150).

This PR is test-only: six files under tests/e2e/ add coverage for security-sensitive server behaviors with no production code changes.

Files Change
tests/e2e/Services/Avatars/AvatarsBase.php, tests/e2e/Services/GraphQL/AvatarsTest.php Add remote-URL SSRF rejection tests (loopback, mapped/decimal IPs, metadata hosts) across REST and GraphQL avatars endpoints.
tests/e2e/Services/Locale/LocaleCustomClientTest.php Add testGetClientIp covering trusted-header IP resolution, X-Forwarded-For parsing, and invalid-value fallback.
tests/e2e/Services/Users/UsersCustomServerTest.php Add scope-isolation tests asserting a sessions.write key cannot mint tokens/JWTs, change credentials, or read MFA codes.
tests/e2e/Services/Databases/DatabasesBase.php, tests/e2e/Services/Databases/Transactions/TransactionPermissionsBase.php Add related-document permission and transaction staging permission tests, including foreign-role rejection and leaked-transaction isolation.

Reviewed commit: c6ac6aa

@ghost

ghost commented Oct 8, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No actionable defects were found in the incremental changes.

Adds end-to-end authorization and input-validation coverage across Avatars, GraphQL, Users, Databases, Transactions, and Locale, including negative cases and positive controls. Shared database and transaction tests exercise supported backends, with relationship-specific cases skipped where relationships are unavailable.

Latest changes: The newest commits remove literal IPv4 and IPv6 loopback targets that the e2e stack allowlists, and retarget the credentialed and gopher URL cases to private IPv4 addresses.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
tests/e2e/Services/Avatars/AvatarsBase.php Covers rejection of non-public and unsupported remote URL targets on REST avatar-fetch routes.
tests/e2e/Services/Databases/DatabasesBase.php Covers related-list and nested related-record permission validation across create, update, and upsert.
tests/e2e/Services/Databases/Transactions/TransactionPermissionsBase.php Covers transaction ownership, restrictions on user bulk staging, and related-permission checks during staged operations.
tests/e2e/Services/GraphQL/AvatarsTest.php Checks that GraphQL avatar resolvers reject non-public remote URL targets.
tests/e2e/Services/Locale/LocaleCustomClientTest.php Covers trusted client-IP header selection and fallback behavior for invalid forwarded addresses.
tests/e2e/Services/Users/UsersCustomServerTest.php Covers sessions.write key authorization and prevents listed session values from being replayed as credentials.

Reviewed the commits since c6ac6aa · 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 S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • 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.

The docker env sets _APP_ALLOWED_INTERNAL_ADDRESSES to 127.0.0.1 and ::1,
so those literals are fetched (404) instead of rejected as invalid URLs.
Keep hostnames, non-http schemes, and non-allowlisted IPs, and match the
GraphQL coverage to the REST list.
@abnegate

abnegate commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Addressed the Tenki nitpick on GraphQL SSRF coverage in 97004f3: GraphQL now uses the same URL list as REST, except 127.0.0.1 / ::1. Those literals are in the e2e stack's _APP_ALLOWED_INTERNAL_ADDRESSES, so they are fetched (404) rather than rejected as invalid URLs. Unit tests still cover them with the allowlist empty.

@abnegate
abnegate merged commit 6cb0260 into main Oct 8, 2026
52 checks passed
@abnegate
abnegate deleted the cursor/authz-input-validation-e2e-4968 branch October 8, 2026 04:47
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