Repository navigation
caddyfile: reject site blocks with unbalanced braces - #8375
Merged
steadytao merged 2 commits intoNov 8, 2026
Merged
Conversation
A braced site block whose last directive has its own block was accepted with its closing brace missing, because the directive's closing brace satisfied the check for the site block's. A stray closing brace after a braceless site was likewise accepted as the end of the block. Track whether the directives of a block were terminated by the block's own closing brace: running out of tokens in a braced block is an error, and a closing brace in a braceless block is an error. Fixes caddyserver#8374
|
✅ Contributor License Agreement All identified contributors have signed the CLA. Thank you! |
steadytao
approved these changes
Nov 8, 2026
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.
Fixes #8374
The Caddyfile parser accepted two unbalanced-brace shapes:
Dispenser.Next()at EOF leaves the cursor on the last token.}after a braceless site, whichdirectives()treated as the end of the block.Parsenow tracks whether the directives of a block were terminated by the block's own closing brace. Running out of tokens inside a braced block returnsunexpected EOF, and a}in a braceless block returnsUnexpected '}' because no matching opening brace, the same messagedirective()already used for that shape.Tests: new cases in the
TestParseAlltable (6 error cases covering both issue shapes, plus an unclosed global options block, and 2 valid controls with nested directive blocks).go test ./caddyconfig/caddyfile/ -count=1andgo test -short ./caddyconfig/... .pass. With the patched binary,caddy adaptrejects both examples from the issue (exit 1) and adapts a valid nested config cleanly (exit 0).Three things worth calling out:
TestWrapUnbracedSiteIdempotentReproducer: its fuzz-derived input is the issue's case-2 shape (a stray}after a braceless site), so Parse now rejects it; the formatter-idempotency assertion on the same input is kept unchanged.:8080 { file_server), the error changes from the previous incidentalsyntax error: unexpected token 'file_server', expecting '}'tounexpected EOF, so all missing-close shapes report the same error.}appearing where a site address is expected (e.g. a lone}or a stray}after a properly closed site block) is still read by Parse as a site key, exactly as on master;caddy adaptrejects such blocks downstream. That is a separate address-parsing behaviour, not one of the shapes in this issue.Assistance Disclosure
This change was prepared with AI assistance (Claude). I reviewed the diff, reproduced the bug on master before the fix, and verified the fix with the package tests and
caddy adaptruns described above.