Sub topic 10
Threat Modeling a Repository Workflow
This chapter assumes you know git and pull requests, can read basic Python and YAML, and understand how a coding agent calls tools. Threat modeling turns the earlier ideas into a short written analysis of one agent workflow. You will list what the agent touches, trace where attacker text can enter, and decide which defenses to apply.
Start with one workflow
Pick one concrete job, such as "an agent triages new issues and runs the tests on pull requests." A model of "the agent" in general is too vague to be useful. Write down four things:
- Inputs: every source of text the agent reads.
- Capabilities: the tools it can call, such as shell, file writes, and network.
- Assets: the data and powers an attacker would want, such as tokens, private code, and write access.
- Outputs: every place the agent can send data, including comments, commits, and URLs.
Map trust boundaries
A trust boundary is a line where content passes from a less trusted party to a more trusted one. In a repository, the maintainer's own prompt is trusted. Issue text from strangers is not. Pull request content from forks is not. Dependencies and fetched web pages are not. Files on the default branch are only as trusted as the people who can merge to it.
Everything on the left can carry instructions. Everything on the right is what an injected instruction could use.
Ask the trifecta questions
For each workflow, answer three questions:
- Can the agent read private data, such as secrets, private repositories, or environment variables?
- Can untrusted text reach its context?
- Can it send data out through a comment, a commit, a URL, or a tool call?
If all three answers are yes, you have a data theft path. Remove at least one leg. This is usually cheaper than trying to detect malicious text.
Record the result
A small table is enough. Each row pairs an entry point with what an attacker could gain and the control you will add.
| Entry point | Attacker goal | Control |
|---|---|---|
| Issue body | Make the agent print environment variables in a comment | Run without secrets in the environment, and give the token `issues: write` only |
| Fork pull request | Run a modified test script | Run in a sandbox with no network |
| `.cursorrules` or hook file | Add commands the agent runs automatically | Require review of agent configuration changes |
| Fetched web page | Send repository data to an attacker URL | Egress allowlist |
Notice that each control limits what the agent can do. None of them depends on the model spotting the attack.
Review and repeat
Revisit the model whenever you add a tool, a new input source, or a broader token. Each change can complete a trifecta that was incomplete before. Rank the rows by impact and likelihood, then fix the highest ones first.
Exercise
An agent reads public issues, has a token with write access to the repository and read access to a private repository, and can post comments. Which trifecta legs are present, and what is the cheapest change that breaks the path?
Show answer
All three are present. Private data is the private repository access, untrusted input is the public issues, and the outbound channel is the comments. The cheapest fix is to remove the private repository access by using a token scoped to the one repository, which also limits the write access. Dropping comment posting would work too, but it removes the feature.