fix(http): reject CR/LF/NUL in set_headers values#28
Draft
andypost wants to merge 1 commit into
Draft
Conversation
The set_headers action lets operators add response headers whose values
are templated strings, e.g.
"response_headers": { "X-Echo": "$uri" }
A template can dereference request-controlled state (URI, query
arguments, headers). If the request URI contains "%0D%0A", the
template substitution produces a value with embedded CRLF, and the
wire serialiser writes "X-Echo: prefix\r\nInjected: x\r\n" — standard
HTTP response splitting.
Reject any computed value that contains CR, LF, or NUL. An unsafe
value is dropped (same semantics as a NULL template result) and an
INFO line names the header so an operator can diagnose a misconfigured
template without exposing the offending request payload at higher log
levels.
Static config values are operator-controlled and conventionally
trusted, but the check is two compares per byte and applies uniformly
to both code paths.
Failing the request would help an attacker probe for the protection;
silently dropping the header keeps the response well-formed.
There was a problem hiding this comment.
Code Review
This pull request introduces a safety check nxt_http_header_value_is_safe to prevent HTTP response-splitting vulnerabilities. It scans header values for carriage return (CR), line feed (LF), or null (NUL) characters, and drops any unsafe values while logging an info message. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
set_headersaction lets operators add response headers whosevalues are templated strings, e.g.
{ "response_headers": { "X-Echo": "$uri" } }A template can dereference request-controlled state (URI, query args,
request headers). When the request URI contains
%0D%0A, thetemplate substitution produces a value with embedded CRLF, and the
wire serialiser writes:
— standard HTTP response splitting.
This PR rejects any computed value that contains CR, LF, or NUL. An
unsafe value is dropped (matching the existing NULL-template-result
semantics: the header is omitted from the response). An
INFOlinenames the offending header so an operator can diagnose a misconfigured
template without leaking the request payload at higher log levels.
Static config values are operator-controlled and conventionally
trusted, but the check is two compares per byte and applies uniformly
to both the static and templated paths.
Failing the request was considered and rejected: a 500 response would
help an attacker probe for the protection. Dropping the header keeps
the response well-formed.
Files
src/nxt_http_set_headers.c— addsnxt_http_header_value_is_safehelper and one call site after value evaluation.
Tests
Manual reproduction:
{ "listeners": { "*:8080": { "pass": "routes" } }, "routes": [{ "action": { "return": 200, "response_headers": { "X-Echo": "$uri" } } }] }Independence
Single file, single concern, no dependency on other in-flight PRs.
Generated by Claude Code