Skip to content

Commit

Permalink
pipeline: test rejection of explority paths
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Oct 26, 2023
1 parent e55f675 commit ca87d7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/pipeline/events_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package pipeline

import (
"net/http"
"path/filepath"
"strings"

"github.com/moov-io/base/log"

Expand Down Expand Up @@ -49,6 +51,11 @@ func (fr *FileReceiver) manuallyProduceFileUploaded() http.HandlerFunc {
w.WriteHeader(http.StatusBadRequest)
return
}
// Reject paths which are trying to traverse the filesystem
if strings.Contains(dir, "..") || filepath.IsAbs(dir) {
w.WriteHeader(http.StatusBadRequest)
return
}

matches, err := m.getNonCanceledMatches(dir)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions internal/pipeline/events_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,18 @@ func TestEventsAPI_FileUploadedErrors(t *testing.T) {
defer resp.Body.Close()
require.Equal(t, http.StatusNotFound, resp.StatusCode)
})

t.Run("Call /file-uploaded on insecure paths", func(t *testing.T) {
paths := []string{"../../etc/passwd", "/etc/passwd"}
for i := range paths {
address := fmt.Sprintf("http://%s/shards/testing/pipeline/%s/file-uploaded", adminServer.BindAddr(), paths[i])
req, err := http.NewRequest("PUT", address, nil)
require.NoError(t, err, fmt.Sprintf("on address %s", address))
resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
require.Equal(t, http.StatusNotFound, resp.StatusCode, fmt.Sprintf("on address %s", address))
}
})

}

0 comments on commit ca87d7d

Please sign in to comment.