Skip to content

Security: Path traversal risk in Blueprint.open_resource - #5982

Closed
barttran2k wants to merge 1 commit into
pallets:mainfrom
barttran2k:contribai/fix/security/path-traversal-risk-in-blueprint-open-re
Closed

barttran2k wants to merge 1 commit into
pallets:mainfrom
barttran2k:contribai/fix/security/path-traversal-risk-in-blueprint-open-re

Conversation

@barttran2k

Copy link
Copy Markdown

Problem

The open_resource method joins the user-provided 'resource' parameter with root_path using os.path.join without sanitizing for path traversal sequences (e.g., '../'). If a developer passes user-controlled input to this method, it could allow reading arbitrary files on the filesystem.

Severity: low
File: src/flask/blueprints.py

Solution

Add path traversal validation by resolving the final path and checking it is still within root_path: resolved = os.path.realpath(path); if not resolved.startswith(os.path.realpath(self.root_path)): raise ValueError('Path traversal detected').

Changes

  • src/flask/blueprints.py (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

The open_resource method joins the user-provided 'resource' parameter with root_path using os.path.join without sanitizing for path traversal sequences (e.g., '../'). If a developer passes user-controlled input to this method, it could allow reading arbitrary files on the filesystem.

Affected files: blueprints.py

Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
@davidism

davidism commented Apr 7, 2026

Copy link
Copy Markdown
Member

This is not how to report a security issue. It's also not a security issue. Do not rely on output generated by LLMs, understand the code yourself before working on or submitting anything to any project.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants