]> git.kaiwu.me - njs.git/commit
HTTP: fix missing validation of r.headersOut values
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 13 Aug 2026 21:48:02 +0000 (14:48 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 14 Aug 2026 19:56:32 +0000 (12:56 -0700)
commitc4df63a33610bc6112e4c723d38d5cd380a924c6
treed10f8336dd99bfdcf268154f2c34cdec48660bec
parent85e2ff5b770ce37e4cd96ae1366a564d62a76e45
HTTP: fix missing validation of r.headersOut values

Previously, a property name used to store a response header was copied
into the header list as is, without checking it against the token
grammar, so a name containing control characters produced a malformed
response.

The name is now validated in the two places where it is resolved for a
store: ngx_http_js_ext_header_out() and its QuickJS counterpart, which
also covers Object.defineProperty().  An invalid name is rejected with a
TypeError.

Previously, values assigned to r.headersOut were stored as is, without
checking them for control characters, while ngx_js_check_header_value()
was applied only on the Fetch Headers path.

The conversion of a JS value into a header value is now done by
ngx_js_header_value() and ngx_qjs_header_value(), which validate the
result.  All the r.headersOut store paths, including the special headers
and Content-Type, use them and reject an invalid value with a TypeError.

Reported by vladimirelitokarev@gmail.com.
nginx/ngx_http_js_module.c
nginx/ngx_js.c
nginx/ngx_js.h
nginx/t/js_headers.t