Skip to content

net/url: surprising behavior when OmitHost=true and Path starts with // #78328

@neild

Description

@neild

A url.URL with OmitHost=true and a Path starting with // will surprisingly stringify as a URL with an authority (host) component:

u := url.URL{
	OmitHost: true,
	Scheme:   "file",
	Path:     "//host/path",
}
fmt.Println(u.String()) // file://host/path

OmitHost is only expected to be set for URLs with a Path starting with a single /(it exists entirely to handle this particular form of URL). url.Parse will never create a URL like the above. However, it's possible to manually construct one, and the results are surprising.

Perhaps we should escape the initial / in the path in this situation.

(This was reported to us as a potential vulnerability. We consider misbehavior in url.Parse to be a potential vulnerability, but not a user-constructed invalid url.URL such as the one above.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions