Skip to content

fix(functions): validate reserved x-appwrite execution headers case-insensitively - #14185

Merged
abnegate merged 12 commits into
mainfrom
cursor/fix-function-header-spoof-4078
Oct 22, 2026
Merged

abnegate merged 12 commits into
mainfrom
cursor/fix-function-header-spoof-4078

Conversation

@abnegate

@abnegate abnegate commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

The function Headers validator now treats the reserved x-appwrite- prefix as case-insensitive. Any caller header whose lowercased name starts with x-appwrite- is stripped before Appwrite injects its own values on every execution path that forwards caller-controlled headers:

  • POST /v1/functions/:functionId/executions (sync, async, scheduled)
  • Functions worker (async HTTP / schedule / leftover queued headers)
  • Function and site custom-domain router
  • GraphQL executions use the same Create action, so they pick up the validator + strip.

The reserved names include x-appwrite-user-id, x-appwrite-trigger, x-appwrite-event, and x-appwrite-key.

The previous check used a case-sensitive str_starts_with($key, 'x-appwrite-'). PHP array keys are case-sensitive, so X-Appwrite-User-Id passed validation. The execution path then set Appwrite's values under lowercase keys, leaving both the caller's mixed-case key and the injected key in the map sent to the executor. Runtimes treat HTTP headers as case-insensitive and expose the caller's value.

On current main, a rejected headers param already returns HTTP 400 (general_argument_invalid). That 400-class mapping is unchanged.

Test Plan

  • Unit tests in tests/unit/Functions/Validator/HeadersTest.php cover mixed case, ALL CAPS, and stripReserved(). These fail if the prefix check is case-sensitive again.
  • E2E in FunctionsCustomClientTest: guest POST with mixed-case and ALL CAPS reserved headers must return 400 general_argument_invalid.
  • E2E in FunctionsCustomServerTest::testCreateExecution FAILURE block: same mixed-case / ALL CAPS reserved headers return 400.
  • Pint passed on changed files.
  • PHPStan level 4 passed on the Headers validator and its unit test. Full-project composer analyze was not run here (no project vendor tree in this environment).
  • vendor/bin/phpunit tests/unit/Functions/Validator/HeadersTest.php passed (31 assertions).

Related PRs and Issues

  • N/A

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?
Open in Web Open in Cursor 

…poofing

Reserved function headers were only blocked when the caller used a
lowercase x-appwrite- prefix, so mixed-case or uppercase names in the
execution headers param reached the runtime alongside injected values.

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

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/fix-function-header-spoof-4078 (after).

Metric Before After Change
🚀 Requests/sec 192.84 198.84 ⚪ +3.1%
⏱️ Latency P50 88.19 ms 88.33 ms ⚪ +0.2%
⏱️ Latency P95 207.93 ms 202 ms ⚪ -2.9%
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 88.33 202 12,483 198.84 -5.94
Account 162.55 290.27 657 11.16 -50.03
TablesDB 87.28 166.42 6,789 110.9 +0.46
Storage 77.86 187.03 3,285 54.91 -10.18
Functions 119.93 224.06 1,752 30.06 -7.4

Top API waits (after)

API request Max wait (ms)
account.prefs.update 435.65
account.name.update 406.29
functions.delete 353.45
tablesdb.rows.create 349.13
storage.buckets.create 344.68

@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.

@cursor cursor Bot changed the title fix(functions): reject case-insensitive x-appwrite execution header spoofing fix(functions): validate reserved x-appwrite execution headers case-insensitively Oct 22, 2026
Co-authored-by: Jake Barnby <[email protected]>
@abnegate
abnegate marked this pull request as ready for review October 22, 2026 05:23
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)

  • 🟠 Worker strip drops x-appwrite-client-ip and geo from async executions — Functions.php:570

Adds a shared Headers validator that rejects caller-supplied reserved headers at the executions API and strips them before function execution, closing an impersonation vector. The change spans the API path, the proxy/execute route, the functions worker, and adds unit plus e2e coverage for spoofed headers.

Files Change
src/Appwrite/Functions/Validator/Headers.php New reserved-header check (isReserved) and stripReserved() helper shared by all execution paths
src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php Rejects requests carrying spoofed reserved headers with 400 before enqueueing
app/controllers/general.php Applies silent stripping on the proxy/execute route instead of rejecting
src/Appwrite/Platform/Workers/Functions.php Strips reserved headers from message payloads before async/scheduled executions run
tests/unit/Functions/Validator/HeadersTest.php, tests/e2e/Services/Functions/* Unit matrix of reserved-header casings and e2e assertions that spoofed headers are rejected

Reviewed commit: 84bf558

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The validator and sanitization cover the API, queued-worker, and custom-domain execution paths, with regression coverage for the changed behavior.

This change makes the reserved x-appwrite- prefix case-insensitive and adds a shared sanitizer for execution headers on API, worker, and custom-domain paths. It adds regression coverage for mixed-case reserved headers and preservation of the trusted client IP on queued executions.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 8
File Change
app/controllers/general.php Sanitizes incoming headers before injecting trusted values for custom-domain execution.
src/Appwrite/Functions/Validator/Headers.php Adds case-insensitive reserved-prefix validation and header stripping.
src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php Strips reserved caller headers before injecting execution metadata.
src/Appwrite/Platform/Workers/Functions.php Strips reserved queued headers while retaining the trusted client-IP header.
tests/e2e/Services/Functions/FunctionsCustomClientTest.php Covers mixed-case rejection and async client-IP forwarding.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Covers mixed-case rejection and reserved-header spoofing on function domains.
tests/resources/functions/basic/index.js Logs the client-IP header for execution assertions.
tests/unit/Functions/Validator/HeadersTest.php Covers case-insensitive validation and reserved-header stripping.

Reviewed 8744b7c · 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

@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

@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.

This PR rejects spoofed reserved x-appwrite-* headers on execution creation and silently strips them on the proxy route and worker paths via a new Headers::stripReserved validator.

Key findings

  • 🟠 Worker strip drops x-appwrite-client-ip and geo from async executions — Functions.php:570

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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 · 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 A · 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

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

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

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

Async execution reads do not include a response body, so the finished run is loaded with the project key and the IP is taken from the function logs.

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

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

Rector's PHPUnit quality set rewrites assertNotFalse(strpos()) to
assertStringContainsString().

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

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread app/controllers/general.php Resolved
Send mixed-case reserved headers through the domain path and check
the function receives Appwrite's values, not the caller-supplied ones.

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

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@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

@abnegate
abnegate merged commit 003584a into main Oct 22, 2026
71 checks passed
@abnegate
abnegate deleted the cursor/fix-function-header-spoof-4078 branch October 22, 2026 06:52
ChiragAgg5k pushed a commit that referenced this pull request Oct 24, 2026
ChiragAgg5k pushed a commit that referenced this pull request Oct 24, 2026
ChiragAgg5k pushed a commit that referenced this pull request Oct 24, 2026
ChiragAgg5k pushed a commit that referenced this pull request Oct 24, 2026
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…eader-spoof-4078

fix(functions): validate reserved x-appwrite execution headers case-insensitively

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