Skip to content

Commit

Permalink
403 for static directory listing, closes #740
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 27, 2020
1 parent 25014ca commit 89c4ddd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions datasette/utils/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ async def inner_static(scope, receive, send):
except FileNotFoundError:
await asgi_send_html(send, "404", 404)
return
if full_path.is_dir():
await asgi_send_html(send, "403: Directory listing is not allowed", 403)
return
# Ensure full_path is within root_path to avoid weird "../" tricks
try:
full_path.relative_to(root_path)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ def test_static(config_dir_client):
assert "text/css" == response.headers["content-type"]


def test_static_directory_browsing_not_allowed(config_dir_client):
response = config_dir_client.get("/static/")
assert 403 == response.status
assert "403: Directory listing is not allowed" == response.text


def test_databases(config_dir_client):
response = config_dir_client.get("/-/databases.json")
assert 200 == response.status
Expand Down

0 comments on commit 89c4ddd

Please sign in to comment.