Skip to content

Headers set validation - #1108

Open
xeioex wants to merge 2 commits into
nginx:masterfrom
xeioex:headers-set-validation
Open

Headers set validation#1108
xeioex wants to merge 2 commits into
nginx:masterfrom
xeioex:headers-set-validation

Conversation

@xeioex

@xeioex xeioex commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This is the extended fix for issue reported in #1107

VadimZhestikov
VadimZhestikov previously approved these changes Aug 13, 2026

@VadimZhestikov VadimZhestikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

A small follow-up simplification you might fold in, if you like it:
VadimZhestikov@a554b9fc

Two things on top of this PR, both no-op refactors:

  • The per-engine ngx_js_headers_update() / ngx_qjs_headers_update()
    wrappers only forward to ngx_js_headers_modify() and translate the
    result code. append() and set() can call ngx_js_headers_modify()
    and *_headers_result() directly, so the wrappers are dropped.
  • ngx_js_headers_modify() took value/vlen by pointer, which reads
    like an output parameter, but no caller uses the trimmed value back
    (it's stored inside the function). Passing them by value removes the
    indirection.

No functional change; the fetch tests pass on both njs and QuickJS. The
commit sits right on top of the current PR tip (b2ed5cd), so it applies
clean. Feel free to squash it in or ignore.

@github-project-automation github-project-automation Bot moved this from New to In Review in NGINX OSS Unified Workspace Aug 13, 2026
xeioex added 2 commits August 12, 2026 19:13
Previously, Headers.set() validated its arguments only when the header
did not already exist.  Existing values were overwritten without
trimming or validating the new value and without checking the immutable
guard.  It also detached duplicate values only from the first header's
chain, while leaving the corresponding list entries active.  The stale
values could reappear when the Headers object was copied or serialized.

The fix is to move append(), set(), and delete() validation and list
updates into engine-independent helpers, deactivate every duplicate on
replacement, reject empty names, and enforce immutable guards
consistently.  Content-Type presence is now derived from the header list
instead of a separate cached pointer.

Reported by vladimirelitokarev@gmail.com.
Previously, Headers.set() converted the header name with
JS_ToCStringLen().  When a new header was added, the list retained that
pointer after it was released with JS_FreeCString(), leaving the header
with a dangling name.

The fix is to copy the name into the request pool only when set() creates
a new list entry.  Replacing an existing entry requires no additional
allocation, and the temporary QuickJS string can always be released
after the mutation.
@xeioex

xeioex commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Applied.

@xeioex
xeioex requested a review from VadimZhestikov August 13, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants