Skip to content

Use net/url.Parse in extractHost to prevent host confusion#10

Merged
andrew merged 1 commit into
mainfrom
fix/extract-host-url-parsing
May 2, 2026
Merged

Use net/url.Parse in extractHost to prevent host confusion#10
andrew merged 1 commit into
mainfrom
fix/extract-host-url-parsing

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 2, 2026

The custom extractHost() function in defaults.go manually parsed URLs by splitting on ://, @, and path separators. This hand-rolled parser could be confused by URLs with encoded characters or unusual userinfo components, causing IsDefaultRegistry and IsPrivateRegistry to misclassify hostile URLs as the official registry.

Replaced with net/url.Parse() followed by Hostname(), which handles all the edge cases (userinfo, percent-encoding, IPv6 brackets, etc.) correctly.

Added TestExtractHostRejectsUserinfo to verify that userinfo in URLs does not confuse host extraction.

@andrew andrew merged commit 90655c1 into main May 2, 2026
2 checks passed
@andrew andrew deleted the fix/extract-host-url-parsing branch May 2, 2026 16:22
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.

1 participant