Skip to content

fix: mask typed text in child-process errors - #70

Draft
cryptotavares wants to merge 2 commits into
mainfrom
cryptotavares/mask-typed-text-in-errors
Draft

cryptotavares wants to merge 2 commits into
mainfrom
cryptotavares/mask-typed-text-in-errors

Conversation

@cryptotavares

Copy link
Copy Markdown
Contributor

Summary: A failed typeText or clipboard write no longer puts the text — often a wallet password — into the error. The text and every form it takes on argv appear as •••.

Problem

execStrict builds its error from the command line and stderr. iOS sends idb ui text <text> and Android sends adb shell input text <text> through it. When the command fails, the error contains the typed text. That error reaches the CLI JSON, the agent transcript and the daemon log.

Command failed: idb ui text hunter2 x --udid AAAA1111-BBBB-CCCC-DDDD-EEEE2222FFFF
Exit code: 1
stderr: ...

Solution

Callers mark the text as a secret with execStrict(cmd, args, { secret }). execStrict replaces each secret, and every form the caller passes for it, in the failure message.

flowchart TD
    A["typeText(text) or setClipboard(text)"] --> B["execStrict with secret: raw text and argv forms"]
    B --> C{"child exit 0?"}
    C -->|yes| D["Return stdout. Typing is unchanged."]
    C -->|no| E["maskSecrets: replace each form in the command line and stderr"]
    E --> F["Throw. The text never appears in the error."]

    classDef new fill:#fff3cd,stroke:#d39e00
    classDef stop fill:#f8d7da,stroke:#c82333
    class B,E new
    class F stop
Loading

Yellow boxes are new. Red boxes stop the call.

What changes

The masked forms are the raw text, the escaped Android argv element and the base64 clipboard argument.

Condition Before After
iOS typeText fails ui text hunter2 x in the error ui text •••
Android typeText fails input text hunter2%sx in the error input text •••
Android clipboard set fails textB64 <base64> in the error textB64 •••
Any of the above succeeds Text is typed or copied No change

Decisions for reviewers

Decision Reason
secret accepts a string or a list of strings execFile keeps arguments separate, but the error joins argv into one line. Android escapes spaces and metacharacters, and the clipboard argument is base64. The caller passes each form that appears on argv.
Keep the mask in exec.ts and let each backend mark the value One function builds every child-process failure message. The backends do not repeat the masking.
Leave iOS setClipboard unchanged xcrun simctl pbcopy reads the text from stdin. The text never reaches argv or the error.
Do not mask returned stdout on success Typing must behave exactly as before when it succeeds.

Review guide

Read the files in this order:

# File What to check
1 src/utils/exec.ts ExecOptions.secret, maskSecrets, and the failure message in execStrict
2 src/backends/idb-backend.ts #execStrict forwards the secret; iOS typeText passes the raw text
3 src/backends/adb-backend.ts #adb forwards the secret; Android typeText passes raw and escaped text; setClipboard passes raw and base64
4 src/backends/android-instrumentation/clipboard.ts encodeClipboardText is the only base64 encoder
5 *.test.ts The failing-typeText tests use the real execStrict with a fake execFile
Testing
  • yarn build, yarn lint and yarn test pass.
  • yarn test: 38 files, 996 passed, 6 skipped, no type errors. Coverage is above the floors.
  • The iOS and Android tests fail typeText('hunter2 x') through the real execStrict and a fake execFile whose stderr echoes the text. They assert that no hunter2 remains and that ••• is present.
  • Mutation check. Returning the input unchanged from maskSecrets makes both masking tests fail.
Known gap
  • The device_type success response still echoes the text (Typed "<text>" (...)). This PR only changes failure paths.

Mark the text sent by the iOS and Android typeText and by the Android
clipboard instrumentation as a secret, so a failed child process cannot
echo it through the command line or stderr.

This branch has not been deployed

No deployments
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