repoward 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. repoward-0.1.0/.gitignore +31 -0
  2. repoward-0.1.0/CHANGELOG.md +32 -0
  3. repoward-0.1.0/CONTRIBUTING.md +35 -0
  4. repoward-0.1.0/LICENSE +21 -0
  5. repoward-0.1.0/PKG-INFO +317 -0
  6. repoward-0.1.0/README.md +287 -0
  7. repoward-0.1.0/SECURITY.md +9 -0
  8. repoward-0.1.0/docs/THREAT_MODEL.md +44 -0
  9. repoward-0.1.0/policy.example.yaml +74 -0
  10. repoward-0.1.0/pyproject.toml +89 -0
  11. repoward-0.1.0/src/repoward/__init__.py +1 -0
  12. repoward-0.1.0/src/repoward/adapters/__init__.py +1 -0
  13. repoward-0.1.0/src/repoward/adapters/ci.py +50 -0
  14. repoward-0.1.0/src/repoward/adapters/github.py +150 -0
  15. repoward-0.1.0/src/repoward/approvals/__init__.py +1 -0
  16. repoward-0.1.0/src/repoward/approvals/store.py +199 -0
  17. repoward-0.1.0/src/repoward/audit.py +235 -0
  18. repoward-0.1.0/src/repoward/canonical.py +20 -0
  19. repoward-0.1.0/src/repoward/catalog.py +29 -0
  20. repoward-0.1.0/src/repoward/cli.py +391 -0
  21. repoward-0.1.0/src/repoward/flow.py +239 -0
  22. repoward-0.1.0/src/repoward/pipeline.py +333 -0
  23. repoward-0.1.0/src/repoward/policy/__init__.py +1 -0
  24. repoward-0.1.0/src/repoward/policy/engine.py +101 -0
  25. repoward-0.1.0/src/repoward/policy/loader.py +245 -0
  26. repoward-0.1.0/src/repoward/policy/models.py +100 -0
  27. repoward-0.1.0/src/repoward/principal.py +15 -0
  28. repoward-0.1.0/src/repoward/py.typed +0 -0
  29. repoward-0.1.0/src/repoward/ratelimit.py +39 -0
  30. repoward-0.1.0/src/repoward/registry.py +68 -0
  31. repoward-0.1.0/src/repoward/sanitize.py +207 -0
  32. repoward-0.1.0/src/repoward/server.py +101 -0
  33. repoward-0.1.0/src/repoward/setup.py +118 -0
  34. repoward-0.1.0/src/repoward/storage.py +26 -0
  35. repoward-0.1.0/src/repoward/tools/__init__.py +1 -0
  36. repoward-0.1.0/src/repoward/tools/ci_read.py +121 -0
  37. repoward-0.1.0/src/repoward/tools/github_dangerous.py +135 -0
  38. repoward-0.1.0/src/repoward/tools/github_read.py +312 -0
  39. repoward-0.1.0/src/repoward/tools/github_write.py +239 -0
  40. repoward-0.1.0/src/repoward/tools/system.py +26 -0
  41. repoward-0.1.0/src/repoward/validation.py +63 -0
@@ -0,0 +1,31 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+
9
+ # Tool caches
10
+ .mypy_cache/
11
+ .pytest_cache/
12
+ .ruff_cache/
13
+ .coverage
14
+ htmlcov/
15
+
16
+ # Secrets and runtime data
17
+ .env
18
+ .env.*
19
+ !.env.example
20
+ *.pem
21
+ *.db
22
+ *.db-*
23
+ *.sqlite3
24
+ audit*.jsonl
25
+ policy.yaml
26
+
27
+ # Editors and OS
28
+ .vscode/
29
+ .idea/
30
+ .DS_Store
31
+ Thumbs.db
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ This project follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
4
+ [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2026-11-06
9
+
10
+ ### Added
11
+
12
+ - `repoward init`, which creates a safe starter policy and prints a client config.
13
+ - MCP server over stdio with a `ping` tool.
14
+ - Default-deny YAML policy with strict loading and `repoward validate-policy`.
15
+ - Single guarded pipeline for every tool attempt.
16
+ - Hash-chained audit log with HMAC mode, `repoward audit verify` and `repoward audit checkpoint`.
17
+ - Per-principal, per-tool rate limits.
18
+ - Read tools for issues, code search, files, CI status and job logs.
19
+ - Framing, invisible-character removal and redaction for text from GitHub users.
20
+ - Write tools for branches, commits, draft pull requests and comments.
21
+ - Approval store, `repoward approvals` commands, and dangerous tools for merging pull requests and
22
+ deleting branches.
23
+ - Flow guard: writes are decided by what the agent has read, using repository visibility and author
24
+ association from GitHub, with `repoward flow` commands for people.
25
+ - Policy rules for the branch prefix, draft-only pull requests and commit limits, and a scan that
26
+ refuses to send recognizable credentials.
27
+
28
+ ### Security
29
+
30
+ - `github_get_file` could return a denied file through a symlink at an allowed path, because
31
+ GitHub's contents API follows such links and reports them as files. It now walks the Git tree
32
+ and refuses anything but a regular file. Never in a release.
@@ -0,0 +1,35 @@
1
+ # Contributing
2
+
3
+ ## Setup
4
+
5
+ Requires Python 3.11+ and [uv](https://docs.astral.sh/uv/).
6
+
7
+ ```bash
8
+ uv sync
9
+ ```
10
+
11
+ ## Checks
12
+
13
+ Run these before opening a pull request. CI runs the same commands.
14
+
15
+ ```bash
16
+ uv run ruff check .
17
+ uv run ruff format --check .
18
+ uv run mypy
19
+ uv run pytest
20
+ ```
21
+
22
+ A live suite runs against real sandbox repositories. It is skipped by default and needs
23
+ `GITHUB_TOKEN`, `GITHUB_WRITE_TOKEN`, `REPOWARD_LIVE_REPO` and `REPOWARD_LIVE_PRIVATE_REPO`. It
24
+ merges real commits, so only point it at sandboxes:
25
+
26
+ ```bash
27
+ uv run pytest -m live
28
+ ```
29
+
30
+ ## Pull requests
31
+
32
+ - Keep each change small and focused.
33
+ - Use [Conventional Commits](https://www.conventionalcommits.org/) for commit messages.
34
+ - Add tests for behavior changes. Security-relevant logic must have tests.
35
+ - Never commit secrets, including in test fixtures.
repoward-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sanoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,317 @@
1
+ Metadata-Version: 2.5
2
+ Name: repoward
3
+ Version: 0.1.0
4
+ Summary: A GitHub MCP server that stops AI agents leaking private code when a malicious issue tells them to.
5
+ Project-URL: Homepage, https://github.com/Sanoy24/repoward
6
+ Project-URL: Issues, https://github.com/Sanoy24/repoward/issues
7
+ Project-URL: Changelog, https://github.com/Sanoy24/repoward/blob/main/CHANGELOG.md
8
+ Author: sanoy
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai-agents,github,mcp,model-context-protocol,prompt-injection,security
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: anyio>=4.9
23
+ Requires-Dist: filelock<5,>=3.20
24
+ Requires-Dist: httpx<0.29,>=0.28
25
+ Requires-Dist: mcp<3,>=2.3
26
+ Requires-Dist: pathspec<2,>=1
27
+ Requires-Dist: pydantic<3,>=2.12
28
+ Requires-Dist: pyyaml>=6
29
+ Description-Content-Type: text/markdown
30
+
31
+ # repoward
32
+
33
+ <!-- mcp-name: io.github.Sanoy24/repoward -->
34
+
35
+ A GitHub MCP server that stops AI agents acting on what an attacker's issue told them to do.
36
+
37
+ > **Status: alpha.** It has not had an independent security review. Read
38
+ > [the threat model](https://github.com/Sanoy24/repoward/blob/main/docs/THREAT_MODEL.md), especially the part about where it runs.
39
+
40
+ ## The problem
41
+
42
+ An agent with GitHub access can read a malicious public issue, read a private repository, and post
43
+ the contents in a public pull request. Each call looks allowed on its own, so per-tool permissions
44
+ do not stop the sequence. This is the
45
+ [attack Invariant Labs published](https://invariantlabs.ai/blog/mcp-github-vulnerability) against
46
+ agents using GitHub's MCP server, and repoward's test suite replays it against real repositories.
47
+
48
+ ## Flow guard
49
+
50
+ Before every write, repoward checks what this agent has already read, using facts from GitHub:
51
+
52
+ | If the agent has read | Then |
53
+ | --- | --- |
54
+ | Anything from a private repository | Writes to public repositories are denied |
55
+ | An issue, pull request or comment from an author outside `OWNER`, `MEMBER` and `COLLABORATOR`, or a job log | Each write needs human approval |
56
+
57
+ This does not depend on the model noticing an attack or on scanning text, so rewording or
58
+ encoding the data does not get around it. The state survives restarts, and no tool can clear it.
59
+ A person can:
60
+
61
+ ```bash
62
+ uvx repoward flow status
63
+ uvx repoward flow reset
64
+ ```
65
+
66
+ What it does not do:
67
+
68
+ - It only sees this server's tools. A shell, a browser or another MCP server is still a way out, so
69
+ it protects agents whose GitHub access and outbound routes are limited to this server.
70
+ - Data can stay in an agent's context after the window (60 minutes by default) ends. Restart a
71
+ long-running agent to clear its context.
72
+ - Reading one private repository and writing to another private repository is allowed, unless you
73
+ set `single_repo: true`.
74
+ - Repository files and code search results do not count as untrusted input, because they were
75
+ merged by someone with write access.
76
+ - `author_association` is a coarse signal, and a compromised trusted account counts as trusted.
77
+ - Maintainers of public repositories will see more approval requests. That is the cost of the
78
+ default, and `trusted_associations` is configurable.
79
+
80
+ ## What works today
81
+
82
+ - **Policy:** default-deny YAML with roles, repository allowlists and path denylists. See
83
+ [policy.example.yaml](https://github.com/Sanoy24/repoward/blob/main/policy.example.yaml).
84
+ - **Single guarded path:** every tool attempt, including unknown tools and invalid arguments, passes
85
+ through one pipeline and is logged.
86
+ - **Audit log:** a hash-chained record of every decision, with optional HMAC and checkpoints.
87
+ - **Rate limits:** per principal and per tool.
88
+ - **Read tools:** `github_list_issues`, `github_get_issue`, `github_search_code`, `github_get_file`,
89
+ `ci_get_status` and `ci_get_job_logs`.
90
+ - **Write tools:** `github_create_branch`, `github_commit_files`, `github_create_pull_request` and
91
+ `github_comment`. Writes only reach branches with the configured prefix (`agent/` by default),
92
+ pull requests are draft only by default, commit sizes are limited, nothing is forced or retried,
93
+ and text holding a recognizable credential is refused.
94
+ - **Dangerous tools:** `github_merge_pull_request` and `github_delete_branch` need human approval.
95
+ An approval covers one exact call at one exact commit, works once and expires. Merging is off
96
+ until a policy turns it on.
97
+ - **Untrusted content handling:** text from GitHub users comes back wrapped in a tag with a random
98
+ id per response, after invisible characters, hidden HTML comments and images are removed and
99
+ secrets are redacted. This is a mitigation, not a guarantee: a model can still be fooled, which
100
+ is why the rules above are enforced outside the model.
101
+
102
+ ## Planned
103
+
104
+ - **Least-privilege tokens:** short-lived GitHub App tokens scoped to each call.
105
+
106
+ ## Who it is for
107
+
108
+ Agents whose only route to GitHub is this server, such as CI bots and hosted agents. An agent with
109
+ shell access can run `git` or read local credentials directly, so this server is not a security
110
+ boundary for it.
111
+
112
+ ## Install
113
+
114
+ Requires [uv](https://docs.astral.sh/uv/). Create a starter policy, which also prints a client
115
+ config to paste:
116
+
117
+ ```bash
118
+ uvx repoward init --repo your-org/your-repo
119
+ ```
120
+
121
+ The starter policy gives the server read-only tools. Add `--role contributor` for write tools. Files
122
+ live in `~/.repoward`, or wherever `REPOWARD_HOME` points. An existing policy is never overwritten.
123
+
124
+ Then add it to your MCP client, and use a token set up as described in [GitHub token](#github-token).
125
+ Avoid committing a config that holds a real token.
126
+
127
+ <details open>
128
+ <summary><b>Claude Code</b></summary>
129
+
130
+ ```bash
131
+ claude mcp add --env GITHUB_TOKEN=<your-token> --transport stdio repoward -- uvx repoward serve
132
+ ```
133
+
134
+ </details>
135
+
136
+ <details>
137
+ <summary><b>Claude Desktop</b></summary>
138
+
139
+ In `claude_desktop_config.json`, under Settings > Developer > Edit Config:
140
+
141
+ ```json
142
+ {
143
+ "mcpServers": {
144
+ "repoward": {
145
+ "command": "uvx",
146
+ "args": ["repoward", "serve"],
147
+ "env": { "GITHUB_TOKEN": "<your-token>" }
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ </details>
154
+
155
+ <details>
156
+ <summary><b>Cursor</b></summary>
157
+
158
+ In `~/.cursor/mcp.json`, reading the token from your environment:
159
+
160
+ ```json
161
+ {
162
+ "mcpServers": {
163
+ "repoward": {
164
+ "command": "uvx",
165
+ "args": ["repoward", "serve"],
166
+ "env": { "GITHUB_TOKEN": "${env:GITHUB_TOKEN}" }
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ </details>
173
+
174
+ <details>
175
+ <summary><b>VS Code</b></summary>
176
+
177
+ In `.vscode/mcp.json` or your user profile's `mcp.json`, which prompts for the token once:
178
+
179
+ ```json
180
+ {
181
+ "inputs": [
182
+ { "type": "promptString", "id": "github-token", "description": "GitHub token", "password": true }
183
+ ],
184
+ "servers": {
185
+ "repoward": {
186
+ "type": "stdio",
187
+ "command": "uvx",
188
+ "args": ["repoward", "serve"],
189
+ "env": { "GITHUB_TOKEN": "${input:github-token}" }
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ </details>
196
+
197
+ <details>
198
+ <summary><b>Codex</b></summary>
199
+
200
+ In `~/.codex/config.toml`, forwarding the token from your environment:
201
+
202
+ ```toml
203
+ [mcp_servers.repoward]
204
+ command = "uvx"
205
+ args = ["repoward", "serve"]
206
+ env_vars = ["GITHUB_TOKEN"]
207
+ ```
208
+
209
+ </details>
210
+
211
+ <details>
212
+ <summary><b>Gemini CLI</b></summary>
213
+
214
+ In `~/.gemini/settings.json`, reading the token from your environment:
215
+
216
+ ```json
217
+ {
218
+ "mcpServers": {
219
+ "repoward": {
220
+ "command": "uvx",
221
+ "args": ["repoward", "serve"],
222
+ "env": { "GITHUB_TOKEN": "$GITHUB_TOKEN" }
223
+ }
224
+ }
225
+ }
226
+ ```
227
+
228
+ </details>
229
+
230
+ Any other client that can launch a stdio MCP server runs the same command: `uvx repoward serve`.
231
+
232
+ Useful commands:
233
+
234
+ ```bash
235
+ uvx repoward validate-policy
236
+ uvx repoward audit verify
237
+ ```
238
+
239
+ ## Approving risky actions
240
+
241
+ A call that needs approval does not run. It returns an `approval_id`, and a person decides from a
242
+ terminal:
243
+
244
+ ```bash
245
+ uvx repoward approvals list
246
+ uvx repoward approvals show <id>
247
+ uvx repoward approvals approve <id>
248
+ ```
249
+
250
+ The agent then repeats the same call. Pushing new commits changes the commit the call names, so
251
+ the old approval no longer applies, and GitHub refuses a merge whose head has moved.
252
+
253
+ If the agent runs as the same OS user as this server and has a shell, it could run these commands
254
+ or edit the database itself. Run the server and its files under a separate user or in a container
255
+ for approvals to mean anything.
256
+
257
+ ## GitHub token
258
+
259
+ Use a [fine-grained personal access token](https://github.com/settings/personal-access-tokens/new)
260
+ limited to the repositories you allow, with short expiry. Choose **Only select repositories** so
261
+ that repository permissions appear. The read tools need these, all read-only:
262
+
263
+ | Permission | Used for |
264
+ | --- | --- |
265
+ | Metadata | Required by GitHub |
266
+ | Contents | `github_get_file` |
267
+ | Issues | `github_list_issues`, `github_get_issue` |
268
+ | Pull requests | Pull requests in those same tools |
269
+ | Actions | `ci_get_status`, `ci_get_job_logs` |
270
+ | Commit statuses | `ci_get_status` |
271
+
272
+ To use the write tools, also give it read and write access to Contents, Issues and Pull requests.
273
+ Leave the Workflows permission off: GitHub then refuses workflow file changes even if your policy
274
+ allows the path.
275
+
276
+ `Contents: write` lets a token push to any branch and merge, and GitHub cannot limit it to `agent/`
277
+ branches. That limit lives in this server, so also protect your default branch with a ruleset that
278
+ requires pull requests and has no bypass for the token's owner. If the token leaks or the server is
279
+ misconfigured, that ruleset still holds.
280
+
281
+ Limits to know about:
282
+
283
+ - `ci_get_status` does not show third-party checks reported only through the Checks API, which
284
+ GitHub documents as unavailable to fine-grained tokens.
285
+ - `github_search_code` covers the default branch and files under 384 KB. New repositories can
286
+ return nothing until GitHub indexes them, and its handling of real results has so far only been
287
+ tested against simulated responses.
288
+ - `github_get_file` refuses symlinks, submodules, binary files and files over 1 MB. It walks the
289
+ Git tree, so each read makes one request per folder in the path.
290
+ - `ci_get_job_logs` fails closed if GitHub moves log storage to a host it does not recognize.
291
+ - `github_merge_pull_request` does not support merge queues or stacked pull requests.
292
+ - `github_delete_branch` checks the commit and then deletes, because GitHub has no conditional
293
+ delete, so a small window remains between the two.
294
+
295
+ ## What the audit log proves
296
+
297
+ The log is tamper-evident, not tamper-proof.
298
+
299
+ | Attack | Plain chain | With an HMAC key the attacker cannot read | With off-host checkpoints |
300
+ | --- | --- | --- | --- |
301
+ | Edit one record | Detected | Detected | Detected |
302
+ | Edit a record and recompute all later hashes | **Not detected** | Detected | Detected back to the last checkpoint |
303
+ | Delete the newest records | **Not detected** | **Not detected** | Detected back to the last checkpoint |
304
+
305
+ Set `REPOWARD_AUDIT_HMAC_KEY` to use HMAC, and store the output of `repoward audit checkpoint`
306
+ somewhere the server cannot write. Comment bodies, titles, commit messages and file contents are
307
+ logged as a length and hash rather than as text. A crash during a write leaves an incomplete last line, and new
308
+ writes are then refused until an operator repairs the log. Secret redaction is best effort.
309
+
310
+ ## Contributing and security
311
+
312
+ See [CONTRIBUTING.md](https://github.com/Sanoy24/repoward/blob/main/CONTRIBUTING.md). Please report vulnerabilities as described in
313
+ [SECURITY.md](https://github.com/Sanoy24/repoward/blob/main/SECURITY.md).
314
+
315
+ ## License
316
+
317
+ [MIT](https://github.com/Sanoy24/repoward/blob/main/LICENSE). This is an independent project, not affiliated with or endorsed by GitHub.