Sub topic 2
Where Untrusted Content Enters a Coding Agent
This chapter assumes you know git, issues, and pull requests, and have a general idea of how an AI coding assistant works. It builds on the agent loop from the previous chapter.
Trusted and untrusted text
A coding agent's context holds text from many places. Only some of it comes from you. The rest is text the agent fetched, and someone else may have written it. Treat that text as untrusted. It may be accurate, but you did not write it and you cannot vouch for it.
The question to ask is: who could have written this text, and could that person be an attacker? A file in your repository may have been written by any past contributor. An issue may have been written by anyone with an account.
The main entry points
| Source | Who can write it | Typical example |
|---|---|---|
| Repository files | Contributors, forks, past commits | README, source comments, test fixtures |
| Issues and pull requests | Anyone who can open one, often the whole internet | Bug report text, PR description |
| Comments and reviews | Anyone who can comment | Review notes, bot replies |
| Documentation | Doc authors, third-party sites | Pages the agent fetches from the web |
| Dependencies | Package authors | Files in `node_modules`, installed READMEs |
| Tool output | Whatever the tool touched | Test logs, `git log`, web search results |
Tool output is easy to overlook. A test runner prints an error message, and that message may quote data from a file or a network response. The agent reads it like any other text, so a trusted tool can carry untrusted content.
Trust is not uniform inside one source
One source can hold both trusted and untrusted text. Inside a single repository:
- A file you wrote this morning is trusted.
- A file from a pull request opened by a stranger is not.
- A vendored library is somewhere in between.
Hosting platforms add to the mix. Issue titles and bodies are attacker-controlled on public projects. Commit messages and branch names are also free text that an author chooses.
Following the flow
The diagram shows how external text reaches the model. Each arrow is a point where content crosses into the context.
The loop in the diagram matters. The model's tool calls produce tool output, and that output re-enters the context. One piece of poisoned text can therefore steer later steps, and each step can pull in more content.
A practical habit
Before running an agent on a task, list what it will read. Mark each item as written by you, written by your team, or written by someone else. This list is the starting point for the threat model built later in this tutorial.
Exercise
An agent is asked to fix a failing test in your public repository. It runs the tests, reads the failure log, opens an open issue that mentions the test, and fetches a library's documentation page. Which of these inputs could contain attacker-written text?
Show answer
All of them could. The failure log can quote data from files or network responses. Anyone can write the public issue. The documentation page is controlled by its publisher. Only text you wrote yourself is trusted, and even the test files may include contributions from others.