Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent directory traversal in the dev server #2604

Merged
merged 1 commit into from Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion mkdocs/livereload/__init__.py
Expand Up @@ -4,6 +4,7 @@
import mimetypes
import os
import os.path
import posixpath
import re
import socketserver
import threading
Expand Down Expand Up @@ -183,9 +184,11 @@ def condition():
if path == "/js/livereload.js":
file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "livereload.js")
elif path.startswith(self.mount_path):
rel_file_path = path[len(self.mount_path):].lstrip("/")
rel_file_path = path[len(self.mount_path):]
if path.endswith("/"):
rel_file_path += "index.html"
# Prevent directory traversal - normalize the path.
rel_file_path = posixpath.normpath("/" + rel_file_path).lstrip("/")
file_path = os.path.join(self.root, rel_file_path)
elif path == "/":
start_response("302 Found", [("Location", self.mount_path)])
Expand Down