Skip to content

fix(functions): reject control characters in execution header values - #15143

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/execution-header-crlf
Oct 31, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/execution-header-crlf

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Execution header values are forwarded to the runtime as request headers, so they should be single-line.

// Headers validator
if (\preg_match('/[\x00-\x08\x0A-\x1F\x7F]/', (string) $val) === 1) {
    return false; // tab still allowed
}

Executor::createExecution() also drops any header whose name or value contains CR, LF or NUL before forwarding.

Tests: new cases in tests/unit/Functions/Validator/HeadersTest.php (fail without the validator change).

Related: appwrite-labs/cloud#6673

Header values are forwarded as request headers to the runtime, so they must be single-line. The executor client also drops any header that would span lines.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 2 nitpicks below.

🧹 Nitpicks (2) — 🟢 2 low
  • 🟢 Avoid preg_match in header validator (Headers.php:64) — The new control-character check uses preg_match (src/Appwrite/Functions/Validator/Headers.php:64), and the new executor filter does the same (src/Executor/Executor.php:143).
  • 🟢 Executor filter skips CRLF check for non-scalar values (Executor.php:143) — The new defense-in-depth filter in src/Executor/Executor.php:141-145 concatenates $key with the value only when is_scalar($value), so an array or object value bypasses the line-break check entirely and is forwarded to the runtime request.

This PR hardens function execution against header injection: user- or config-supplied headers are validated for control characters before reaching runtimes, with a second denylist filter in the executor for defense in depth, plus unit tests for the new validator.

Files Change
src/Appwrite/Functions/Validator/Headers.php, tests/unit/Functions/Validator/HeadersTest.php Adds a Headers validator rejecting NUL, line breaks, and other control characters in header values, with unit coverage.
src/Executor/Executor.php Filters runtime request headers against \r/`
/\x00and thex-appwrite` prefix before forwarding them to the runtime.

Reviewed commit: e2c8523

@ghost

ghost commented Oct 31, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental replacements preserve the previous control-character checks, including NUL handling and the allowed tab case.

Function execution header values are restricted to single-line content, with horizontal tabs still allowed, and unsafe headers are filtered before forwarding to the runtime. Unit tests cover rejected control characters and the permitted tab case.

Latest changes: The newest commits replace the regex checks with strpbrk() checks and define the validator's disallowed control characters in a shared constant.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
src/Appwrite/Functions/Validator/Headers.php Rejects control characters in header values while allowing tabs, and updates the validator description.
src/Executor/Executor.php Filters headers containing CR, LF, or NUL before forwarding them to the runtime.
tests/unit/Functions/Validator/HeadersTest.php Adds coverage for rejected control characters and allowed tabs.

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

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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.

Follows the repo rule against new preg_* calls.
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/execution-header-crlf (after).

Metric Before After Change
🚀 Requests/sec 210.76 219.2 ⚪ +4%
⏱️ Latency P50 81.12 ms 78.86 ms ⚪ -2.8%
⏱️ Latency P95 192.5 ms 182.39 ms 🟢 -5.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 78.86 182.39 13,680 219.2 -10.11
Account 154.99 300.65 720 12.23 +11.29
TablesDB 77.24 144.2 7,440 121.96 -9.92
Storage 70.78 162.26 3,600 60.79 -10.28
Functions 112.33 218.76 1,920 33.16 +8.72

Top API waits (after)

API request Max wait (ms)
account.prefs.update 455.35
storage.buckets.create 396.96
functions.variables.update 393.84
account.name.update 375.95
functions.create 339.09

@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

@ChiragAgg5k
ChiragAgg5k merged commit 30f9009 into main Oct 31, 2026
70 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/execution-header-crlf branch October 31, 2026 15:12
@ChiragAgg5k ChiragAgg5k self-assigned this Nov 2, 2026
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