- Location
- examples/grade-a-pipeline.workflow.js:219
- Finding
- Indirect Prompt Injection Through Repository-Derived Maps and Diffs<![CDATA[
## Vulnerability Details
**File Location**: `examples/grade-a-pipeline.workflow.js:219-230, 261-280, 285-310, 337, 401-425`
**Vulnerability Type**: Indirect prompt injection from untrusted repository content
**Risk Level**: High
### Vulnerable Code
```javascript
const mapBlock = (MAP) => '\n\n===== CODEBASE MAP (authoritative; do not re-derive) =====\n' + MAP + '\n===== END MAP =====\n';
```
```javascript
const cartographerPrompt = (shard, idx) =>
'You are CARTOGRAPHER ' + idx + '. Read ONLY these files inside ' + INTEGRATION_WT + ' (a clean checkout of the repo). Do NOT modify anything.\n' +
'Files (relative to that worktree):\n' + shard.map(f => ' - ' + f).join('\n') + '\n\n' +
'For each file return: path, language, one-line role, and its top-level SYMBOLS (functions, classes, methods, ' +
'exported constants, routes/endpoints, CLI commands) with kind+name+signature+line, plus the modules it depends on. ' +
'Be precise and complete; this map is injected into every downstream worker. Return SHARDMAP.';
```
```javascript
const reviewPrompt = (lens, MAP, diff) =>
'You are a CODE REVIEWER with the ' + lens + ' lens. Review ONLY the cumulative diff below against the map. Find real, ' +
'specific defects in this lens; do not invent nits. ' + mapBlock(MAP) +
'\nCUMULATIVE DIFF:\n' + diff.slice(0, 150000) + '\nReturn REVIEW (findings[] with file, issue, severity, fix).';
```
### Technical Analysis
The workflow reads attacker-controllable repository files, converts their contents into a synthesized map, and inserts that map into numerous downstream prompts. It explicitly labels the map as “authoritative.” Repository-derived diffs are likewise inserted into reviewer and grading prompts.
No robust trust-boundary instruction tells downstream agents that repository text is untrusted data and that embedded directives must never alter tool use, safety rules, output schemas, or task objectives. Delimiters identify where the map begins and e
...[truncated 1778 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Treat all repository content, maps, diffs, test output, and planner output as untrusted data.
2. Add a higher-priority instruction stating that embedded repository instructions must never be followed and may only be analyzed as data.
3. Remove the “authoritative” designation from repository-derived free text.
4. Prefer structured representations containing normalized file paths, symbol names, and dependencies instead of copying free-form prose.
5. Strip or encode control-like text before inserting repository content into prompts.
6. Separate content-processing agents from mutation-capable agents and grant each the minimum required tools.
7. Disable network and out-of-scope filesystem access for cartography, planning, review, and grading agents.
8. Independently verify every proposed diff, changed path, command result, and Git operation outside the model.
9. Add prompt-injection fixtures to tests, including hostile source comments, Markdown instructions, filenames, test output, and diff content.
]]>