-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
Does the library unescape the URI before handing it to the handler functions? |
Which library and URI are you referring to? |
The golang provided net/http and the incoming URI. Another formulation of this is essentially - if the client sends a name such as |
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #376 +/- ##
==========================================
+ Coverage 55.49% 56.25% +0.76%
==========================================
Files 8 8
Lines 1202 1223 +21
==========================================
+ Hits 667 688 +21
Misses 482 482
Partials 53 53
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Great point. In short, a file with the name As far as I see, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small stuff you might wanna look at, but looks good in general! :)
proxy.go
Outdated
func (p *Proxy) notAcceptableResponse(w http.ResponseWriter, _ *http.Request) { | ||
log.Debug("not acceptable response") | ||
w.WriteHeader(406) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (p *Proxy) notAcceptableResponse(w http.ResponseWriter, _ *http.Request) { | |
log.Debug("not acceptable response") | |
w.WriteHeader(406) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this and write the header directly otherwise you will get double debug messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intended to be a rather generic debug message like the other response functions do (e.g. see line 91 in proxy.go
).
example of debug output:
{"level":"info","msg":"User: dummy, Request type PUT, Path: /test/dummy/csa/sq?/data_file","time":"2023-04-20T11:51:56Z"}
{"level":"debug","msg":"filepath contains disallowed characters: ?","time":"2023-04-20T11:51:56Z"}
{"level":"debug","msg":"not acceptable response","time":"2023-04-20T11:51:56Z"}
There are two debug messages but not identical, the first one gives the explicit problem and the one below the response status . I can combine them in to one but the way it is now the function above is reusable and in addition I think the debug messages are more informative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the function and moved the WriteHeader
in the main body.
proxy.go
Outdated
filepath, err := helper.FormatUploadFilePath(rawFilepath) | ||
if err != nil { | ||
log.Debugf(err.Error()) | ||
p.notAcceptableResponse(w, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p.notAcceptableResponse(w, r) | |
w.WriteHeader(http.StatusNotAcceptable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ec2d372
to
7146394
Compare
- check for improper filename characters - make filepaths os compatible - upon error return status 406
// Check for mixed "\" and "/" in filepath. Stop and throw an error if true so that | ||
// we do not end up with unintended folder structure when applying ReplaceAll below | ||
if strings.Contains(filePath, "\\") && strings.Contains(filePath, "/") { | ||
return filePath, fmt.Errorf("filepath contains mixed '\\' and '/' characters") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be unnecessary in the end, but it will require manual testing to validate since /
actually is a valid separator on windows.
This PR prevents potential filepath naming problems that may arise due to cross-platform incompatibilities.
The procedure implemented is as follows:
In case of a rejection,
proxy
returns a 406 error response to the client and prints debug logs with details on the disallowed characters found in the filepath. Testsuite is updated, too.The fix was tested for the case when
proxy
runs in linux and an s3 client (s3cmd, sda-cli) runs in either linux or windows. Not tested for mac but hopefully it behaves like linux ;-).P.S. following standup discussion, spaces in filenames are allowed (along with the majority of unicode).
Closes #370