0001-web-Fix-an-open-redirect-in-StaticFileHandler.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. From ac79778c91bd9a4a92111f7e06d4b12674571113 Mon Sep 17 00:00:00 2001
  2. From: Ben Darnell <ben@bendarnell.com>
  3. Date: Sat, 13 May 2023 20:58:52 -0400
  4. Subject: [PATCH] web: Fix an open redirect in StaticFileHandler
  5. Under some configurations the default_filename redirect could be exploited
  6. to redirect to an attacker-controlled site. This change refuses to redirect
  7. to URLs that could be misinterpreted.
  8. A test case for the specific vulnerable configuration will follow after the
  9. patch has been available.
  10. Upstream: https://github.com/tornadoweb/tornado/commit/32ad07c54e607839273b4e1819c347f5c8976b2f
  11. [Thomas: backported to fix CVE-2023-28370]
  12. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  13. ---
  14. tornado/web.py | 9 +++++++++
  15. 1 file changed, 9 insertions(+)
  16. diff --git a/tornado/web.py b/tornado/web.py
  17. index cd6a81b4..05b571eb 100644
  18. --- a/tornado/web.py
  19. +++ b/tornado/web.py
  20. @@ -2806,6 +2806,15 @@ class StaticFileHandler(RequestHandler):
  21. # but there is some prefix to the path that was already
  22. # trimmed by the routing
  23. if not self.request.path.endswith("/"):
  24. + if self.request.path.startswith("//"):
  25. + # A redirect with two initial slashes is a "protocol-relative" URL.
  26. + # This means the next path segment is treated as a hostname instead
  27. + # of a part of the path, making this effectively an open redirect.
  28. + # Reject paths starting with two slashes to prevent this.
  29. + # This is only reachable under certain configurations.
  30. + raise HTTPError(
  31. + 403, "cannot redirect path with two initial slashes"
  32. + )
  33. self.redirect(self.request.path + "/", permanent=True)
  34. return None
  35. absolute_path = os.path.join(absolute_path, self.default_filename)
  36. --
  37. 2.41.0