Skip to content

Reject absolute paths in devToolsFileFromPath#9844

Open
adilburaksen wants to merge 2 commits into
flutter:masterfrom
adilburaksen:fix-devtools-file-read-absolute-path
Open

Reject absolute paths in devToolsFileFromPath#9844
adilburaksen wants to merge 2 commits into
flutter:masterfrom
adilburaksen:fix-devtools-file-read-absolute-path

Conversation

@adilburaksen
Copy link
Copy Markdown

Problem

LocalFileSystem.devToolsFileFromPath() is documented as "Only files within ~/.flutter-devtools/ can be accessed" and enforces that with pathFromDevToolsDir.contains('..'). However it does not reject absolute paths. path.join(devToolsDir(), pathFromDevToolsDir) discards the base directory when the second argument is absolute, so an absolute pathFromDevToolsDir (which contains no ..) escapes the intended directory.

This is reachable via getBaseAppSizeFile/getTestAppSizeFile (handlers/_app_size.dart, appSizeBase/appSizeTest parameters) -> devToolsFileAsJson -> devToolsFileFromPath, allowing a caller to read an arbitrary .json file on the machine rather than only files under ~/.flutter-devtools/.

Fix

  • Reject absolute paths (path.isAbsolute) in addition to the existing .. check.
  • Add a defense-in-depth path.isWithin(devToolsDir, resolvedPath) containment check on the resolved path.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves path validation in devToolsFileFromPath to prevent arbitrary file reads by rejecting absolute paths and ensuring the resolved path is within the DevTools directory. The reviewer recommends adding automated tests to verify these security-critical checks and prevent regressions.

Comment on lines +48 to +49
if (pathFromDevToolsDir.contains('..') ||
path.isAbsolute(pathFromDevToolsDir)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

[MUST-FIX] Please add automated tests to verify these security-critical path validation checks.\n\nSince this change fixes a security vulnerability (arbitrary file read via path traversal/absolute paths), it is crucial to have automated tests to prevent regressions.\n\nThe tests should cover:\n- Valid relative paths (should be allowed and return the file if it exists).\n- Absolute paths (should be rejected).\n- Path traversal attempts using .. (should be rejected).\n- Root-relative paths (e.g., starting with / or \\ on Windows, which might bypass path.isAbsolute but should be caught by path.isWithin).

References
  1. All changes should include automated tests to ensure correctness and prevent regressions. (link)

@bkonyi bkonyi removed their request for review June 1, 2026 18:54
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