Skip to content

[WRONG BRANCH] fix(codebuddy): stage system prompts in a private file instead of process argv - #479

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/investigate-codebuddy-vulnerability-in-repository
Draft

[WRONG BRANCH] fix(codebuddy): stage system prompts in a private file instead of process argv#479
luvs01 wants to merge 1 commit into
mainfrom
codex/investigate-codebuddy-vulnerability-in-repository

Conversation

@luvs01

@luvs01 luvs01 commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The CodeBuddy adapter passed request-derived system/developer prompt text on the child process command line, exposing potentially sensitive prompt content to local process-listing and /proc/<pid>/cmdline inspection.

Description

  • Stop embedding prompt text into argv and instead stage the folded system+developer prompt in an exclusive temp file and pass its path to the CLI via --system-prompt-file from buildArgs.
  • Create the staging file with mkdtemp + writeFile(..., { mode: 0o600, flag: "wx" }), fail closed with a clear error if staging fails, and always remove the private temp directory after the turn completes.
  • Wire the new systemPromptFile parameter through createCodeBuddyAdapter / runTurn so runCodingAgentTurn receives args that reference the file rather than the prompt text.
  • Add regression tests in tests/providers/codebuddy-adapter.test.ts that assert the staged file contains the prompt, that the child argv does not contain prompt text, that file permissions are restrictive on Unix, and that the file is deleted after the turn.

Testing

  • Ran bun test tests/providers/codebuddy-adapter.test.ts and the CodeBuddy-focused suite passed (23 tests, 0 failures).
  • Ran bun run typecheck and bun run privacy:scan, both of which completed successfully.
  • Ran a broader bun run test; the run showed many passing tests but ultimately aborted due to a parallel-worker panic in this environment unrelated to the CodeBuddy change; the focused CodeBuddy tests remained green.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T02:42:16.871149Z 5a9cd6b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 307d3445-d9d7-42eb-b966-e0884aabc4cf


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a9cd6b7db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (effort) args.push("--effort", effort);
const system = buildSystemPrompt(parsed);
if (system) args.push("--append-system-prompt", system);
if (systemPromptFile) args.push("--system-prompt-file", systemPromptFile);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use the append-file flag to preserve the vendor prompt

For every turn containing a system or developer prompt, this changes the previous append behavior into replacement behavior: the Claude-compatible CLI distinguishes --system-prompt-file, which replaces its default system prompt, from --append-system-prompt-file, which appends file contents (CLI flag reference). Replacing the vendor prompt can remove the CLI's baseline behavioral and protocol instructions, so pass the staged file through the append-file variant instead.

Useful? React with 👍 / 👎.

Comment on lines +83 to +87
if (system) {
try {
promptDir = await mkdtemp(join(tmpdir(), "ocx-codebuddy-prompt-"));
promptFile = join(promptDir, "system-prompt.txt");
await writeFile(promptFile, system, { encoding: "utf8", mode: 0o600, flag: "wx" });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stage the prompt only after turn preflight

When the temporary directory is unavailable or unwritable, a request with a system prompt now emits system_prompt_staging_failed before runCodingAgentTurn can perform its pre-abort, canonical-destination, credential, or CLI checks. Consequently, even an already-cancelled request or invalid provider configuration gets the wrong error and unnecessarily writes request-derived content to disk; move staging into a post-preflight callback or perform it after those checks.

AGENTS.md reference: src/AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Comment on lines +113 to +114
} finally {
if (promptDir) await rm(promptDir, { recursive: true, force: true }).catch(() => {});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry or report failures that leave the prompt file behind

If recursive removal encounters a transient EPERM or EBUSY—notably on Windows—the empty catch silently leaves the plaintext system/developer prompt in the temporary directory indefinitely. Since this change's privacy guarantee depends on deleting that file after the child exits, use bounded removal retries and retain a cleanup mechanism or diagnostic when deletion still fails rather than discarding the error.

AGENTS.md reference: src/AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 10, 2026
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(codebuddy): stage system prompts in a private file instead of process argv [WRONG BRANCH] fix(codebuddy): stage system prompts in a private file instead of process argv Sep 10, 2026
@github-actions
github-actions Bot marked this pull request as draft September 10, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant