Skip to content

security: fix path traversal in StaticFileHandler#1285

Open
q1uf3ng wants to merge 2 commits into
google:masterfrom
q1uf3ng:fix/path-traversal-static-handler
Open

security: fix path traversal in StaticFileHandler#1285
q1uf3ng wants to merge 2 commits into
google:masterfrom
q1uf3ng:fix/path-traversal-static-handler

Conversation

@q1uf3ng
Copy link
Copy Markdown

@q1uf3ng q1uf3ng commented May 7, 2026

Summary

The custom StaticFileHandler in openhtf/output/servers/web_gui_server.py overrides Tornado's validate_absolute_path() to return the path without any validation, completely removing the built-in path traversal protection.

This allows requests such as GET /img/../../../../etc/passwd to read arbitrary files on the host filesystem.

Fix

  • Use os.path.abspath() in get_absolute_path() to resolve ../ sequences
  • Check the resolved path starts with the static root directory in validate_absolute_path()
  • Return 403 if the path escapes the root, 404 if the file doesn't exist

Reproduction

# With the current code, the following returns /etc/passwd contents:
curl --path-as-is "http://HOST:PORT/img/../../../../../../../../etc/passwd"

# Tornado's default StaticFileHandler correctly returns 403

The custom StaticFileHandler overrides validate_absolute_path() to
return the path without any validation, removing Tornado's built-in
path traversal protection. This allows requests like
GET /img/../../../../etc/passwd to read arbitrary files.

Restore path validation by using os.path.abspath() in
get_absolute_path() and checking the resolved path is within the
static root in validate_absolute_path().
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant