lib/model, lib/versioner: Prevent symlink attack via versioning (fixes #4286)

Prior to this, the following is possible:

- Create a symlink "foo -> /somewhere", it gets synced
- Delete "foo", it gets versioned
- Create "foo/bar", it gets synced
- Delete "foo/bar", it gets versioned in "/somewhere/bar"

With this change, versioners should never version symlinks.
This commit is contained in:
Jakob Borg
2017-07-25 11:36:09 +02:00
parent 54155cb42d
commit f1f21bf220
8 changed files with 146 additions and 5 deletions

View File

@@ -26,6 +26,8 @@ type Simple struct {
}
func NewSimple(folderID, folderPath string, params map[string]string) Versioner {
cleanSymlinks(folderPath)
keep, err := strconv.Atoi(params["keep"])
if err != nil {
keep = 5 // A reasonable default
@@ -50,6 +52,9 @@ func (v Simple) Archive(filePath string) error {
} else if err != nil {
return err
}
if fileInfo.Mode()&os.ModeSymlink != 0 {
panic("bug: attempting to version a symlink")
}
versionsDir := filepath.Join(v.folderPath, ".stversions")
_, err = os.Stat(versionsDir)