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/http: parent directory listing vulnerability #3842

Closed
snaury opened this issue Jul 19, 2012 · 5 comments
Closed

net/http: parent directory listing vulnerability #3842

snaury opened this issue Jul 19, 2012 · 5 comments

Comments

@snaury
Copy link
Contributor

snaury commented Jul 19, 2012

There's a pretty classic vulnerability in net/http that allows users to:

1. Get a file listing of any directory (despite index.html) via requests in the form
http://goserver/.%00/
2. Get a file listing of a *parent* directory via requests in the form
http://goserver/..%00/

This is not much, since I can't think of a way to traverse farther than a single parent
directory, or opening files in said directory, but file listings of any directory might
be quite severe for some.
@snaury
Copy link
Contributor Author

snaury commented Jul 19, 2012

Comment 1:

Correction: by any directory I meant any subdirectory in http.FileHandler.
Until this is fixed (the best place is in path.Clean probably?) a possible workaround
for those who need it might be something like this:
func hardened(handler http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        index := strings.Index(r.URL.Path, "\x00")
        if index >= 0 {
            http.Error(w, "403 Forbidden", 403)
        } else {
            handler.ServeHTTP(w, r)
        }
    })
}
// ...
http.ListenAndServe(":80", hardened(http.DefaultServeMux))

@bradfitz
Copy link
Contributor

Comment 2:

Labels changed: removed priority-triage.

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 3:

http://golang.org/cl/6442061

@bradfitz
Copy link
Contributor

Comment 4:

This issue was closed by revision 538b212.

Status changed to Fixed.

@rsc
Copy link
Contributor

rsc commented Jul 30, 2012

Comment 5:

Labels changed: added go1.0.3, security.

@rsc rsc added this to the Go1.0.3 milestone Apr 14, 2015
@rsc rsc removed the go1.0.3 label Apr 14, 2015
bradfitz added a commit that referenced this issue May 11, 2015
««« backport 2307a931664e
net/http: don't allow zero byte in FileServer paths

Should probably be fixed in the syscall package, either
additional or instead of this CL.

Fixes #3842

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6442061

»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants