@@ -10,6 +10,7 @@ import (
1010 "io/ioutil"
1111 "log"
1212 "net/http"
13+ "path/filepath"
1314 "strconv"
1415 "strings"
1516
@@ -279,7 +280,7 @@ func (s *HTTPServer) handlePostSeq(w http.ResponseWriter, r *http.Request) {
279280
280281func (s * HTTPServer ) handlePostFile (w http.ResponseWriter , r * http.Request ) {
281282 u := s .charmUserFromRequest (w , r )
282- path := pattern .Path (r .Context ())
283+ path := filepath . Clean ( pattern .Path (r .Context () ))
283284 ms := r .URL .Query ().Get ("mode" )
284285 m , err := strconv .ParseUint (ms , 10 , 32 )
285286 if err != nil {
@@ -316,7 +317,7 @@ func (s *HTTPServer) handlePostFile(w http.ResponseWriter, r *http.Request) {
316317
317318func (s * HTTPServer ) handleGetFile (w http.ResponseWriter , r * http.Request ) {
318319 u := s .charmUserFromRequest (w , r )
319- path := pattern .Path (r .Context ())
320+ path := filepath . Clean ( pattern .Path (r .Context () ))
320321 f , err := s .cfg .FileStore .Get (u .CharmID , path )
321322 if errors .Is (err , fs .ErrNotExist ) {
322323 s .renderCustomError (w , "file not found" , http .StatusNotFound )
@@ -353,7 +354,7 @@ func (s *HTTPServer) handleGetFile(w http.ResponseWriter, r *http.Request) {
353354
354355func (s * HTTPServer ) handleDeleteFile (w http.ResponseWriter , r * http.Request ) {
355356 u := s .charmUserFromRequest (w , r )
356- path := pattern .Path (r .Context ())
357+ path := filepath . Clean ( pattern .Path (r .Context () ))
357358 err := s .cfg .FileStore .Delete (u .CharmID , path )
358359 if err != nil {
359360 log .Printf ("cannot delete file: %s" , err )
0 commit comments