Skip to content

caddyhttp: preserve unknown placeholders in static response headers - #8014

Merged
steadytao merged 1 commit into
caddyserver:masterfrom
hktitof:fix/respond-header-replace-known
Sep 13, 2026
Merged

steadytao merged 1 commit into
caddyserver:masterfrom
hktitof:fix/respond-header-replace-known

Conversation

@hktitof

@hktitof hktitof commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #8013

Summary

the respond directive expanded header field names and values with repl.ReplaceAll, which blanks any {...} the replacer does not recognize, so a JSON header value like {"key":"value"} was sent empty and value-{unknown}-kept came out value--kept

this switches both to repl.ReplaceKnown, matching the header handler fix in #4880 (same class as #4418) and the respond body expansion a few lines below, so unrecognized braces are left intact and real placeholders still expand

Steps to reproduce

  1. go test ./modules/caddyhttp/ -run TestStaticResponseHeadersKeepUnknownPlaceholders -count=1
  2. Expected: header values with unknown {...} survive, real placeholders still expand
  3. Actual (raw output on untouched master):
--- FAIL: TestStaticResponseHeadersKeepUnknownPlaceholders (0.00s)
    staticresp_test.go:88: X-Json header = "", want "{\"key\":\"value\"}" (unknown placeholders in header values must not be blanked)
    staticresp_test.go:91: X-Lit header = "value--kept", want "value-{not-a-real-placeholder}-kept"
FAIL

regression tests in staticresp_test.go pin both directions: unknown braces survive and a set placeholder still expands

Assistance Disclosure

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

The respond directive expanded header field names and values with
repl.ReplaceAll, which blanks any {...} the replacer does not recognize

Header values are config data, often JSON or carrying literal braces, so a
value like {key:value} was sent empty and a-{b}-c came out a--c

Use ReplaceKnown, matching the header handler fix in caddyserver#4880 (same class as
caddyserver#4418) and the respond body expansion a few lines below, so unknown braces
survive and real placeholders still expand

@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.

@steadytao steadytao changed the title caddyhttp: only replace known placeholders in respond headers caddyhttp: preserve unknown placeholders in static response headers Sep 13, 2026
@steadytao steadytao added the bug 🐞 Something isn't working label Sep 13, 2026
@steadytao steadytao added this to the v2.11.5 milestone Sep 13, 2026
@steadytao
steadytao merged commit 56e3a88 into caddyserver:master Sep 13, 2026
27 checks passed
steadytao pushed a commit that referenced this pull request Sep 26, 2026
…8017)

The basic auth provider expanded account usernames and passwords with
repl.ReplaceAll, which blanks any {...} the replacer does not recognize

Credentials are config data, so a username like alice-{bogus} was stored
as alice- and a password like ab{cd}ef was quietly rewritten into
different valid base64, turning a config mistake into a working
password the admin never set

Use ReplaceKnown, matching the respond headers fix in #8014 and the
header handler fix in #4880, so unknown braces survive and real
placeholders like {env.*} still expand
@hktitof

hktitof commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge @steadytao, glad this fix is in now, cheers!

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

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

respond blanks literal braces in header values (unknown placeholders)

2 participants