Skip to content

test: preventative security E2E suite over the live route table - #14245

Merged
abnegate merged 12 commits into
mainfrom
cursor/preventative-security-e2e-8fae
Oct 8, 2026
Merged

abnegate merged 12 commits into
mainfrom
cursor/preventative-security-e2e-8fae

Conversation

@abnegate

@abnegate abnegate commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Adds a preventative security E2E suite: every live /v1 route is taken from the process router (Http::getRoutes() after the same bootstrap the specs task uses) and offered to a set of pluggable attack classes. A newly added endpoint is probed automatically. This is the dynamic counterpart to the Semgrep baseline in #14062, not another list of hand-written cases for known reports (that is #14064).

Coverage (routes × classes)

Source of truth: Catalog loads app/controllers/general.php + module HTTP init, then Http::getRoutes(). Aliases collapse to the primary path. GraphQL fan-out and mock-labeled routes are skipped; everything else under /v1 is in.

Green scan (791d774a8c / rewritten as daaf6b324c, 705 /v1 routes, ~27s of probes):

Class Routes probed Findings
guest-access 705 0
cross-tenant 542 0
idor 402 0
scope-least-privilege 530 0
console-role 1 + owner-only probes 0
header-spoof 542 + identity probes 1 WARNING (trusted-proxy topology)
ssrf-url 43 0
sensitive-fields 227 0

Attack classes (tests/e2e/Security/Attack/, auto-discovered):

Class What it sends Safe outcome
guest-access Project header only 401/403 unless the route scope intersects the guest role
cross-tenant Project A key (and session) on project B, only on non-guest routes 401/403
idor User B session + user A's path IDs 401/403/404, or 2xx that does not contain A's userId / email
scope-least-privilege API key that holds only locale.read plus built-in key scopes, only on non-guest routes 401/403 unless the route's declared scope is in that set
console-role Developer session on org scopes their role does not include (skips guest/account/projects.read); plus owner-only membership mutations 401/403
header-spoof Reserved x-appwrite-* identity headers (mixed case), X-Forwarded-For Must not authenticate as the spoofed user
ssrf-url Loopback / link-local / metadata URLs on URL-typed params 400/401/403/404. Timeouts and 2xx on fetch endpoints are findings. Stored-only URLs that accept a value are not (create does not connect).
sensitive-fields GET as a normal user secret / password / execution streams must be empty or absent

Adding a class is one file in Attack/.

Baseline

tests/e2e/Security/baseline.json is the allowlist (same spirit as .semgrep/baseline.json):

  • CI fails on any finding whose attack + method + path + probe key is not listed.
  • CI fails if a listed finding has an empty reason.
  • Route inventory is locked (705 METHOD /v1/... ids). CI fails on a live catalog route that is not listed until the inventory is updated.
  • Stale entries are printed and do not fail the job.

The baseline lists a forwarded-IP WARNING: compose/CI sits on loopback or RFC1918, so default _APP_TRUSTED_PROXIES reflects X-Forwarded-For.

False positives that were not allowlisted:

  • Presence upsert echoing a caller-chosen $id while userId stays the caller.
  • Account passwordUpdate — ISO datetime of last password change, documented on the Account model.
  • Organization project list/get — developers can list org projects in the console.

To accept a reviewed new endpoint (and refresh the route list):

docker compose exec appwrite test tests/e2e/Security --group=security

_APP_SECURITY_BASELINE=update docker compose exec appwrite test tests/e2e/Security --group=security

Review the baseline.json diff like code. How to add a route is documented in tests/e2e/Security/README.md.

CI

New job Tests / E2E / Security — one stack (default PostgreSQL, dedicated tables), sequential PHPUnit, 20-minute test budget (~27s of probes after world boot). Shared fixture world (one console organization, two projects, two users, least-privilege key, console developer). ParaTest is not used: multiplying that world per process costs more than the request loop saves.

Docs: tests/e2e/Security/README.md.

Unit tests for catalog filtering, baseline matching (including that a canary route is rejected once routes is locked), probe path filling, and attack discovery run in the existing unit job.

Test Plan

  • Pint on the new PHP files
  • Checks (PHPStan / Rector) green
  • First real scan: 705 routes, findings reviewed
  • Tests / E2E / Security green with reasoned baseline
  • Unit tests/unit/Security pass (unit job)
  • Route inventory locked at 705; unit canary POST /v1/security-inventory-canary is fresh
  • Merged main (includes fix(users): align session route scopes with their admin/server auth types #13994) and dropped the resolved baseline row; remaining allowlist is the forwarded-IP warning only
Open in Web Open in Cursor 

Enumerate /v1 routes from Http::getRoutes() and run pluggable attack
classes (guest access, cross-tenant, IDOR, key scopes, console roles,
header spoofing, SSRF URLs, sensitive fields). Known exceptions live
in a checked-in baseline; CI fails on new findings without a reason.

Co-authored-by: Jake Barnby <[email protected]>
@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.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/preventative-security-e2e-8fae (after).

Metric Before After Change
🚀 Requests/sec 173.27 172.13 ⚪ -0.7%
⏱️ Latency P50 97.48 ms 98.87 ms ⚪ +1.4%
⏱️ Latency P95 245.19 ms 244.46 ms ⚪ -0.3%
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 98.87 244.46 11,172 172.13 -0.73
Account 197.84 384.55 588 9.76 -10.82
TablesDB 94 178.83 6,076 97.36 -8.54
Storage 93.92 210.98 2,940 48.05 +12.22
Functions 139.07 296.91 1,568 26.27 -2.1

Top API waits (after)

API request Max wait (ms)
account.name.update 661.6
account.prefs.update 500.15
storage.buckets.create 489.04
tablesdb.rows.update 470.12
functions.variables.update 454.67

cursoragent and others added 4 commits October 8, 2026 03:26
Self-hosted allows a single console organization, so World::boot
was 403ing on the second POST /teams. Create the org once and
attach both isolation projects to it. Also clear PHPStan and
Rector nits that failed Checks.

Co-authored-by: Jake Barnby <[email protected]>
A guest-callable route succeeding with a foreign key or a
locale-only key is the public surface, not a bypass. Same for
console-role probes on account/home/console scopes that any
logged-in session already satisfies.

Co-authored-by: Jake Barnby <[email protected]>
The live suite covered 705 /v1 routes. Presence upsert echoing a
caller-chosen id is not an IDOR; passwordUpdate is a datetime;
developers can read org projects. Record remaining allowlisted
rows, including locale forwarded-IP reflection under default
trusted proxies.

Co-authored-by: Jake Barnby <[email protected]>
Shorten allowlist reasons and drop first-scan row notes from
the suite README so the checked-in files stay unremarkable.

Co-authored-by: Jake Barnby <[email protected]>
@cursor
cursor Bot force-pushed the cursor/preventative-security-e2e-8fae branch from d5b45e7 to 1845b76 Compare October 8, 2026 04:27
@abnegate
abnegate marked this pull request as ready for review October 8, 2026 04:36
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 3 medium

💬 Inline comments (3)

🧹 Nitpicks (2) — 🟢 2 low
  • 🟢 returnsSecretByDesign guard is unreachable (SensitiveFields.php:58) — SensitiveFields::applies() only reaches returnsSecretByDesign() when $route->method === 'GET' (tests/e2e/Security/Attack/SensitiveFields.php:30), but the exemption inside returnsSecretByDesign() requires $route->method !== 'GET' (tests/e2e/Security/Attack/SensitiveFields.php:63), so it can never return true.
  • 🟢 BaselineTest leaks temp files on failed assertions (BaselineTest.php:13) — tests/unit/Security/BaselineTest.php:13 and line 42 create a temp baseline file and remove it only as the final statement of each test (lines 38 and 54).

This PR introduces an automated attack-probe framework that enumerates the API catalog and runs SSRF, IDOR, guest-access, header-spoofing, scope, and sensitive-field probes against a live stack, recording accepted findings in a checked-in baseline. Supporting infrastructure covers route targeting, finding keys, and baseline persistence.

Files Change
tests/e2e/Security/Attack*, Probe.php, RouteTarget.php, World.php Probe classes, HTTP dispatch helper, and shared stack bootstrapping for guest/developer/console roles
tests/e2e/Security/Baseline.php, Finding.php, Catalog.php, baseline.json Baseline allowlist persistence, finding identity/keys, and route enumeration from the live router
tests/e2e/Security/SecurityProbeTest.php, tests/unit/Security/* PHPUnit entry point plus unit tests for attacks, probe helpers, baseline, and route targeting
.github/workflows/ci.yml, phpunit.xml New e2e_security workflow job and testsuite/group wiring for the suite

Risk is moderate: the suite itself is new test tooling, but baseline-update and param-substitution bugs could silently weaken or wipe the security allowlist.

Reviewed commit: 1845b76

@ghost

ghost commented Oct 8, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Adds a route-table-driven security E2E suite that probes live /v1 endpoints with auto-discovered attack classes and compares findings and route inventory against a reviewed baseline. The pull request also adds shared fixtures, CI and PHPUnit wiring, operating documentation, and unit tests for the catalog, probing, attack discovery, and baseline helpers.

Latest changes: The latest commits make a completed baseline update replace the findings list, preserving reasons only for findings still observed, and update the README and unit test to cover that behavior.

Verdict New comments Fixed Still open
💬 Commented 0 0 0
📂 Walkthrough · 9
File Change
.github/workflows/ci.yml, phpunit.xml Adds the dedicated security E2E CI job and registers the suite.
tests/e2e/Security/Attack.php, tests/e2e/Security/Attack/ Defines the attack contract and attack classes for route-level authorization, isolation, spoofing, SSRF, and sensitive-field probes.
tests/e2e/Security/Attacks.php, Baseline.php, Catalog.php, Finding.php, Probe.php, RouteTarget.php, SecurityProbeTest.php, World.php Implements route discovery, shared fixtures, probe requests, attack execution, and baseline checking and updates.
tests/e2e/Security/README.md, baseline.json Documents the security suite and baseline workflow, and stores the reviewed route inventory and findings.
tests/unit/Security/AttacksTest.php, BaselineTest.php, ProbeTest.php, RouteTargetTest.php Tests attack discovery, baseline partitioning and updates, probe parameter handling, and route-target behavior.
.github/workflows/ci.yml Adds the dedicated security E2E CI job.
phpunit.xml Registers the security E2E suite.
tests/e2e/Security/README.md Documents suite coverage, baseline updates, and CI behavior.
tests/e2e/Security/baseline.json Stores reviewed findings and the locked live route inventory, now including the remaining 14 route IDs.

Reviewed the commits since ef85a21 · 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

Comment thread tests/e2e/Security/Probe.php Resolved
Comment thread tests/e2e/Security/baseline.json Resolved

@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 B · See the inline comments. Summary

Comment thread tests/e2e/Security/baseline.json Resolved

@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 · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot 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.

The PR adds a preventative security e2e probe suite (tests/e2e/Security/*) with a baseline allowlist, unit tests, and a dedicated e2e_security CI job.

Key findings

Comment thread tests/e2e/Security/Attack/SsrfUrl.php Resolved
Comment thread tests/e2e/Security/Baseline.php Resolved
cursoragent and others added 4 commits October 8, 2026 04:44
Merge dummy required fields under URL overrides so multi-param
routes reach the handler instead of a 400. Refuse a baseline rewrite
unless the world booted and every attack class ran, keep rows the
run did not emit, and copy the document to the cache volume when
tests/ is not bind-mounted.
@abnegate

abnegate commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Addressed the open Hansi + Tenki findings in ef85a21:

  • SSRF probes merge dummy required fields under the URL override (Probe::params()), so multi-param routes are actually exercised
  • Baseline update refuses a partial/--filter run and keeps rows the run did not emit
  • Update also writes /storage/cache/security-baseline.json when tests/ is not bind-mounted

@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 B · See the inline comments. Summary

Comment thread tests/e2e/Security/Baseline.php Resolved
@ghost

ghost commented Oct 8, 2026

Copy link
Copy Markdown

Already reviewed ef85a21. No new commits since then, so I didn't post another review.

Keeping omitted rows after a full Attacks::all() run would allowlist
a later recurrence of a fixed probe. Partial runs still refuse to
write; a completed update now replaces the findings list and only
preserves reasons for keys that still fire.
@abnegate

abnegate commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

Dropped stale baseline rows on a completed update in 919e8c7. Partial runs still refuse to write; a full run no longer keep-alives resolved findings.

@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 commented Oct 8, 2026

Copy link
Copy Markdown

Already reviewed 919e8c7. No new commits since then, so I didn't post another review.

@abnegate
abnegate merged commit e68e954 into main Oct 8, 2026
104 checks passed
@abnegate
abnegate deleted the cursor/preventative-security-e2e-8fae branch October 8, 2026 06:55
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