Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/url: should Parse accept hostnames with leading hyphens? #19462

Closed
xeoncross opened this issue Mar 8, 2017 · 4 comments
Closed

net/url: should Parse accept hostnames with leading hyphens? #19462

xeoncross opened this issue Mar 8, 2017 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@xeoncross
Copy link

xeoncross commented Mar 8, 2017

What version of Go are you using (go version)?

go version go1.7.4 darwin/amd64

What did you do?

I have tested with multiple invalid strings and found that url.Parse() and url.ParseRequestURI() allow invalid URL strings without an error.

u, err := url.Parse("http://-10:10/foobar")

https://play.golang.org/p/_qvse6f4C9

What did you expect to see?

An Error. -10:10 is not a URL, an IP 4/6, or a CIDR.

What did you see instead?

net/url allows invalid hostnames

@xeoncross xeoncross changed the title Invalid URL's accepted by url.Parse() Invalid URLs accepted by url.Parse() Mar 8, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Mar 8, 2017

This looks like a joke or meme instead of a bug report.

Feel free to re-file if you want to be serious.

@bradfitz bradfitz closed this as completed Mar 8, 2017
@xeoncross
Copy link
Author

I removed the photo. I don't think a new issue is needed. I'll just leave this here for future google searches.

@bradfitz bradfitz reopened this Mar 8, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Mar 8, 2017

So the question is whether url.Parse should be strict about enforcing that a DNS name can't begin with a hyphen (and can only contain hyphens in the middle/end)?

But those rules only apply to certain schemes.

The URL spec (RFC 3986) says:

      host        = IP-literal / IPv4address / reg-name
...
   reg-name      = *( unreserved / pct-encoded / sub-delims )
...
   unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"

So it seems like hyphens are valid anywhere.

Do you have a counterargument?

@bradfitz bradfitz added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 8, 2017
@bradfitz bradfitz changed the title Invalid URLs accepted by url.Parse() net/url: should Parse accept hostnames with leading hyphens? Mar 8, 2017
@xeoncross
Copy link
Author

No counterargument.

@bradfitz bradfitz closed this as completed Mar 8, 2017
@golang golang locked and limited conversation to collaborators Mar 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants