http: Add mechanism to forbid certain files/directories
This commit is contained in:
parent
11e8e7460a
commit
7480742e9e
@ -17,12 +17,13 @@ type ErrorData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
Environment *step.Environment
|
Environment *step.Environment
|
||||||
Directories bool
|
Directories bool
|
||||||
StepExt ucontainer.Set[string]
|
StepExt ucontainer.Set[string]
|
||||||
Index []string
|
Index []string
|
||||||
ErrorDocument string
|
ErrorDocument string
|
||||||
DirectoryDocument string
|
DirectoryDocument string
|
||||||
|
DenyAll ucontainer.Set[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
|
func (this *Handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
|
||||||
@ -43,8 +44,15 @@ func (this *Handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
hasTrailingSlash := strings.HasSuffix(pat, "/")
|
hasTrailingSlash := strings.HasSuffix(pat, "/")
|
||||||
pat = path.Clean(req.URL.Path)
|
pat = path.Clean(req.URL.Path)
|
||||||
|
name := pathToName(pat)
|
||||||
|
|
||||||
info, err := statFile(filesystem, pathToName(pat))
|
// access control
|
||||||
|
if this.DenyAll.Has(name) {
|
||||||
|
this.serveError(res, req, http.StatusForbidden, req.URL, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := statFile(filesystem, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.serveError(res, req, http.StatusNotFound, req.URL, false)
|
this.serveError(res, req, http.StatusNotFound, req.URL, false)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user