mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-15 11:57:59 +00:00
fix(dput): validate :file path param to prevent directory traversal
This commit is contained in:
+7
-1
@@ -208,6 +208,12 @@ func apiFilesUploadOne(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileName := c.Params.ByName("file")
|
||||||
|
if !verifyPath(fileName) {
|
||||||
|
AbortWithJSONError(c, 400, fmt.Errorf("wrong file"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(context.UploadPath(), utils.SanitizePath(c.Params.ByName("dir")))
|
path := filepath.Join(context.UploadPath(), utils.SanitizePath(c.Params.ByName("dir")))
|
||||||
err := os.MkdirAll(path, 0777)
|
err := os.MkdirAll(path, 0777)
|
||||||
|
|
||||||
@@ -217,7 +223,7 @@ func apiFilesUploadOne(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
stored := []string{}
|
stored := []string{}
|
||||||
|
|
||||||
destPath := filepath.Join(path, c.Params.ByName("file"))
|
destPath := filepath.Join(path, fileName)
|
||||||
dst, err := os.Create(destPath)
|
dst, err := os.Create(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
AbortWithJSONError(c, 500, err)
|
AbortWithJSONError(c, 500, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user