Skip to content

fix(controller): validate ADB shell commands to close arbitrary-shell (S4)#28

Merged
luisguzman-adfa merged 1 commit into
mainfrom
fix/phase1-security-s4-adb-command
Jun 23, 2026
Merged

fix(controller): validate ADB shell commands to close arbitrary-shell (S4)#28
luisguzman-adfa merged 1 commit into
mainfrom
fix/phase1-security-s4-adb-command

Conversation

@luisguzman-adfa

Copy link
Copy Markdown
Collaborator

Summary

Phase 1 (security hardening). IIABAdbManager.executeCommand ran openStream("shell:" + command) — an on-device shell over ADB — with no validation. Today's callers pass fixed commands, but the method accepts any string, so a value with shell metacharacters (; | & $ ( ) < >, backticks, quotes, newlines) could chain or substitute extra commands run with ADB privileges. Tech-debt item S4.

Changes

  • adb/domain/AdbShellCommand (new, pure JVM): isSafe(command) rejects shell control / substitution / redirection / quote characters and control chars, so only a single self-contained command can run. Unit-tested (AdbShellCommandTest).
  • IIABAdbManager.executeCommand: validates and fails closed (logs + does not open the shell: stream) on an unsafe command. The two legitimate settings put global … / device_config put … calls are unaffected.

Design note (per discussion)

We chose metacharacter rejection over an exact command allowlist: ADB commands legitimately grow with new features, so an allowlist would be brittle, whereas rejecting ; | & $ \ ( ) < > ' " \+ CR/LF/control neutralizes command-chaining/substitution while allowing any normal single command. The othershell: calls in the class (top, settings get, dumpsys`) are fixed literals and were not the vector.

Testing

AdbShellCommandTest (pure JVM, CI testDebugUnitTest gate): accepts the two real app commands; rejects chaining, substitution, redirection, quotes/escape, newlines, empty/null. Logic also verified out of band (16 cases).

With S4 done, the only remaining Phase 1 item is F15 (cleartext OTA APK).

… (S4)

IIABAdbManager.executeCommand ran openStream("shell:" + command) — an
on-device shell over ADB — with no validation. The current callers pass fixed
commands, but the method accepts any string, so a value containing shell
metacharacters (; | & $ ( ) < >, backticks, quotes, newlines) could chain or
substitute extra commands run with ADB privileges (tech-debt S4).

- domain: new pure AdbShellCommand.isSafe(command) — rejects shell
  control/substitution/redirection/quote characters and control chars so only a
  single self-contained command can run. Pure JVM, unit-tested
  (AdbShellCommandTest).
- IIABAdbManager.executeCommand fails closed (logs + does not open the stream)
  on an unsafe command. The two legitimate settings/device_config calls are
  unaffected.
- Docs: CLAUDE.md design map + TECH_DEBT_PLAN progress log (S4 done; only F15
  remains in Phase 1).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@luisguzman-adfa luisguzman-adfa merged commit 07f24f1 into main Jun 23, 2026
1 check passed
@luisguzman-adfa luisguzman-adfa deleted the fix/phase1-security-s4-adb-command branch June 23, 2026 15:41
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