fix(web-api): percent-decode before path-splitting #560
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR patches a path traversal vulnerability.
I would like to thank the IT department at McGill's School of Computer Science for noticing this bug, and Max Kopinsky for working on the patch with me.
I did not separately report the bug since the fix is quite simple.
Description
Without this patch, try visiting http://localhost:8080/css/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc/passwd assuming learn-ocaml is running on port 8080. Notice that this successfully downloads the file
/etc/passwd
. There is some code present in learn-ocaml that is supposed to prevent this, namely the functionsanitise_path
, but since the path-splitting operation is performed before the percent-decoding, it is possible to smuggle slashes deeper into the system by simply percent-encoding them as%2f
.Checklist
Note to maintainers
Close #…
if a related issue exists.