Skip to content

fix(psr7): reject CR, LF and NUL in header values - #14806

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/header-value-control-characters
Oct 22, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/header-value-control-characters

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Utopia\Psr7\Message::withHeader() and withAddedHeader() now throw InvalidArgumentException for header values containing CR, LF or NUL, as PSR-7 requires.

The webhooks worker sends the webhook name in X-Appwrite-Webhook-Name. Names are free text, so the worker strips control characters from the name before using it as a header value, keeping deliveries for such webhooks working.

Test plan

  • bin/monorepo check psr7 and bin/monorepo test psr7: new data-provider tests cover CR, LF, CRLF, NUL and a list containing a bad value for both methods; tabs and non-ASCII stay accepted
  • PHPStan on the worker and the e2e test
  • E2E WebhooksCustomServerTest::testWebhookNameWithLineBreaksIsDelivered: a webhook named with CR/LF/tab is delivered once, with those characters removed from the header

Related: appwrite-labs/cloud#6674

PSR-7 requires implementations to refuse header values that would break message framing. Webhook names are free text and end up in the X-Appwrite-Webhook-Name header, so the worker strips control characters from the name rather than letting the delivery fail.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens the webhook delivery path against header injection by stripping control characters from the webhook name before it is sent as a header, and tightens the PSR-7 message layer's header value validation.

Files Change
packages/psr7/src/Message.php Adds header value validation rejecting CR, LF and NUL bytes on both withHeader and withAddedHeader paths.
packages/psr7/tests/MessageTest.php Unit tests covering header values with embedded control characters and multibyte text.
packages/psr7/CHANGELOG.md Notes the header validation change.
src/Appwrite/Platform/Workers/Webhooks.php Strips control characters from the webhook name before building the delivery header.
tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php e2e coverage asserting webhooks with line breaks and tabs in the name are accepted and delivered sanitized.

One low-severity residual was noted but kept below the reporting threshold: normalizeHeaderValue still accepts C0 control bytes other than CR/LF/NUL and DEL, which the PSR-7 field-content grammar technically forbids.

Reviewed commit: 1ee58d3

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed validation and webhook sanitization paths behave consistently with the stated contract, and both have regression coverage.

The PSR-7 message implementation now rejects header values containing CR, LF, or NUL, with unit coverage for both header methods and accepted tab/Unicode values. Webhook delivery removes control characters from webhook names before setting the name header, with an end-to-end regression test.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
packages/psr7/CHANGELOG.md Documents the header-value validation fix.
packages/psr7/src/Message.php Rejects CR, LF, and NUL in normalized header values.
packages/psr7/tests/MessageTest.php Covers invalid header values for both methods and accepted tabs/Unicode.
src/Appwrite/Platform/Workers/Webhooks.php Strips control characters from webhook names before sending the header.
tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php Checks delivery of a webhook whose name contains control characters.

Reviewed 1ee58d3 · 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

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/header-value-control-characters (after).

Metric Before After Change
🚀 Requests/sec 194.92 207.23 🟢 +6.3%
⏱️ Latency P50 86.39 ms 83.24 ms ⚪ -3.7%
⏱️ Latency P95 209.54 ms 197.76 ms 🟢 -5.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 83.24 197.76 12,825 207.23 -11.77
Account 151.37 299.26 675 11.19 +12.06
TablesDB 78.74 146.78 6,975 114.99 -9.36
Storage 79.98 191.43 3,375 57.6 -23.06
Functions 120.84 242.98 1,800 31.36 +4.81

Top API waits (after)

API request Max wait (ms)
account.prefs.update 437
functions.variables.update 406.03
account.name.update 399.73
functions.create 397.01
storage.buckets.create 395.77

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

@ChiragAgg5k
ChiragAgg5k merged commit 594b29c into main Oct 22, 2026
86 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/header-value-control-characters branch October 22, 2026 18:09
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…rol-characters

fix(psr7): reject CR, LF and NUL in header values

(cherry picked from commit 594b29c)
sarbojitrana pushed a commit to sarbojitrana/appwrite that referenced this pull request 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.

1 participant