Skip to content

Commit

Permalink
Merge pull request #965 from neicnordic/feat/disallow-reserved-charac…
Browse files Browse the repository at this point in the history
…ters

Disallow reserved characters
  • Loading branch information
jbygdell authored Jul 31, 2024
2 parents 7a23296 + 268d923 commit b203446
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions sda/cmd/s3inbox/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,11 @@ func formatUploadFilePath(filePath string) (string, error) {
outPath := strings.ReplaceAll(filePath, "\\", "/")

// [\x00-\x1F\x7F] is the control character set
re := regexp.MustCompile(`[\\:\*\?"<>\|\x00-\x1F\x7F]`)
re := regexp.MustCompile(`[\\<>"\|\x00-\x1F\x7F\!\*\'\(\)\;\:\@\&\=\+\$\,\?\%\#\[\]]`)

dissallowedChars := re.FindAllString(outPath, -1)
if dissallowedChars != nil {
return outPath, fmt.Errorf("filepath contains disallowed characters: %+v", strings.Join(dissallowedChars, ", "))
disallowedChars := re.FindAllString(outPath, -1)
if disallowedChars != nil {
return outPath, fmt.Errorf("filepath contains disallowed characters: %+v", strings.Join(disallowedChars, ", "))
}

return outPath, nil
Expand Down
4 changes: 2 additions & 2 deletions sda/cmd/s3inbox/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (suite *ProxyTests) TestFormatUploadFilePath() {
assert.EqualError(suite.T(), err, "filepath contains mixed '\\' and '/' characters")

// no mixed "\" and "/" but not allowed
weirdPath = `dq\sw:*?"<>|\t\sdf.c4gh`
weirdPath = `dq\sw:*?"<>|\t\sdf!s'(a);w@4&f=+e$,g#[]d%.c4gh`
_, err = formatUploadFilePath(weirdPath)
assert.EqualError(suite.T(), err, "filepath contains disallowed characters: :, *, ?, \", <, >, |")
assert.EqualError(suite.T(), err, "filepath contains disallowed characters: :, *, ?, \", <, >, |, !, ', (, ), ;, @, &, =, +, $, ,, #, [, ], %")
}

0 comments on commit b203446

Please sign in to comment.