/

CVE-2026-30308

Severity:

CRITICAL RISK

(9.8)

Code Injection via Prompt Injection in HAI Build Code

CVE-2026-30308

Analyzed

Vulnerability type

Category:

Code Injection via Prompt Injection

CWE:

CWE-94

Impact:

Arbitrary Command Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

HAI Build Code Generator's automatic terminal command execution feature can be subverted through prompt injection, causing the model to misclassify malicious commands as "safe."

By wrapping destructive commands in adversarial prompts, an attacker may bypass user approval and achieve arbitrary command execution on the host system.

Affected context

This vulnerability manifests when HAI Build Code Generator is configured to auto-run shell or terminal commands suggested by an AI model.

The risk is highest when:

  • The "Execute safe commands" mode is enabled
  • Model outputs are treated as authoritative on whether a command is safe
  • User approval is skipped based on the model's own safety judgment
  • The environment allows those commands to run with meaningful privileges on the underlying system

Exploit preconditions

  • Attack surface: Any channel where untrusted text can influence the model's code or command suggestions (e.g., project files, comments, issue descriptions, external documentation, or shared prompts).
  • Required access: Ability to inject or control text consumed by the model during generation (no direct shell access needed).
  • Trigger point: The model generates terminal commands wrapped in a prompt-injection template and labels them as "safe," causing the tool to auto-execute them.
  • Why exploitation is possible: The safety decision is delegated to the same model that is being attacked. The system lacks a robust separation between:
  • Instruction-following behavior (which can be manipulated), and
  • Security policy enforcement (which should be deterministic and external to the model).

Why this happens

The underlying issue is a design flaw where security-critical decisions about command execution are delegated to an LLM that is easily influenced by prompt injection.

Instead of enforcing an external, rule-based allowlist or explicit user approval, the system trusts the model's judgment of whether a command is "safe."

Prompt injection—untrusted text that instructs the model to reinterpret or override its prior safety instructions—can cause the model to re-label arbitrary commands as benign.

This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), since user-controlled or untrusted content effectively controls what commands (code) are generated and executed, without sufficient validation or isolation.

Potential impact

  • Execution of arbitrary shell commands on the developer's machine or CI environment
  • Modification, exfiltration, or deletion of source code and configuration files
  • Installation of malware, backdoors, or data stealers on the host system
  • Compromise of credentials (API keys, SSH keys, tokens) accessible from the environment
  • Lateral movement to connected services (e.g., repositories, artifact registries, cloud accounts)

General mitigation guidance

Effective mitigation centers on removing the model from the trust boundary for command execution decisions and strictly constraining what can run:

  • Eliminate model-driven safety gating: Do not rely on the model's self-assessment of whether a command is safe; use deterministic policies instead.
  • Use explicit user approval by default: Require human confirmation for all non-trivial commands, especially those that write to disk, modify dependencies, or touch system configuration.
  • Apply strict command allowlisting: Limit auto-execution to a narrow set of predefined, parameterized commands with bounded effects (e.g., read-only queries, formatters, linters).
  • Constrain execution environment: Run auto-executed commands in a sandboxed context (containers, VMs, or restricted users) with minimal filesystem and network privileges.
  • Reduce trust in input text: Treat all model input (files, comments, external docs) as untrusted, and avoid linking it directly to elevated actions without separate validation.
  • Separate safety policy from model prompts: Encode safety rules in code/configuration rather than relying on prompt instructions that the model can be persuaded to ignore.

How teams detect issues like this

Detection should focus on identifying both risky patterns in the product's design and abnormal command behavior at runtime:

  • Design and code review signals:
  • Any logic where an LLM output directly controls command execution or safety classification.
  • References to "safe commands" based solely on model evaluation without a hard-coded policy.
  • Absence of allowlists or explicit user confirmation for commands that can modify system state.
  • Static analysis and policy checks:
  • Rules that flag flows from "LLM output" or "model response" sinks into command execution APIs (e.g., exec, spawn, shell wrappers).
  • CI policies that prevent merging changes introducing new automatic execution paths without reviews.
  • Runtime and operational monitoring:
  • Logging all auto-executed commands, their sources, and whether they were user-approved.
  • Alerting on sensitive operations triggered via auto-execution (e.g., package manager calls, file deletion, network exfiltration utilities).
  • Periodic review of command logs for anomalous or developer-atypical patterns.
  • Automated review tools:
  • Use application security scanners or governance tools tuned to detect "LLM-to-shell" flows and missing enforcement steps between model output and execution.

Sources

SourceLink
github.comgithub.com/Secsys-FDU/LLM-Tool-Calling-CVEs/issues/10
github.comgithub.com/presidio-oss/hai-build

Frequently asked

questions

Yes, in the sense that an attacker does not need direct access to the victim's shell. If they can control or influence text that the model reads—such as repository content, documentation, or shared prompts—they may cause HAI Build Code Generator to generate and auto-execute malicious commands.

The attacker needs the ability to inject content into a channel the model consumes (for example, a pull request, ticket, README, or shared prompt). They do not need local code execution initially; the vulnerable auto-execution feature grants that when it trusts the model's "safe" classification.

Decouple security from the model by:

  • Removing or severely restricting auto-execution,
  • Requiring explicit, informed user consent for impactful commands, and
  • Enforcing a strict, code-level allowlist of what can be run automatically, independent of model judgment.

Treat LLMs as untrusted advisors, not decision-makers for high-risk actions. Place deterministic controls between model output and side-effectful operations (file writes, network calls, command execution), constrain execution environments, and adopt security reviews specifically focused on LLM-to-action pipelines and prompt injection resilience.

Find out what's already
exploitable in your codebase.