Sub topic 2
Attack Patterns in Coding-Agent Workflows
Assume you know basic Git, issues, pull requests, the command line, and simple Python and YAML. This chapter focuses on how untrusted repository content can influence an agent that can read, write, or run commands.
Common attack patterns
An indirect prompt injection hides instructions inside content the agent is asked to process. Examples include:
- Hidden text in HTML comments, generated files, or whitespace.
- “Poisoned” documentation that tells the agent to upload configuration files.
- Malicious issue descriptions or pull-request comments that request unsafe commands.
- Code comments that look like developer guidance but actually target the agent.
The model receives these words in the same context as legitimate instructions. A label such as <untrusted> helps reviewers, but it does not create a security boundary. The agent must also have limited capabilities.
Repository configuration deserves the same suspicion. Rules files, MCP settings, editor tasks, and Git hooks can change what an agent reads or runs. Do not automatically trust configuration merely because it is committed to the repository.
How stolen data leaves
An injected instruction may try to send data through:
- An HTTP request to an attacker-controlled URL.
- A rendered image or Markdown link whose URL contains secret text.
- A commit, issue comment, or pull-request comment.
- Arguments passed to a tool, including a test runner or package manager.
- Logs that another service collects.
The dangerous combination is private data, untrusted input, and an outbound channel. If any one of these is absent or tightly controlled, data theft becomes harder.
Threat modeling and least privilege
Model one workflow before enabling it:
- List every input: files, issues, comments, dependencies, and tool output.
- List every capability: file access, shell commands, network access, credentials, and write permissions.
- Identify where sensitive data could be read and where it could leave.
- Add controls at each boundary.
Give the agent only the permissions required for its task. Prefer read-only tokens, no production credentials, isolated workspaces, disabled network access, and an allowlist of approved commands. Run high-impact actions behind human approval.
import subprocess
ALLOWED = {
("git", "status"),
("git", "diff"),
("pytest", "-q"),
}
def run_tool(argv):
command = tuple(argv)
if command not in ALLOWED:
raise PermissionError(f"command not allowed: {argv}")
return subprocess.run(
argv, capture_output=True, text=True, timeout=60, check=False
)This wrapper limits command arguments, but it is only one layer. A secure workflow also limits files, credentials, network destinations, and write access.
Exercise
An agent reads issue text and can access a cloud token and the public internet. Which part of the threat model should you change first?
Show answer
Remove the token or block outbound network access. Ideally, apply both controls and give the agent only read-only permissions.