Repository navigation
Validates package root URIs - #10096
Conversation
This change validates the detected directory in VmServiceHandler before caching it or updating DTD, requiring that it: is a local file:// URI with no authority, query, fragment, or dot-segment traversal (. / ..), does not point or resolve (via symlinks) to the filesystem root or the user's home directory (HOME / USERPROFILE), and exists on disk and contains either pubspec.yaml or .dart_tool/package_config.json. It also extracts shared isValidLocalFileUri and isValidLocalFileUriString helpers in file_utils.dart (reused by ExtensionsManager and the extensions API handler) and adds unit and server API tests covering valid roots, invalid URI forms, filesystem/home root rejection, missing package markers, and end-to-end /api/notifyForVmServiceConnection handling. Makes progress towards: * flutter/dash-devexp-internal#88 * flutter/dash-devexp-internal#93
There was a problem hiding this comment.
Code Review
This pull request introduces package root validation in VmServiceHandler before caching or updating Dart Tooling Daemon (DTD) workspace roots, utilizing new local file URI validation helpers to prevent path traversal and reject invalid roots (such as the filesystem root or user home directory). The review feedback highlights a critical logical issue where validating the package root during disconnect flows can prevent proper cleanup of DTD workspace roots if the directory or its package markers were deleted during the session. It is recommended to skip validation when connected is false to ensure stale roots are successfully removed.
… validation. * Reject encoded slashes (`/` / `%2f`) in `isValidLocalFileUri` path segments and validate raw `root` strings with `isValidLocalFileUriString` before `Uri.parse` in `detectRootPackageForVmService`, with new `%2f` test coverage. * Simplify `_validateRootPackageUri` to check `dir.existsSync()` first, resolve symlinks once (failing closed on `FileSystemException`), and compare only the resolved path against the filesystem root and resolved home directory. * Remove duplicate `_validateRootPackageUri` validation from `updateDtdWorkspaceRoots` and move its rejection tests to standalone `isValidRootPackageUri` unit tests without DTD. * Extract the repeated `runWithRetry` polling blocks in `detectRootPackageForVmService` tests into a shared `detectRootWithRetry` helper. * Update invalid-URI error messages in `_vm_service.dart` and `_devtools_extensions.dart`, add doc comments to `VmServiceHandler` constants, remove redundant `@visibleForTesting`, and document the new helpers and stricter URI checks in `packages/devtools_shared/CHANGELOG.md`.
- Move `_invalidLocalFileUriMessage` to a library-private constant in `server_api.dart` and reuse it in `_devtools_extensions.dart` and `_vm_service.dart` so invalid local file URI error messages stay in sync. - Expose `VmServiceHandler.validateRootPackageUri` as `@visibleForTesting`, remove `isValidRootPackageUri`, and assert on specific rejection reason messages in `general_api_test.dart`. - Trim the invalid local file URI test in `general_api_test.dart` to a single query URI case since `file_utils_test.dart` already covers all invalid URI components. - Restore plain `Uri.parse` fixtures in `updateDtdWorkspaceRoots` tests and remove the unnecessary temporary directory setup and deleted-directory test. - Document `detectRootWithRetry`'s default `isReady` behavior and simplify its `isReady` callbacks to use null-aware `contains`.
…e-roots # Conflicts: # packages/devtools_shared/CHANGELOG.md # packages/devtools_shared/lib/src/server/handlers/_devtools_extensions.dart # packages/devtools_shared/lib/src/server/handlers/_vm_service.dart # packages/devtools_shared/test/server/general_api_test.dart
|
@kenzieschmoll @bkonyi this is ready for another look |
kenzieschmoll
left a comment
There was a problem hiding this comment.
LGTM, though I'd recommend waiting for @bkonyi's approval before landing.
This change validates and resolves symlinks for the detected directory in
VmServiceHandlerbefore caching the resolved URI or updating DTD, requiring that it:file://URI with no authority, query, fragment, or null bytes that converts cleanly to a local file pathHOME/USERPROFILE), or an ancestor of it, and exists on diskpubspec.yamlor.dart_tool/package_config.json.It also extracts shared
isValidLocalFileUri,isValidLocalFileUriString, andinvalidLocalFileUriMessagehelpers infile_utils.dart(reused byExtensionsManagerand the extensions API handler) and adds unit and server API tests covering valid and symlink-resolved roots, invalid URI forms, filesystem/home/home-ancestor root rejection, missing package markers, and end-to-end/api/notifyForVmServiceConnectionhandling.Makes progress towards: