File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import (
11
11
"math/rand"
12
12
"net/http"
13
13
"os"
14
+ "path"
14
15
"path/filepath"
15
16
"strings"
16
17
"sync"
@@ -241,14 +242,24 @@ type CreateReportRequest struct {
241
242
Name string `json:"name"`
242
243
}
243
244
245
+ func sanitizeFilename (name string ) string {
246
+ return path .Base (path .Clean ("/" + name ))
247
+ }
248
+
244
249
func (s * ArchiverServer ) createReport (c * gin.Context ) {
245
250
var req CreateReportRequest
246
251
if err := c .ShouldBindJSON (& req ); handleError (c , err ) {
247
252
return
248
253
}
249
254
255
+ reportName := sanitizeFilename (req .Name )
256
+ if reportName == "." || reportName == "/" {
257
+ handleError (c , fmt .Errorf ("invalid report name '%s'" , req .Name ))
258
+ return
259
+ }
260
+
250
261
reportID := generateReportID ()
251
- _ , err := s .registerReport (reportID , req . Name )
262
+ _ , err := s .registerReport (reportID , reportName )
252
263
if handleError (c , err ) {
253
264
return
254
265
}
You can’t perform that action at this time.
0 commit comments