Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 3c90668

Browse files
committed
fix: clean path before accessing file store
1 parent 9c620ae commit 3c90668

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

server/http.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

280281
func (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

317318
func (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

354355
func (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

Comments
 (0)