Skip to content

Quote package names before they reach the device shell - #75

Closed
EmberIdle wants to merge 1 commit into
doudar:mainfrom
EmberIdle:fix/quote-shell-package-names
Closed

EmberIdle wants to merge 1 commit into
doudar:mainfrom
EmberIdle:fix/quote-shell-package-names

Conversation

@EmberIdle

Copy link
Copy Markdown

What changed

adb shell joins its arguments into a single command line that the device's sh parses, so a package name containing shell metacharacters (;, $(...), backticks, spaces) would run arbitrary commands on the device. The file manager already quotes its arguments with quoteShellArg, but the app actions did not.

  • launchPackage, forceStopPackage, clearPackageData, uninstallPackage (mobile path), uninstallPackageUser0, openAppSettings and _getAppLabel now pass the package name through quoteShellArg.
  • setDefaultLauncher quotes the launcher component and enableWirelessDebugging quotes the tile list it reads back from the device, since both come from device output rather than the catalog.
  • New isValidAndroidPackageName (lib/services/android_package_name.dart) checks the Android application ID grammar. The package actions refuse and log an error for anything that fails it, as defence in depth ahead of the quoting.

No behaviour change for well-formed package names: pm clear com.example.app becomes pm clear 'com.example.app', which the device shell reads identically. This is the same quoting the file manager has used on Windows, macOS and Linux.

Why

Package names reach these calls from pm list packages output, the catalog, and the launcher list. A hostile or malformed source should not be able to execute shell on the bike.

How it was verified

  • dart format, flutter analyze, flutter test (121 tests) all pass on Flutter 3.44.4.
  • New tests in test/adb_service_test.dart capture the exact argument lists sent to runAdbCommand and assert the quoted forms for launch, force stop, clear data, uninstall for user 0, app settings, launcher component and tile list. A further test sends com.example.app; rm -rf /sdcard through every package action and asserts that no command is run and each refusal is logged.
  • test/android_package_name_test.dart covers accepted and rejected names.

Not verified on a Peloton: I have no hardware. The quoting form is identical to what the file manager already sends, so an on-device sanity check of Launch, Force stop and Clear data from the Installed App Manager would be welcome.

🤖 Generated with Claude Code

adb shell joins its arguments into one command line that the device's sh
parses, so a package name containing shell metacharacters could run
arbitrary commands on the device. The file manager already quotes its
arguments with quoteShellArg; the app actions (launch, force stop, clear
data, uninstall, app settings, dumpsys label lookup), the launcher
component and the quick-settings tile list did not.

Every interpolated package name is now quoted, and package names are
also validated against the Android application ID grammar before any
command is built, so a malformed name is logged and refused instead of
sent.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@EmberIdle

Copy link
Copy Markdown
Author

Closing for now; will reopen when the batch of fixes is ready for review.

@EmberIdle EmberIdle closed this Nov 13, 2026
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.

2 participants