Skip to content

caddyhttp: keep absent optional placeholders empty - #8019

Merged
francislavoie merged 4 commits into
masterfrom
optional-http-placeholders
Oct 3, 2026
Merged

francislavoie merged 4 commits into
masterfrom
optional-http-placeholders

Conversation

@steadytao

Copy link
Copy Markdown
Member

Summary

Keep missing cookie and valid TLS placeholders empty when using ReplaceKnown. Unknown or malformed TLS placeholder names remain literal, and existing TLS values are unchanged.

Follow-up to #8014, prompted by @steffenbusch’s compatibility concern in #8013 (thankyou)

Added coverage for absent and present cookies, valid TLS placeholders on plain HTTP, invalid TLS names and static-response headers.

Assistance Disclosure

Claude was used to help trace the compatibility failure mentioned by Steffen which was then verified and the PR was authored by hand.

@steffenbusch

Copy link
Copy Markdown
Contributor

Hi @steadytao I was wondering if default value support in placeholders (#7967) could be a solution that makes everyone happy.

Let me (try to) explain my thought:
If ReplaceKnown respects a placeholder default value of an empty string for an unknown placeholder, it should behave the same as ReplaceAll where the unknown placeholder would be resolved to an empty string.

@steadytao

Copy link
Copy Markdown
Member Author

Hmmmm. Defaults could be fairly useful separately but this fixes existing configurations without requiring users to change their placeholders. #7967 only applies a default when the underlying name is recognised so it would still need this fix for valid TLS placeholders on plain HTTP.

@steadytao

Copy link
Copy Markdown
Member Author

Happy to deliberate though.

@steadytao steadytao added the bug 🐞 Something isn't working label Sep 14, 2026
@steadytao steadytao added this to the v2.11.5 milestone Sep 14, 2026
@steadytao

Copy link
Copy Markdown
Member Author

Does need merge before .5 ^

@steffenbusch

Copy link
Copy Markdown
Contributor

Defaults could be fairly useful separately but this fixes existing configurations without requiring users to change their placeholders.

Preserving existing configurations is much appreciated.

#7967 only applies a default when the underlying name is recognised so it would still need this fix for valid TLS placeholders on plain HTTP.

I see.

A potential use case for other placeholders beside tls and cookie are http request headers that are passed via placeholders to backends (maybe even in request_body / #8008) and those backends might expect an empty value if not provided by the browser/client rather than the value of eg {http.request.header.X-Api-Key}.

@steadytao

steadytao commented Sep 14, 2026 •

Copy link
Copy Markdown
Member Author

That case should already work as {http.request.header.X-Api-Key} resolves to an empty string when the header is absent, even with ReplaceKnown. It would behave the same with #8008 so the backend would not receive the literal placeholder. Cookies and TLS were the inconsistent cases that this addresses.

@steffenbusch

Copy link
Copy Markdown
Contributor

Very glad to hear - maybe a regression test for such use case could be added to #8008 @hktitof

@steadytao

Copy link
Copy Markdown
Member Author

Not a bad shout. Yes please.

@hktitof

hktitof commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

pushed a regression test for this to #8008 just now covering both absent and present header placeholders, all clean!

@francislavoie francislavoie modified the milestones: v2.11.6, v2.11.7 Sep 30, 2026
@steadytao steadytao modified the milestones: v2.11.7, v2.12.0 Oct 3, 2026
@steadytao

steadytao commented Oct 3, 2026 •

Copy link
Copy Markdown
Member Author

@steadytao needed for 2.11.7

@steadytao steadytao self-assigned this Oct 3, 2026
@francislavoie
francislavoie enabled auto-merge (squash) October 3, 2026 01:46
@francislavoie
francislavoie merged commit 55a95ad into master Oct 3, 2026
31 checks passed
@francislavoie
francislavoie deleted the optional-http-placeholders branch October 3, 2026 01:54
farisbasha added a commit to farisbasha/caddy that referenced this pull request Dec 1, 2026
Since caddyserver#8019 a missing cookie placeholder returned an empty string, so CEL
expressions such as `{cookie.foo} != null` matched every request. Return
nil (still known) so CEL sees null again, while string replacement keeps
writing an empty value.

Fixes caddyserver#8481
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.

4 participants