Fix: opencode auto-memory-update leaks full transcript via process argv (ps/procfs) - #152
Closed
priyamkarn wants to merge 3 commits into
Closed
priyamkarn wants to merge 3 commits into
priyamkarn wants to merge 3 commits into
Conversation
…ss argv runOpenCodeAgent passed the sensitive prompt (which embeds the full session transcript, including anything not yet caught by redaction) as a literal '-p' command-line argument. Process arguments are visible to other local users via ps/proc for the lifetime of the process -- and this runs automatically, unattended, on every background auto-memory-update, not just when a human runs a CLI command. codex.ts already avoids this via stdin and openhands.ts via a task file; opencode's CLI has no stdin/file option for its prompt though (confirmed against its docs), only a literal -p value, so the fix writes the prompt to a file inside the caller's private (mode 0700) run directory and passes only a short file-reference wrapper via argv instead. Adds a regression test that stubs the opencode binary, captures its real argv, and asserts the sensitive content never appears there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
runOpenCodeAgent(libs/agent-runner/opencode.ts) passed the full working-memory-updateprompt -- which embeds the entire session transcript -- as a literal
-p <text>command-line argument to the
opencodebinary:Process arguments are visible to other local users via
ps aux//proc/<pid>/cmdlinefor as long as the process runs. This isn't a one-off CLI invocation -- it runs
automatically and unattended via the background hook worker on every coding session
(libs/hooks/worker.ts), so the exposure window recurs continuously.
Why opencode specifically
I checked opencode's actual CLI docs before assuming "just switch to stdin" would work:
its prompt argument has no stdin or file-path option, only a literal
-pvalue. So thisneeded a different fix than the other two platforms use.
Fix
Write the prompt to a file (
opencode-task-prompt.md) inside the same private rundirectory
worker.tsalready creates viamkdtempSync(mode 0700 per POSIX), and passonly a short, non-sensitive wrapper referencing that file path as the
-pvalue. Theagent reads its real instructions itself via its own file tool -- same effective prompt
content, just relocated out of argv.
Confirmed
runOpenCodeAgenthas exactly one call path in the codebase (viaworker.ts),so this directory-privacy assumption holds everywhere it's actually used today.
Tests
scripts/check-opencode-prompt-file.jsstubs a fakeopencodebinary that records itsown argv, runs the real built
runOpenCodeAgentagainst it, and asserts: the sensitivemarker never appears in argv, the
-pvalue references the prompt file, and the realprompt content was actually written there. Wired into
npm test.