Skip to content

caddyhttp: Prevent commas in header values from being split in CLI commands - #7268

Merged
mholt merged 1 commit into
caddyserver:masterfrom
gilbsgilbs:comma-in-headers
Sep 23, 2025
Merged

mholt merged 1 commit into
caddyserver:masterfrom
gilbsgilbs:comma-in-headers

Conversation

@gilbsgilbs

Copy link
Copy Markdown
Contributor

pflag.GetStringSlice treats commas as delimiters, which causes issues when passing headers whose values contain commas (X-Robots-Tag: noindex, nofollow). These are incorrectly split into multiple headers and errors out:

  • X-Robots-Tag: noindex
  • nofollow

Switch to pflag.GetStringArray, which does not split on commas[1].

Note that this changes behavior for cases where multiple headers were provided in a single argument with commas (--header-down "X-Foo: Bar,X-Bar: Foo"). Such cases will now be treated as a single header value. If this breaking change is unacceptable, we will need a smarter fallback mechanism.

[1] spf13/pflag#90

Assistance Disclosure

"No AI was used."

`pflag.GetStringSlice` treats commas as delimiters, which causes issues
when passing headers whose values contain commas (`X-Robots-Tag:
noindex, nofollow`). These are incorrectly split into multiple headers
and errors out:

- `X-Robots-Tag: noindex`
- ` nofollow`

Switch to `pflag.GetStringArray`, which does not split on commas[1].

Note that this changes behavior for cases where multiple headers were
provided in a single argument with commas (`--header-down "X-Foo:
Bar,X-Bar: Foo"`). Such cases will now be treated as a single header
value. If this breaking change is unacceptable, we will need a smarter
fallback mechanism.

[1] spf13/pflag#90

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

Makes sense, thanks! We don't tend to test these commands too much (generally recommend using a Caddyfile) so things like this get easily missed.

@francislavoie francislavoie changed the title fix: prevent commas in header values from being split caddyhttp: Prevent commas in header values from being split in CLI commands Sep 20, 2025
@francislavoie francislavoie added this to the v2.10.3 milestone Sep 20, 2025
@mholt
mholt merged commit f5c3094 into caddyserver:master Sep 23, 2025
@mholt

mholt commented Sep 23, 2025

Copy link
Copy Markdown
Member

Yeah, this is probably more correct. Thank you!

@francislavoie francislavoie modified the milestones: v2.10.3, v2.11.0 Oct 16, 2025
@github-actions github-actions Bot mentioned this pull request Dec 3, 2025
4 tasks
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.

3 participants