Skip to content

Validate Host URL on Login#31986

Open
YannickAlex07 wants to merge 3 commits intohelm:mainfrom
YannickAlex07:fix/validate-host-on-login
Open

Validate Host URL on Login#31986
YannickAlex07 wants to merge 3 commits intohelm:mainfrom
YannickAlex07:fix/validate-host-on-login

Conversation

@YannickAlex07
Copy link
Copy Markdown

@YannickAlex07 YannickAlex07 commented Apr 1, 2026

What this PR does / why we need it:

This PR adds host validation on login to check if a scheme or path is present. If yes, the login is cancelled with a dedicated error message, informing the user what went wrong.

The context of this PR is the issue #31962, where we discussed the handling of the URL scheme in Helm v4 and the change from v3 (also refer to #30873). Currently, providing a scheme does raise a non-specific error, therefore the goal of this change is to provide clearer error messages and halt execution early (even if ORAS would technically also catch these errors later down the line). Providing a path did already produce a warning, however I decided to remove the warning and integrate the check into the new validation.

Validation is implemented using a naive regex to check if any scheme or path is present, as built-in things like url.Parse don't behave well when no scheme is present, interpreting the entire host as a path.

Closes #31962

Special notes for your reviewer:

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

…s. Halt the execution if any is found with a dedicated error message.

Signed-off-by: Yannick Alexander <yannick@alexanderdev.io>
Copilot AI review requested due to automatic review settings April 1, 2026 08:53
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 1, 2026
Signed-off-by: Yannick Alexander <yannick@alexanderdev.io>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds upfront validation for helm registry login host input to reject scheme and path components early, improving error clarity and avoiding later ORAS parsing failures.

Changes:

  • Replaced the previous warning-only “host has path” check with an erroring validateHost pre-check in Client.Login.
  • Introduced a regex-based host parser to detect scheme/path and return dedicated error messages.
  • Updated unit tests to cover scheme/path rejection cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/registry/client.go Adds validateHost + regex-based parsing; enforces no scheme/path before remote.NewRegistry.
pkg/registry/client_test.go Replaces warning test with validateHost table-driven tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/registry/client.go
Comment thread pkg/registry/client.go Outdated
Comment thread pkg/registry/client_test.go
Comment thread pkg/registry/client.go
@promptless-for-oss
Copy link
Copy Markdown

Promptless prepared a documentation update related to this change.

This PR adds stricter host validation to helm registry login. The docs update clarifies the valid host format: hosts must be hostname-only with optional port (e.g., ghcr.io, localhost:8000), and schemes (http://, https://) and paths are not allowed.

Review at helm/helm-www#2057

…e pattern access

Signed-off-by: Yannick Alexander <yannick@alexanderdev.io>
@pull-request-size pull-request-size Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 1, 2026
Comment thread pkg/registry/client.go
// While ORAS will also validate some of these things, the current errors are a bit opaque.
// By validating these things upfront, we can provide clearer error messages to users when they attempt to login with an invalid host string.
func validateHost(host string) error {
matches := hostRegex.FindStringSubmatch(host)
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.

Copilot is correct here, and alluding to a larger problem. This regex will reject many valid "hosts". A "host" here can mean anything from an IP address to a full domain name. Anything which is "resolvable" by the user's OS's network stack, effectively. And Helm can't attempt to encode these rules.

For a check like "Is the "host" actually a URL with a scheme or path?", url.Parse() can be used (One caveat with url.Parse(..) is that a "host" name is not really a URL. But if a URL is supplied, then url.Parse(..) will identify any scheme or path)

Copy link
Copy Markdown
Author

@YannickAlex07 YannickAlex07 Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the concern - the current regex is kept very broad (I updated it after Copilots comment) and should let through the vast majority of hosts but there will likely be cases that it still might not match (one I can think of are URLs with query parameters and co. - however those are anyway not allowed, right?).

Using url.Parse(...) though has some caveats. The main issue is, that without a scheme it will / might interpret the entire url as just a relative path. Because users have to provide the host without a scheme (users not doing that is exactly what we want to catch here), we would need to do an up-front check and prepend a dummy://-scheme for Parse(...) to not get confused and interpret it as a relative path. Doing so would require a regex anyway and then conditionally we would need to prepend a scheme if not match was found.

I am not opposed to changing the logic to use the regex as a scheme check only and then use url.Parse(...) to validate the rest of the URL - would you be good with this approach then?

Copy link
Copy Markdown
Member

@gjenkins8 gjenkins8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registry Login with HTTPS URL

4 participants