Fix static mounts using relative paths and prevent traversal exploits#554
Merged
simonw merged 5 commits intosimonw:masterfrom Jul 11, 2019
abdusco:static_mount_fix
Merged
Fix static mounts using relative paths and prevent traversal exploits#554simonw merged 5 commits intosimonw:masterfrom abdusco:static_mount_fix
simonw merged 5 commits intosimonw:masterfrom
abdusco:static_mount_fix
Conversation
Since paths include a drive prefix like `C:` on Windows, splitting mount directive gives three segments, and python fails to unpack it into two variables.
Contributor
Author
|
I've also added another fix for using static mounts with absolute paths on Windows. |
Contributor
Author
|
I wanted to add a test for it too, but I've realized it's impossible to test a server process as we cannot get its exit code. # tests/test_cli.py
def test_static_mounts_on_windows():
if sys.platform != "win32":
return
runner = CliRunner()
result = runner.invoke(
cli, ["serve", "--static", r"s:C:\\"]
)
assert result.exit_code == 0 |
Owner
|
Thanks for this! The tests are failing for Python 3.5 right now which is strange. https://travis-ci.org/simonw/datasette/jobs/556272017 One failure looks like this: Maybe an exception was renamed between 3.5 and 3.6? |
Owner
|
Released as 0.29.1: https://datasette.readthedocs.io/en/latest/changelog.html#v0-29-1 |
simonw
pushed a commit
that referenced
this pull request
Nov 11, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While debugging why my static mounts using a relative path (
--static mystatic:rel/path/to/dir) not working, I noticed that the requests fail no matter what, returning 404 errors.The reason is that datasette tries to prevent traversal exploits by checking if the path is relative to its registered directory. This check fails when the mount is a relative directory, because
/abs/dir/fileobviously not underdir/file.datasette/datasette/utils/asgi.py
Lines 303 to 306 in 81fa8b6
This also has the consequence of returning any requested file, because when
/abs/dir/../../evil.fileresolvesaiofileshappily returns it to the client after it resolves the path itself. The solution is to make sure we're checking relativity of paths after they're fully resolved.I've implemented the mentioned changes and also updated the tests.