Summary
CodeWhale's run_tests tool automatically runs cargo test in a repository workspace without asking the user for confirmation, effectively treating the repository's test suite as trusted code.
In a malicious or untrusted repository, test binaries, build scripts, or procedural macros can execute arbitrary shell commands, steal secrets, or establish persistence with zero user approval, especially when combined with auto-loaded prompts that encourage running tests on startup.
Affected context
This issue affects CodeWhale installations using versions 0.3.0 through 0.8.23 where:
- The
run_teststool is available and configured withApprovalRequirement::Auto. - The agent is used against repositories that may contain untrusted or third-party code.
- The environment in which CodeWhale runs has access to developer credentials, SSH keys, API tokens, or other sensitive data.
The risk is heightened when AGENTS.md or similar configuration files are auto-loaded into the system prompt and instruct the agent to proactively invoke run_tests at session start, turning test execution into an implicit background action.
Exploit preconditions
- Attack surface: Local developer or CI environment where CodeWhale operates.
- Required access: Ability to supply or influence the repository contents that CodeWhale is pointed at (e.g., cloning a malicious repo, opening an untrusted pull request, or editing AGENTS.md).
- Trigger point: Invocation of the
run_teststool, which in turn runscargo testin the workspace with no approval prompt. - Why exploitation is possible:
cargo testcompiles and executes arbitrary Rust code, including test functions,build.rsscripts, and procedural macros.- CodeWhale treats test execution as a safe, auto-approved action, collapsing the boundary between "viewing code" and "running code".
- AGENTS.md can nudge or instruct the agent to run tests automatically, so execution may occur without explicit user intent at that moment.
Why this happens
The root cause is a design-level trust boundary failure: CodeWhale's run_tests tool assumes that project test code is safe to execute and configures ApprovalRequirement::Auto, eliminating human-in-the-loop confirmation for running cargo test.
This maps to CWE-94: Improper Control of Generation of Code ('Code Injection') in the sense that untrusted repository content is treated as trustworthy executable logic. The tooling effectively allows external code (tests, build scripts, macros) to be introduced via repository files and then compiled and executed automatically, without proper validation, sandboxing, or explicit user consent. The problem is not a single input parsing bug, but the unsafe pattern of granting arbitrary project code an execution path under an "auto-approve" policy.
Potential impact
- Local execution of arbitrary OS commands under the user's account.
- Exfiltration of SSH keys, API tokens, cloud credentials, or configuration files accessible to the environment.
- Tampering with local source trees, Git metadata, or developer tooling configuration.
- Establishment of persistence via modified shell profiles, editor configs, or scheduled tasks.
- Abuse of the developer's machine to pivot into internal networks or CI environments.
General mitigation guidance
Effective mitigation focuses on restoring a clear and conservative execution boundary between "reading code" and "running code":
- Require explicit user approval before executing any test, build, or arbitrary command in a repository, especially for
cargo test-like operations that compile and run project code. - Treat all repository content as untrusted by default; adopt least privilege when invoking compilers, test runners, or build systems.
- Provide configuration options or policies to disable or strictly restrict auto-execution behaviors (including actions suggested by AGENTS.md or similar prompt files).
- Where execution of untrusted code is necessary, prefer sandboxed or containerized environments with constrained permissions and limited access to host secrets.
- Encourage workflows where sensitive credentials are not directly exposed to tools that might automatically execute repository code.
How teams detect issues like this
Detection centers on identifying unsafe auto-execution pathways and monitoring how tools treat repository content:
- Review agent and tooling code for patterns where external project files can trigger automatic command execution, particularly test runners or build steps configured with auto-approval.
- Use static analysis or policy checks to flag code paths that run shell commands, compilers, or test frameworks without explicit user confirmation or without trust checks on the source.
- In deployment and CI configurations, instrument logging around test and build invocations to detect unexpected
cargo testruns or similar commands initiated by agents. - Incorporate security reviews into the design of developer-assistance tools, focusing on where they cross from "analyzing" to "executing" project artifacts.

