fix(server): allow template variables in link hostname. Fixes #10696#16371
fix(server): allow template variables in link hostname. Fixes #10696#16371myzk-a wants to merge 3 commits into
Conversation
…j#10696 Signed-off-by: myzk-a <rorosocksxion@gmail.com>
abe5ee8 to
cdd0ca2
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe URL sanitization logic in config/config.go was changed to derive the URI scheme via a new ChangesURL Sanitize scheme extraction
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)Not applicable — the change is a localized scheme-parsing refactor with a single component and no multi-actor interaction flow. Related issues: Fixes #10696 by allowing template variables in link hostnames without breaking URL sanitization. Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: none specified Poem: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #10696
Motivation
Configuring a link with a template variable in the hostname part of the URL, e.g.
makes the Argo Server crash at startup:
This is a regression: it worked in 3.3 and broke when link sanitization was introduced in 3.4.0-rc1 (#8779).
Config.Sanitizepasses the raw, un-expanded URL tourl.Parse, which rejects${...}in the host part (variables in the path/query are unaffected). That parse only exists to extract the scheme and reject dangerous protocols such asjavascript:— the server never needs the host, since template variables are expanded by the UI at render time.Modifications
config/config.go: replaceurl.ParseinSanitizewith aschemeOfhelper that extracts only the scheme, per RFC 3986 §3.1. Since the host/path/query are never parsed, template variables may appear anywhere in the URL.schemeOfis re-implemented from the RFC (not copied) and uses the same technique as the standard library's unexportednet/urlgetScheme; a missing scheme is reported as"", which the protocol allowlist rejects as before. Scheme validation behavior is fully preserved, including rejectingjavascript:URLs that contain variables.config/config_test.go: add regression test cases.Note that URLs that
url.Parsewould reject for reasons other than the scheme (e.g. a malformed host) are now accepted. This is intentional: the server cannot distinguish a typo from an un-expanded template variable, and the failure mode improves from "server crash-loops at startup" to "a dead link in the UI".Verification
http://${metadata.name}.logging-facility?podName=${metadata.name}reproduces the exact error from the issue before the fix and passes after it; existingTestSanitizecases still pass.workflow-controller-configmap, the server crash-looped before the fix and starts normally after it.Documentation
No change needed: docs/links.md already states that links can contain placeholder variables, without restricting where they may appear. This fix restores the documented behavior.
AI
Claude Code was used for root-cause analysis, regression history research, design discussion, and code review. The code and tests were written by the author.
Summary by CodeRabbit
http://URLs containing placeholders are now accepted as expected.javascript:URLs with placeholders continue to be blocked with the existing error message.