fix: enforce rules on recursive operations and expired proxy tokens (#6053)
This commit is contained in:
1 parent
a789f29cee
commit
72faf6dd3c
5 files changed
+307
-19
No files matched your search
+30
-16
@@ -35,25 +35,19 @@ type data struct {
|
||||
|
||||
// Check implements rules.Checker.
|
||||
func (d *data) Check(path string) bool {
|
||||
// Rules are written as "/"-separated virtual paths, but callers hand us
|
||||
// paths built by the OS as well as ones taken from the request: afero.Walk
|
||||
// and filepath.Join use "\" on Windows, where the filesystem also treats it
|
||||
// as a separator. Canonicalize first so the authorization decision does not
|
||||
// depend on which separator the caller happened to use.
|
||||
path = slashClean(path)
|
||||
|
||||
// When the filesystem has been rebased (e.g. a public share rooted at a
|
||||
// subdirectory), the incoming path is relative to that root. Resolve it
|
||||
// back to the user's original scope before matching rules, otherwise rules
|
||||
// targeting paths below the share root would be silently bypassed.
|
||||
if d.checkerPrefix != "" {
|
||||
path = gopath.Join(d.checkerPrefix, path)
|
||||
}
|
||||
|
||||
if d.user.HideDotfiles && rules.MatchHidden(path) {
|
||||
if d.user.HideDotfiles && rules.MatchHidden(d.rulePath(path)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return d.CheckRules(path)
|
||||
}
|
||||
|
||||
// CheckRules reports whether the global and user rules allow path. Unlike
|
||||
// Check, it ignores HideDotfiles: hiding dotfiles is a display preference, so
|
||||
// it must not stop a user from operating on a tree that contains one.
|
||||
func (d *data) CheckRules(path string) bool {
|
||||
path = d.rulePath(path)
|
||||
|
||||
allow := true
|
||||
for _, rule := range d.settings.Rules {
|
||||
if rule.Matches(path, d.server.CaseInsensitiveFs) {
|
||||
@@ -70,6 +64,26 @@ func (d *data) Check(path string) bool {
|
||||
return allow
|
||||
}
|
||||
|
||||
// rulePath canonicalizes path into the form the rules are written in.
|
||||
func (d *data) rulePath(path string) string {
|
||||
// Rules are written as "/"-separated virtual paths, but callers hand us
|
||||
// paths built by the OS as well as ones taken from the request: afero.Walk
|
||||
// and filepath.Join use "\" on Windows, where the filesystem also treats it
|
||||
// as a separator. Canonicalize first so the authorization decision does not
|
||||
// depend on which separator the caller happened to use.
|
||||
path = slashClean(path)
|
||||
|
||||
// When the filesystem has been rebased (e.g. a public share rooted at a
|
||||
// subdirectory), the incoming path is relative to that root. Resolve it
|
||||
// back to the user's original scope before matching rules, otherwise rules
|
||||
// targeting paths below the share root would be silently bypassed.
|
||||
if d.checkerPrefix != "" {
|
||||
path = gopath.Join(d.checkerPrefix, path)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
func handle(fn handleFunc, prefix string, store *storage.Storage, server *settings.Server) http.Handler {
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
for k, v := range globalHeaders {
|
||||
|
||||
Reference in new issue
Block a user