Skip to content

webdav: return forbidden on failed proppatch #94

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion webdav/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ loop:

f, err := fs.OpenFile(ctx, name, os.O_RDWR, 0)
if err != nil {
stat, statErr := fs.Stat(ctx, name)
// If the error is a permission error or the file is a directory, return permission
// denied. We check the directory case because some file systems do not support
// writing to directories.
if errors.Is(err, os.ErrPermission) || (statErr == nil && stat.IsDir()) {
return patchesForbidden(patches), nil
}
return nil, err
}
defer f.Close()
Expand All @@ -327,13 +334,17 @@ loop:
}
// The file doesn't implement the optional DeadPropsHolder interface, so
// all patches are forbidden.
return patchesForbidden(patches), nil
}

func patchesForbidden(patches []Proppatch) []Propstat {
pstat := Propstat{Status: http.StatusForbidden}
for _, patch := range patches {
for _, p := range patch.Props {
pstat.Props = append(pstat.Props, Property{XMLName: p.XMLName})
}
}
return []Propstat{pstat}, nil
return []Propstat{pstat}
}

func escapeXML(s string) string {
Expand Down