Heuristic:0xNyk Council of high intelligence Heredoc Prompt Injection Guard
| Knowledge Sources | |
|---|---|
| Domains | Security, CLI_Integration, Multi_Model_Systems |
| Last Updated | 2026-10-20 00:00 GMT |
Overview
Use a quoted heredoc (`<<'EOF'`) to write prompt text to a temp file, then pass it via `$(cat "$file")` — never inline prompt text in the command string, which would allow shell metacharacter injection from user-supplied problem text.
Description
The Heredoc Prompt Injection Guard is a security pattern used by all external provider dispatch methods in the Council of High Intelligence. When the coordinator dispatches a council member to an external CLI (`codex exec`, `gemini`, `ollama run`, `cursor-agent`) or an OpenAI-compatible API (`curl`), the prompt text — which contains user-supplied problem statements and potentially adversarial content — must never be inlined directly into the shell command string.
The problem: if prompt text containing `"`, backticks, or `$(…)` is interpolated into a command string, an attacker can craft a problem statement that breaks out of the string and executes arbitrary shell commands. For example, a problem like `Should we use "; rm -rf /; #"` would be catastrophic if naively interpolated.
The solution: write the prompt to a temp file using a quoted heredoc (`<<'COUNCIL_PROMPT_EOF'`), where the single-quoted delimiter prevents all variable expansion and command substitution within the heredoc body. Then pass the file content via `"$(cat "$PROMPT_FILE")"` as a single quoted argument to the provider command. The temp file is removed immediately after use.
Usage
Use this heuristic whenever dispatching a council member to an external CLI or API via the Bash tool. This is a hard protocol constraint — the SKILL.md dispatch templates are explicitly designed around this pattern and warn against inlining:
> "Never inline the prompt directly into the command string — problem text containing `"`, `` ` ``, or `$(…)` would break the shell or inject commands."
Applies to all five external dispatch methods: `codex_exec`, `gemini_cli`, `ollama_run`, `cursor_cli`, and `openai_compatible_api`.
The Insight (Rule of Thumb)
- Action: Write the prompt to a temp file using a quoted heredoc, then pass it as a quoted argument via `$(cat "$file")`. Never interpolate prompt text into the command string.
- Value: Use `<<'COUNCIL_PROMPT_EOF'` (single-quoted delimiter) — the single quotes disable all expansion inside the heredoc. An unquoted delimiter (`<<EOF`) would still allow `$(…)` injection.
- Trade-off: Adds 2 lines of boilerplate (mktemp + heredoc) and a cleanup line per dispatch. The overhead is negligible compared to the security risk of shell injection.
- Compatibility: Works with all Bash-based dispatch methods. For the `openai_compatible_api` method, the same pattern applies, with the additional security of passing the API key via process substitution (`-H @<(…)`) so it never appears in `ps` output.
Reasoning
Shell command injection is one of the oldest and most dangerous security vulnerabilities. In the council context, the prompt text is not fully trusted: it contains user-supplied problem statements, and in Round 2+, it contains outputs from other LLMs — which could themselves contain adversarial text designed to exploit the dispatch mechanism.
A quoted heredoc (`<<'DELIM'`) is the strongest protection: the single-quoted delimiter tells Bash to treat the entire body as a literal string with zero expansion. No `$`, backtick, or `\` is interpreted. This is strictly safer than unquoted heredocs, double-quoted strings, or `printf` — all of which allow some form of expansion.
The temp file + `$(cat "$file")` pattern ensures the prompt is passed as a single argument to the provider command, regardless of its content. Even if the prompt contains the exact delimiter string, it would only terminate the heredoc early — it cannot execute commands.
The pattern is codified in every external dispatch template in `SKILL.md` (L310-318 for codex, L324-330 for gemini, L338-343 for ollama, L352-357 for cursor, L369-378 for openai_compatible), and the dispatch method documentation explicitly states the constraint.