Skip to content

Commit fef9a33

Browse files
committed
Fixes path injection vulnerability #35
1 parent bd6afb3 commit fef9a33

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

archiver/remoteServer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math/rand"
1212
"net/http"
1313
"os"
14+
"path"
1415
"path/filepath"
1516
"strings"
1617
"sync"
@@ -241,14 +242,24 @@ type CreateReportRequest struct {
241242
Name string `json:"name"`
242243
}
243244

245+
func sanitizeFilename(name string) string {
246+
return path.Base(path.Clean("/" + name))
247+
}
248+
244249
func (s *ArchiverServer) createReport(c *gin.Context) {
245250
var req CreateReportRequest
246251
if err := c.ShouldBindJSON(&req); handleError(c, err) {
247252
return
248253
}
249254

255+
reportName := sanitizeFilename(req.Name)
256+
if reportName == "." || reportName == "/" {
257+
handleError(c, fmt.Errorf("invalid report name '%s'", req.Name))
258+
return
259+
}
260+
250261
reportID := generateReportID()
251-
_, err := s.registerReport(reportID, req.Name)
262+
_, err := s.registerReport(reportID, reportName)
252263
if handleError(c, err) {
253264
return
254265
}

0 commit comments

Comments
 (0)