Skip to content

requestbody: replace only known placeholders in the set body - #8008

Merged
steadytao merged 1 commit into
caddyserver:masterfrom
hktitof:fix/requestbody-set-known-placeholders
Sep 26, 2026
Merged

steadytao merged 1 commit into
caddyserver:masterfrom
hktitof:fix/requestbody-set-known-placeholders

Conversation

@hktitof

@hktitof hktitof commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

the request_body set body is user-supplied and commonly JSON, but it was expanded with repl.ReplaceAll, which blanks any {...} the replacer does not recognize, so a plain JSON body was sent empty

a body that does use a placeholder is mangled too: {"token":"{env.SOME_VAR}"} came out as "}, since the opening {"token":" is consumed as an unrecognized placeholder before the real one is reached

this switches the set body to repl.ReplaceKnown, matching the respond body and the active health check body (#8003), so unrecognized braces are left intact and real placeholders still expand

regression tests in requestbody_test.go pin both directions: JSON braces survive, a known placeholder still expands

reported for the JSON case in #7021

Assistance Disclosure

AI used: yes, for drafting test coverage and description formatting

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

The set body is user-supplied and commonly JSON, but it was expanded with
ReplaceAll, which blanks any {...} the replacer does not recognize, so a
plain JSON body was sent empty and a body mixing JSON with a real
placeholder was mangled

Use ReplaceKnown, matching the respond body, so unrecognized braces are
left intact and real placeholders still expand. Regression test pins both
directions
@hktitof
hktitof force-pushed the fix/requestbody-set-known-placeholders branch from 5c96725 to 27e2e17 Compare September 14, 2026 12:02
@hktitof

hktitof commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

all checks green on the head, ready whenever you have time @steadytao!

@steadytao
steadytao merged commit 81a0b6d into caddyserver:master Sep 26, 2026
25 checks passed
@hktitof

hktitof commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the review and merge @steadytao, happy to contribute to caddy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants