Repository navigation
fix(deploy): refuse a location that shadows the nginx header set - #1111
Merged
Merged
Conversation
The nginx security-header gate recorded `add_header` lines only when the parser depth was exactly 1, so a header inside a `location` was invisible to it. nginx does not merge header sets: a location that declares any `add_header` of its own stops inheriting the server-level set, so a sample that added one header under `location /` passed the gate while serving none of the four headers on that path, including the nginx-generated 4xx/5xx `always` exists for. The rule now reads location bodies of any depth: a location that declares a header anywhere must repeat all four with `always` at its own level, and the check fails naming the location's opening line otherwise. The deploy-check contract gains both halves - a location with a `Cache-Control` is refused and named, and a location that repeats the four is accepted - so the new rule cannot pass by refusing every location. The shipped sample declares no location-level header and keeps passing unchanged.
HugoXK-bot
approved these changes
Nov 19, 2026
HugoXK-bot
left a comment
Collaborator
There was a problem hiding this comment.
Verdict: PASS at 698b5c8
Written-by: HugoXK-bot
Author: Fledge Platform Verdict
- The checker reads a token stream now, so layout stops deciding the verdict:
{,}and;split wherever they sit, quoted values and#comments are respected, and the\ris stripped before a line is read (scripts/check-nginx-config.sh:142,:156-158); a block is aserverorlocationby its header text (:97-108). - The rule still refuses the shadowing and not the shape: a
locationthat declares any directadd_headermust repeat all four withalwaysat its own level, and the failure names the location line plus each missing header (:119-126); the server-level rule is untouched. - I drove all five shapes through the gate with a stub
nginxmyself: shipped sample 0; one-liner withCache-Controlrefused at line 3 naming all four; the same one-liner repeating all four accepted;{on the next line refused at line 4; CRLF copy accepted; a quoted"no-store; max-age=0 }"value still parsed, and dropping onealwayswas refused. - The contract grew 8 → 11 checks (one-liner refused and named, one-liner repeat accepted, brace-on-the-next-line refused) at
scripts/check-deploy-samples.sh:157-209, andtest/securityHeaders.test.tsis 12/12 at this tip. - Tip integrity: head
698b5c85carries tree1bb58258…(the tree the body names) with parentd5b5559d, anddeploy/nginx.conf.exampleis untouched, so the sample a self-hoster copies did not move under this rule.
Ran:
npx tsx --test test/securityHeaders.test.ts— 12/12 passnpm run typecheck— cleanbash scripts/check-nginx-config.sh --sample …with a stubnginxover the five shapes above — exit 0/1/0/1/0 as expected
Not run: realnginx -t(no nginx binary on this box;deploy-checkinstalls it in CI and was skipped at this tip because nodeploy/file changed), andnpm run mock:check(nopublic/orsrc/views/change, so no UI face).
Owner
Author
|
Security: CHANGES at 698b5c8
|
The first rule tracked a `location` only when its line carried `{` and read an
`add_header` only when the directive began a line, so a legal one-liner
`location = /health { add_header Cache-Control "no-store" always; }` shadowed
the server set and passed the gate, and a location whose `{` sat on the next
line was invisible. A CRLF copy failed with `has no add_header` although every
header was present, because the `\r` sat between the value and `always`.
The check now reads the rendered sample as a token stream: `{`, `}` and `;`
close a directive wherever they sit, quotes and comments are respected, and
`\r` is normalised away. A block is a `server` or a `location` by its header
text, so brace and directive placement no longer decide what is seen. The
server rule is unchanged; a location that declares any direct `add_header`
still has to repeat all four with `always`.
The contract gains three copies: the one-liner with one header (refused, named),
the one-liner repeating all four (accepted), and the brace-on-the-next-line
location (refused, named). Tests cover the three shapes plus a CRLF copy, and
`docs/deploy.md` states the shape independence.
Push-disclosure: rebuilt from tree 1bb5825 and pushed by Fledge Platform Lead (Git Data path) because the Dev-1 lane has no write channel after the 2026-11-19 mirror incident; the tree is the author's, the push is the Lead's.
…#1097) The static half of the deploy gate reads the shipped nginx sample for the four console security headers. Three inputs walked past it, and the first two are legal nginx that serves fewer headers than the server set. - scripts/check-nginx-config.sh: a brace opens or closes a block only at a token boundary, so `location ~ ^/v}v[0-9]+` stays one location instead of one that closed early, and a location that declares one header there is refused by its own opening line. A `}` that closes nothing is now an error rather than a dropped character. Every block that declares any `add_header` is judged on the set it serves, not only the innermost location, so an `if` (or `limit_except`) inside a server or a location is a header-owning level of its own. A sample with no `server` block is refused with "no server block to check" instead of passing with nothing asserted. - scripts/check-deploy-samples.sh: sixteen checks, adding the two negative shapes, an empty and a comment-only sample, and a control for each shape (a valid `^/v[0-9]{1,3}$` location and an `if` that repeat the whole set). - test/securityHeaders.test.ts: six red cases and their controls, and the contract's new summary lines. - docs/deploy.md: the shapes, the token boundary and the `include` gap. `nginx -t` stays the parser of record; the static half no longer passes an input it cannot judge. Fixes #1097 Push-disclosure: tree authored by Fledge Platform Dev-1, rebuilt and pushed by Fledge Platform Lead (Dev-1 lane has no write channel). Tree: b63df3f
Owner
Author
|
Security: PASS at 0083b77
|
HugoXK-bot
approved these changes
Nov 19, 2026
HugoXK-bot
left a comment
Collaborator
There was a problem hiding this comment.
Verdict: PASS at 0083b77
Written-by: HugoXK-bot
Replaces: 698b5c8
scripts/check-nginx-config.sh:191-208mirrors nginx 1.18's lexer:{opens a block everywhere except the${var}form, and}stays literal inside a token (src/core/ngx_conf_file.c:723,:741-745), so the audit's^/v}v[0-9]+one-header location is refused (test/securityHeaders.test.ts:278) while the quoted-quantifier control is accepted (:320).- The
if/limit_exceptlevel is judged on the set it serves (:339, control:362); an empty or comment-only sample is refused withno server block to check(scripts/check-nginx-config.sh:225, test:394). - The invalid controls are gone: the contract pins the quoted quantifier and a real
$request_methodvariable; 17/17 with the stub, 19/19 plus 7/7 at the tip, 26/26 after merging95016f39into it. Security:is the audit seat's line and it already names this sha; the698b5c85line is not reused here.
Ran: npx tsx --test test/securityHeaders.test.ts test/nginxCheck.test.ts
Ran: git merge --no-edit main (95016f3)
Not run: realnginx -t— no nginx binary here anddocker.iois unreachable (image pull timed out), so the tokenizer is checked against nginx 1.18 source instead; CI unpickable at this sha (queued, not red).
…#1097) The static half of the deploy gate reads the shipped nginx sample for the four console security headers. Three inputs walked past it, and the first two are legal nginx that serves fewer headers than the server set. - scripts/check-nginx-config.sh: a `}` opens or closes a block only at a token boundary, so `location ~ ^/v}v[0-9]+` stays one location instead of one that closed early, and a location that declares one header there is refused by its own opening line. A `}` that closes nothing is now an error rather than a dropped character. Every block that declares any `add_header` is judged on the set it serves, not only the innermost location, so an `if` (or `limit_except`) inside a server or a location is a header-owning level of its own. A sample with no `server` block is refused with "no server block to check" instead of passing with nothing asserted. - scripts/check-nginx-config.sh, second audit pass on a box with a real nginx: a `{` is a block opener wherever nginx sees it outside a quoted string, even mid-token — nginx 1.18 rejects the unquoted quantifier `^/v[0-9]{1,3}$` with `unknown directive "1,3}$"` — so the previous control was an invalid sample and is replaced by a `}`-in-token control plus a quoted-quantifier control. The `${var}` form stays in the token. The contract's `if` shapes now use a real nginx variable instead of `$always`. - scripts/check-deploy-samples.sh: seventeen checks, adding the two negative shapes, the quoted-quantifier control, an empty and a comment-only sample, and a control for each shape. - test/securityHeaders.test.ts: eight new cases in the same table — five that are red on the published tip and three controls that stay green on both — and the contract's new summary lines. - docs/deploy.md: the shapes, the token boundaries, the quoted quantifier and the `include` gap. `nginx -t` stays the parser of record; the static half no longer passes an input it cannot judge. Measured with nginx/1.18.0 on this box: the shipped sample parses, the contract's seventeen checks pass, and the unquoted quantifier is rejected by nginx itself. Fixes #1097
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.
Written-by: HugoXK
Author: Fledge Platform Dev-1
Push-disclosure: the tree described here is authored by Fledge Platform Dev-1 and pushed by Fledge Platform Lead as a child of
2ab673037522f274732715db4b9bc8f7cbb672f8(the published tip of the previous slice) through the Git Data path; the Dev-1 lane has no write channel. Tree:944efbde2e6166878c73ca0412c0e16e7b335722.Fixes #1097
Why this tip exists
The audit's
Security: CHANGES at 698b5c85980b9d443474927ce047b3fd17362251(comment 7013185425) found two false passes the shape fix still allowed, and Test found a third input that passed with nothing asserted at all. All three are legal nginx or a missing subject, and the first two serve fewer headers than the server set — the exact class this card exists to close.Then, with a real
nginx/1.18.0on this box, the previous tree (b63df3f, published as2ab6730) failed its own contract: its control copied an unquoted regex quantifier^/v[0-9]{1,3}$, and nginx rejects that shape withunknown directive "1,3}$". A{is not kept inside a token — nginx opens a block there even mid-word; only a}is literal inside a token. The contract therefore goes red the moment the real-parse half is present, and the previous docs sentence that called that control a valid location was wrong. This tip replaces the control with shapes nginx accepts and pins both tokenizer rules.What changed
}inside a token.scripts/check-nginx-config.shclosed a block on every}, but nginx keeps a}inside a token:location ~ ^/v}v[0-9]+ { add_header Cache-Control "no-store" always; }is one location at runtime, and it serves onlyCache-Control. The reader now breaks on a}only at a token boundary (bufempty or ending in whitespace), so the regex stays in the header text and the location is judged on the header it declares. A}arriving at a boundary with no block open is an error (unexpected close brace at line N) rather than a dropped character.{is a block opener. nginx opens a block at every{outside a quoted string, even mid-token; the only exception is the${var}form, where the brace directly after$stays in the token. A{with nothing before it opens nothing and is refused (unexpected open brace at line N). This is what makes the previous control invalid: an unquoted^/v[0-9]{1,3}$is not nginx, and the accepted shape is the quoted"^/v[0-9]{1,3}$". Both the}-in-token and the quoted-quantifier controls are in the contract.ifinside a location. The header used to be recorded against the innermost block only, so a legallocation / { if ($request_method = POST) { add_header Cache-Control "no-store" always; } }left the location's own count at 0 and passed, although the matched responses serve onlyCache-Control. Every block that declares anyadd_headeris now judged on the set it serves — theif(orlimit_except) is a header-owning level named by its own opening line, accepted once it repeats the four.--sampleexited 0 "parsed": the awk stage had nothing to assert. It is now refused withno server block to check — a sample that has none cannot carry the four headers. The contract'sifcopies also use a real nginx variable ($request_method = POST);$alwaysis an unknown variable that only a stub accepts.scripts/check-deploy-samples.shgrows from eleven checks to seventeen: the two negative shapes, a quoted-quantifier control, an empty and a comment-only sample, plus a control for each shape (the}-in-token location and theifrepeating the whole set) so the rule cannot pass by refusing every brace or every inner block.test/securityHeaders.test.tscarries the new red cases and their controls in the same table.docs/deploy.mdstates the shapes, the token boundaries, the quoted quantifier and theincludegap.Where this differs from the audit's note
The note asks that a
}arriving with a non-empty token be refused as nginx's "unexpected}". nginx keeps a}inside a token —location ~ ^/v}v[0-9]+parses on nginx 1.18 andlocation ~ ^/v}v[0-9]+$with the whole header set must stay accepted — so refusing every in-token}would refuse a valid configuration, including the contract's own control. The rule instead reads the brace as nginx reads it (literal inside the token) and still refuses the audit's sample on its real defect, one header named and three missing. A}at a boundary with no block open is refused (unexpected close brace). If the audit wants the valid shape refused as well, it is a one-line change to the boundary test, but it would be a refusal of a correct configuration.Red half, at the published tip
2ab6730With the script from that tip and the new tests,
npx tsx --test test/securityHeaders.test.tsfails five: the brace-in-token location (12), theif-level header (15), the stray}(17), the empty/comment-only sample (18), and the contract test (19) because the contract now drives shapes the old script accepted. The controls (}-in-token repeating the set, quoted quantifier,ifrepeating the set) and the shipped sample stay green on both tips, which keeps the refusals about the shadowing and not the shape.Separately, the published tree's own contract is red with real nginx:
bash scripts/check-deploy-samples.shatb63df3fexits 1 at its quantifier control withunknown directive "1,3}$". That is the defect this tip removes.Green half, on tree
944efbdnpm run check→ 2997 tests, 0 fail, twice on this tree; lint at the baseline, typecheck and build clean (dependencies from the existingnpm ciinstall; no manifest change).npx tsx --test test/securityHeaders.test.ts→ 19/19.bash scripts/check-deploy-samples.shwith realnginx/1.18.0→ exit 0, seventeen checks.node scripts/risk-gate.mjs --base 066a9cc8…→risk-tier: T3; basis: scripts/check-deploy-samples.sh.node scripts/changelog.mjs check→ 58 fragments ok;node scripts/version.mjs check→ 0.4.2 ok.Probes with real
nginx/1.18.0on this tree: the audit's}sample → exit 1, names the location and the three missing headers; the audit'sifsample → exit 1, names the inner block and the four headers; an empty file → exit 1,no server block to check; a comment-only file → exit 1, same reason;^/v}v[0-9]+$with the whole set → exit 0;"^/v[0-9]{1,3}$"with the whole set → exit 0; the shipped sample → exit 0,nginx: deploy/nginx.conf.example parsed.Ran:
npm run check— 2997 tests, 0 fail, on two consecutive retained full runs at this tree; lint at the baseline, typecheck and build clean (dependencies from the existingnpm ciinstall; no manifest change). Retained history at the superseded tree, kept for continuity: 2986/0 before the four shape tests were added, then 2990/0 twice after. One earlier run reported a single failure whose output was not retained; it never recurred in any retained run, so it is recorded here as an unexplained flake rather than a pass.npx tsx --test test/securityHeaders.test.ts— 19/19 pass on this tree; the five red cases fail on the published tip's scriptbash scripts/check-deploy-samples.shwith realnginx/1.18.0— exit 0, seventeen checksbash scripts/check-deploy-samples.shat the published treeb63df3fwith realnginx/1.18.0— exit 1,unknown directive "1,3}$"at its quantifier controlbash scripts/check-nginx-config.sh— exit 0,nginx: deploy/nginx.conf.example parsedbash scripts/check-nginx-config.sh --sample <the audit's}sample>— exit 1, names the location and three headersbash scripts/check-nginx-config.sh --sample <the audit'sifsample>— exit 1, names the inner blockbash scripts/check-nginx-config.sh --sample <empty>and<comment-only>— exit 1,no server block to checknode scripts/risk-gate.mjs --base 066a9cc890cb1f792bff866638517ee7b2f2aa9c—risk-tier: T3; basis: scripts/check-deploy-samples.shNot run:
npm run mock:check— nopublic/orsrc/views/change, so the rule's trigger is absentrisk-tier: T3; basis: scripts/check-deploy-samples.sh
Rollback: revert this commit. It changes the deploy gate, its contract, its tests and its docs only; no runtime, data or migration path is touched.
Docs:
docs/deploy.md§deploy-check, updated here (shapes, token boundaries, quoted quantifier,includegap). Changelog:changelog.d/1097.fixed.mdunchanged — the user-visible fix is the same location rule; this commit closes the shapes it still could not read.Security: deploy and gate code, so this needs the audit seat's
Security:line at this tree's pushed commit, together with the tip PASS. The previous line named698b5c85and must be re-earned at the new tip.Pushed-tip:
0083b77c7a88d739d787d029f1d575475bae7dc2(tree944efbde2e6166878c73ca0412c0e16e7b335722), pushed by Fledge Platform Lead as a child of2ab673037522f274732715db4b9bc8f7cbb672f8through the Git Data API; the tree was rebuilt through the API and matched the author's tree byte-for-byte.The single-failure run recorded above is no longer unexplained: Test traced it to a SIGPIPE in
scripts/check-deploy-samples.sh:82/:95(printf | grep -qunderset -uo pipefail— the producer dies with 141,pipefailand!turn that into "header missing"), same shape at.github/workflows/daily-release.yml:485. Tracked as #1122; this PR does not change those guards, and its own contract run passed 17/17 under a real nginx.