Skip to content

Commit 32ad07c

Browse files
committed
web: Fix an open redirect in StaticFileHandler
Under some configurations the default_filename redirect could be exploited to redirect to an attacker-controlled site. This change refuses to redirect to URLs that could be misinterpreted. A test case for the specific vulnerable configuration will follow after the patch has been available.
1 parent e0fa53e commit 32ad07c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tornado/web.py

+9
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,15 @@ def validate_absolute_path(self, root: str, absolute_path: str) -> Optional[str]
28792879
# but there is some prefix to the path that was already
28802880
# trimmed by the routing
28812881
if not self.request.path.endswith("/"):
2882+
if self.request.path.startswith("//"):
2883+
# A redirect with two initial slashes is a "protocol-relative" URL.
2884+
# This means the next path segment is treated as a hostname instead
2885+
# of a part of the path, making this effectively an open redirect.
2886+
# Reject paths starting with two slashes to prevent this.
2887+
# This is only reachable under certain configurations.
2888+
raise HTTPError(
2889+
403, "cannot redirect path with two initial slashes"
2890+
)
28822891
self.redirect(self.request.path + "/", permanent=True)
28832892
return None
28842893
absolute_path = os.path.join(absolute_path, self.default_filename)

0 commit comments

Comments
 (0)