Repository navigation
reverseproxy: replace only known placeholders in health check body - #8003
Merged
mholt merged 1 commit intoSep 9, 2026
Merged
Conversation
The active health check body is user-supplied and commonly JSON, but it
was expanded with ReplaceAll, which blanks any `{...}` the replacer does
not recognize. Only globals are available here, so a JSON
health_request_body was sent as an empty body.
This is not limited to bodies without placeholders. A body that does use
one is mangled too: `{"token":"{env.SOME_VAR}"}` is sent as `"}`, since
the opening `{"token":"` is consumed as an unrecognized placeholder
before the real one is reached.
Use ReplaceKnown, matching the header values a few lines below, so
unrecognized braces are left intact and real placeholders still expand.
Only the body is changed. The Host header on the same path keeps
ReplaceAll deliberately: Go's HTTP server blanks a Host containing
braces, so leaving `{...}` intact there would send a Host the upstream
discards, where blanking it lets Go fall back to the URL host.
steadytao
approved these changes
Sep 9, 2026
steadytao
left a comment
Member
There was a problem hiding this comment.
Follows the same known-placeholder policy as health-check headers. LGTM.
Member
|
CLA assistant and its delays. Rechecked the PR so you can sign now. |
mholt
approved these changes
Sep 9, 2026
This was referenced Sep 10, 2026
This was referenced Sep 30, 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 #7021. Implements @mholt's suggestion in that thread ("We could probably switch to replacing only known placeholders"), scoped to the body.
Problem
The active health check body is expanded with
repl.ReplaceAll, which blanks any{...}the replacer doesn't recognise. Only globals are available here, so a JSONhealth_request_bodyis sent as an empty body:The header values three lines below already use
ReplaceKnown, so the two halves of the same request were built with different rules.This isn't limited to bodies without placeholders. A body that does use one is mangled too —
{"token":"{env.SOME_VAR}"}goes out as"}, because the opening{"token":"is consumed as an unrecognised placeholder before the real one is reached. Both are in the tests.Fix
One line:
ReplaceAll→ReplaceKnownfor the body. Unrecognised braces are left intact; real placeholders still expand.Scope: why the
Hostheader is deliberately left aloneI said on the issue that I'd change
Hoston line 454 too, since it usesReplaceAllwhile the header values below it useReplaceKnown. Testing showed that would make it worse, so I didn't.Go's HTTP server blanks a
Hostcontaining braces — sendingHost: {not.a.placeholder}to anhttptestserver, the handler seesr.Host == "". That's stdlib behaviour. So todayReplaceAllblanks an unknown placeholder and Go falls back to the URL host and the request works;ReplaceKnownwould leave the literal{...}inreq.Hostand the upstream would discard it. Happy to revisit if you read it differently.Tests
Two cases in
active_health_test.go, built on the existingnewActiveHandler/runActiveHealthCheckharness:{env.…}still has the placeholder expandedBoth fail on
masterand pass with the change:go test ./modules/caddyhttp/...,go vetandgofmtare clean.Disclosure
Per CONTRIBUTING: this was written with AI assistance (Claude). I can explain every line, and the behaviour of both the fix and the
Hostfinding above was verified by running the tests, not inferred.