Skip to content
← back to writing
8 min read

Every call was allowed. The sequence was the attack.

How repoward stops an AI agent from leaking private code after reading a malicious GitHub issue: a flow guard decided by GitHub facts, single-use approvals, and an audit log that says exactly what it can and can't prove.

#mcp#security#ai-agents#github#python

Here is an attack that works against a coding agent with ordinary GitHub access. Someone opens an issue on your public repository. The issue body contains instructions aimed at the agent, not at you. The agent reads the issue while triaging, follows the instructions, reads one of your private repositories, and opens a pull request on the public repo that contains what it found.

Invariant Labs published exactly this against agents using GitHub’s own MCP server. The uncomfortable part is not that the model got fooled. Models get fooled. The uncomfortable part is that every single call in that chain was allowed. Reading issues: allowed. Reading a private repo you own: allowed. Opening a pull request: allowed. Per-tool permissions looked at each step and found nothing wrong, because nothing was wrong with any one step.

The attack is the sequence. So I built repoward, a GitHub MCP server that decides each write based on what the agent has already read.

checks on every tool call, in one place
9
read, write, and dangerous tools
6 · 4 · 2
on PyPI, alpha
0.4.0

Why per-tool permissions can’t see it#

Most agent permission systems answer one question: is this tool allowed for this caller? That question has no memory. It can’t tell the difference between “open a PR” after reading your own code and “open a PR” right after reading a stranger’s issue that said to.

Per-tool permissions
  1. Is github_get_issue allowed? Yes.
  2. Is github_get_file on a private repo allowed? Yes.
  3. Is github_create_pull_request allowed? Yes.
  4. Private code is now in a public PR.
Flow guard
  1. Read an issue from an untrusted author. Noted.
  2. Read a file from a private repo. Noted.
  3. Write to a public repo after a private read: denied.
  4. Any write after untrusted input: needs a human.

The flow guard#

Before every write, repoward looks at what this agent has read during the current window (60 minutes by default) and applies two rules:

If the agent has readThen
Anything from a private repositoryWrites to public repositories are denied
An issue, PR, or comment from an author outside OWNER, MEMBER, and COLLABORATOR, or a CI job logEach write needs human approval

The important design decision is where those facts come from. Repository visibility and author_association come from GitHub’s API, not from the model and not from scanning text. That matters because the obvious alternative, looking for “ignore previous instructions” and friends, is a contest the defender loses. An attacker can reword, translate, base64-encode, or split the payload across comments. None of that changes whether the repo is private or whether the author is a collaborator.

The state also survives restarts, and no tool can clear it. If the agent could call flow_reset, a sufficiently convincing issue would tell it to. Only a person can, from the command line:

terminal
$ uvx repoward flow status$ uvx repoward flow reset

One pipeline, no side doors#

The second rule I held myself to: there is exactly one place where tool code runs. Every attempt goes through the same nine steps, including calls to tools that don’t exist and calls with invalid arguments, so every attempt shows up in the log.

MCP client
    |  stdio, or HTTP with a JWT checked on every request
    v
repoward
    1. Find the tool and validate its arguments    fail: refused and logged
    2. Check the policy                            default deny
    3. Check the flow guard                        for writes
    4. Check the rate limit
    5. Check for human approval                    if policy or the flow guard asks for it
    6. Log the decision                            if this fails, a write does not happen
    7. Run the tool
    8. Clean, redact, limit and label the output
    9. Log the outcome
    |
    v
GitHub API

Step 6 is the one I’d point at if someone asked what “fail closed” means in practice. If the decision can’t be written to the audit log, the write doesn’t happen. A write you can’t account for is worse than a write that didn’t happen.

The policy behind step 2 is default-deny YAML with roles, repository allowlists, and path denylists. On top of that, writes have their own guardrails regardless of policy:

  • Writes only reach branches with a configured prefix, agent/ by default.
  • Pull requests are draft-only by default.
  • Commit sizes are capped, and nothing is ever forced or retried.
  • Text holding a recognizable credential is refused before it leaves.
  • .github/** is denied by the starter policy, so an agent can’t edit the workflows that check its own work.

Approvals that can’t be reused#

When a call needs approval, it doesn’t run. It returns an approval_id, and a person decides from a terminal:

terminal
$ uvx repoward approvals list$ uvx repoward approvals show <id>$ uvx repoward approvals approve <id>

The agent then repeats the same call. “The same call” is doing a lot of work there. An approval matches the user, the tool, the repository, and the exact arguments. It works once, and it expires. A merge approval names a commit, so if the agent pushes anything after you approve, the old approval no longer applies, and GitHub itself refuses a merge whose head has moved.

For teams, a merge can also be approved by a real GitHub pull request review. A review counts only if it approves the exact commit being merged, comes from someone other than the PR author and the server’s own identity, and that person has the required access. Any outstanding “request changes” blocks it, and every check is made again at merge time.

Where it runs decides what it protects#

This is the section I’d most like people to read before installing it. repoward’s guarantees depend entirely on what else the agent can reach:

DeploymentThe agent can reachWhat holds
Agent has only MCP tools, no shell or file accessMCP toolsPolicy, flow guard, approvals, and audit
Same OS user, agent has a shell (a typical local coding agent)Everything the user can reachNot a security boundary. It could read the token, edit the policy, or approve its own requests
Server under its own OS user, in a container, or on another hostOnly the MCP interfacePolicy, flow guard, approvals, and audit

The honest summary: for a local coding agent with a shell, repoward helps an agent that has been misled, not one that’s trying to get around it. It’s built for agents whose only route to GitHub is this server, like CI bots and hosted agents. The repo includes a tested setup for running it as a separate Linux user, and GitHub-side controls such as a ruleset protecting your default branch are the backstop in every case.

An audit log that says what it can’t prove#

Every decision goes into a hash-chained log. “Hash-chained” gets used as if it meant “tamper-proof”, so the README spells out what it actually detects:

AttackPlain chainWith an HMAC key the attacker can’t readWith off-host checkpoints
Edit one recordDetectedDetectedDetected
Edit a record and recompute all later hashesNot detectedDetectedDetected back to the last checkpoint
Delete the newest recordsNot detectedNot detectedDetected back to the last checkpoint

Comment bodies, titles, commit messages, and file contents are logged as a length and a hash, not as text, so the audit log doesn’t become a second copy of everything private the agent touched.

Testing a policy against the past#

Changing a security policy blind is how you either lock out legitimate work or open a hole. So repoward policy replay re-runs the recorded decisions against a candidate policy, offline:

repoward policy replay --policy new-policy.yaml
3 decisions: 1 unchanged, 1 changed, 1 unknownChanged:  seq 2  github_comment  org/app: allow -> approval_required  (flow.untrusted_author)Unknown (the log does not hold what this decision depends on):  seq 5  github_commit_files  org/app: allow -> unknown

That unknown is deliberate. Because the log doesn’t store content, some decisions can’t be re-evaluated: whether a commit would now exceed a size limit, or whether hidden text held a credential. Replay says so instead of guessing. It also refuses to run on a log that fails verification.

The bug the threat model found#

The threat model is written as a table, and every row has a “what remains” column. Being forced to fill that column in is what makes it useful: you can’t write “none known” next to a threat without checking. One row asks whether an agent can read a denied file through a symlink.

It could. GitHub’s contents API follows symlinks and reports them as regular files, so a symlink at an allowed path pointing to a denied one would hand over the denied file. The fix was to stop using the contents API for files entirely: github_get_file now walks the Git tree, checks real file modes, and fetches blobs by SHA. It’s listed under Security in the 0.1.0 changelog, and that row of the threat model now says “none known”.

Least privilege that GitHub enforces#

With a personal access token, repoward’s restrictions are enforced by repoward. That’s fine until something goes wrong with repoward. In GitHub App mode, each tool call gets a short-lived token limited to one repository and only the permissions that tool needs, so GitHub enforces the limits too. If GitHub ever returns a token wider than requested, repoward refuses it.

What’s still missing#

It’s alpha, and it has not had an independent security review. The flow guard’s untrusted-author rule is tested against real author_association values from GitHub, and the test suite replays the published attack against real repositories, but that is not the same as someone else trying to break it. HTTP mode, which serves several users each with a JWT from their identity provider, has only been tested with Keycloak.

Try it#

uvx repoward init --repo your-org/your-repo
claude mcp add --env GITHUB_TOKEN=<your-token> --transport stdio repoward -- uvx repoward serve

The starter policy is read-only. Add --role contributor when you want write tools, and read the threat model first. If you’re wiring GitHub access into an agent, the question to ask isn’t “which tools should it have?” It’s “what should it be allowed to do after reading something a stranger wrote?”

2026·shipped

repoward: A GitHub MCP Server That Can't Be Talked Into Leaking

A GitHub MCP server that stops AI agents from acting on what an attacker's issue told them to do: flow guard, default-deny policy, single-use approvals, and a hash-chained audit log.

Personal project

Replays the published GitHub MCP exploit in its test suite

PythonMCPGitHub APIGitHub AppsYAML