fix(ssl): support IPv6 hosts in panel SSL self-signed certificate flow#12652
fix(ssl): support IPv6 hosts in panel SSL self-signed certificate flow#12652Sanjays2402 wants to merge 1 commit into1Panel-dev:dev-v2from
Conversation
Enabling Panel SSL with the self-sign provider rejected IPv6 hosts with
"domain format invalid". Two coupled bugs caused this:
1. The frontend extracted the host from window.location.href with
href.split('//')[1].split(':')[0]. For an IPv6 URL like
https://[::1]:1234 that yields '[' \u2014 not a valid host \u2014 because
the second split splits on the first colon inside the bracketed
address. Use window.location.hostname, which natively returns the
bracket-stripped IPv6 host.
2. The backend ObtainSSL flow used net.ParseIP(domain) directly. Even if
the frontend sent the bracketed form ('[::1]'), net.ParseIP rejects
brackets, so the value flowed into IsValidDomain() and failed the
regex.
Add common.ParseIPLoose() that accepts both bare and bracketed IPv6 in
addition to bare IPv4. Use it at both call sites in ObtainSSL (renew
path and create path). A unit test guards the regression.
Files:
- agent/utils/common/common.go (new ParseIPLoose helper)
- agent/utils/common/parse_ip_test.go (12 cases, all green)
- agent/app/service/website_ca.go (call sites switched)
- frontend/src/views/setting/safe/ssl/index.vue
(host extraction fix)
Fixes 1Panel-dev#12646
Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
What this PR does / why we need it?
Fixes #12646.
Enabling Panel SSL with the self-sign provider rejected IPv6 hosts with
domain format invalid(the screenshot in the issue shows the exact error). Two coupled bugs caused this.Bug 1 — frontend host extraction is broken for IPv6 URLs
frontend/src/views/setting/safe/ssl/index.vueextracted the host from the current URL with:For an IPv6 URL like
https://[::1]:1234:href.split('//')[1]=[::1]:1234.split(':')[0]=[…because the second
splitsplits on the first:inside the bracketed address, leaving just the opening bracket.[then flows to the backend as the SSL domain, which fails the format check.Bug 2 — backend rejects bracketed IPv6
agent/app/service/website_ca.go'sObtainSSLusednet.ParseIP(domain)directly:Even if the frontend correctly sent
[::1],net.ParseIPrejects the bracketed form, so it falls through toIsValidDomainand fails the regex. Both call sites inObtainSSL(the renew path and the create path) had this bug.Summary of your change
Frontend (
frontend/src/views/setting/safe/ssl/index.vue): replace the manualhrefparse withwindow.location.hostname, which natively returns the bracket-stripped host for IPv6 URLs (e.g.[::1]→::1).Backend (
agent/utils/common/common.go): add a small exported helperParseIPLoosethat trims whitespace, strips matching outer[/], and delegates tonet.ParseIP. Use it at both call sites inObtainSSLinstead ofnet.ParseIP.Tests (
agent/utils/common/parse_ip_test.go): 12 cases covering bare IPv4/IPv6, bracketed IPv6, whitespace, empty input, only-brackets, hostnames, garbage, and unbalanced brackets.Behaviour for all non-IPv6-bracketed inputs is unchanged.
Verification
Format:
gofmtclean on all touched files.prettier --checkandeslintclean on the touched Vue file.go vetclean on./utils/common/.Please indicate you've done the following: