godoc: avoid exposing absolute paths on 404
Exposing the full paths to files is considered possible source of vulnerabilities. Change-Id: Ie9ae3791e51fcff5f1df711f84db9879d7e6ce37 Reviewed-on: https://go-review.googlesource.com/29445 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
f1a397bba5
commit
3f4088edb4
|
@ -6,6 +6,8 @@ package godoc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,6 +38,14 @@ func (p *Presentation) ServePage(w http.ResponseWriter, page Page) {
|
||||||
|
|
||||||
func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
if perr, ok := err.(*os.PathError); ok {
|
||||||
|
rel, err := filepath.Rel(runtime.GOROOT(), perr.Path)
|
||||||
|
if err != nil {
|
||||||
|
perr.Path = "REDACTED"
|
||||||
|
} else {
|
||||||
|
perr.Path = filepath.Join("$GOROOT", rel)
|
||||||
|
}
|
||||||
|
}
|
||||||
p.ServePage(w, Page{
|
p.ServePage(w, Page{
|
||||||
Title: "File " + relpath,
|
Title: "File " + relpath,
|
||||||
Subtitle: relpath,
|
Subtitle: relpath,
|
||||||
|
|
Loading…
Reference in New Issue