agentpipe-scan 0.5.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentoffense
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,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentpipe-scan
3
+ Version: 0.5.0
4
+ Summary: Find CI agents that eat untrusted GitHub events and hold secrets
5
+ Author: Agentpipe
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/cyberbobas/agentpipe
8
+ Project-URL: Issues, https://github.com/cyberbobas/agentpipe/issues
9
+ Keywords: ai-agent,github-actions,prompt-injection,ci,security,clinejection,supply-chain,sast,agent-security
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Topic :: Security
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: PyYAML>=6.0
20
+ Dynamic: license-file
21
+
22
+ # agentpipe
23
+
24
+ [![PyPI](https://img.shields.io/pypi/v/agentpipe-scan?color=8b7cf6)](https://pypi.org/project/agentpipe-scan/)
25
+ [![tests](https://github.com/cyberbobas/agentpipe/actions/workflows/tests.yml/badge.svg)](https://github.com/cyberbobas/agentpipe/actions/workflows/tests.yml)
26
+ [![Python](https://img.shields.io/pypi/pyversions/agentpipe-scan)](https://pypi.org/project/agentpipe-scan/)
27
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
28
+
29
+ Find **CI agents that eat untrusted GitHub events and hold keys**. A repo lets a
30
+ stranger's issue title drive an AI agent step that carries an npm token, and now
31
+ an issue is a publish. agentpipe finds those chains statically, before anyone
32
+ opens the issue.
33
+
34
+ Not an Actions linter. Not gitleaks. It reports preconditions and never exploits.
35
+
36
+ ![agentpipe finds an untrusted issue -> AI agent -> npm token publish chain](docs/agentpipe-scan.gif)
37
+
38
+ Part of [Agentoffense](https://agentoffense.com). The recon front of the line:
39
+ find the exposure here, close it at runtime with
40
+ [Airlock](https://github.com/cyberbobas/airlock) and
41
+ [Countersign](https://github.com/cyberbobas/countersign).
42
+
43
+ ```
44
+ pip install agentpipe-scan
45
+ agentpipe scan . # local clone, no network
46
+ agentpipe scan github.com/org/repo # public workflows via GitHub API
47
+ agentpipe scan github.com/org # whole org, aggregated report
48
+ agentpipe prove . # canary kit: prove each finding harmlessly
49
+ # (token: GITHUB_TOKEN env or --token)
50
+ ```
51
+
52
+ ## The killer bit: `prove`
53
+
54
+ A finding says "preconditions exist". `agentpipe prove` turns each high/medium
55
+ finding into a **harmless canary kit**: a unique token, the exact issue/PR text
56
+ to paste into a fork you own, the three places to watch (comment, step summary,
57
+ job log), what a positive result proves — and what it still doesn't (that part
58
+ is the pentest). Every payload is echo/read-only by construction.
59
+
60
+ The report also groups flat findings into **attack chains**
61
+ (entry → amplify → impact, one per job, severity-tagged).
62
+
63
+ ## `agentpipe local` — the laptop half
64
+
65
+ CI is only half the surface. `agentpipe local` audits agent configs on the
66
+ machine itself (`~/.claude.json`, `.mcp.json`, cursor/gemini/windsurf configs):
67
+
68
+ | id | finding |
69
+ |---|---|
70
+ | LOC-01 | confirmations weakened/off (`bypassPermissions`, unscoped tool grants) |
71
+ | LOC-02 | MCP server via unpinned `npx -y pkg` (rug-pull channel) |
72
+ | LOC-03 | filesystem MCP rooted at `/` or `~` |
73
+ | LOC-04 | remote MCP over plaintext `http://` or with no auth header |
74
+ | LOC-05 | hook piping the network into a shell (`curl … \| sh`) |
75
+ | LOC-06 | plaintext credential in an MCP env block (values are masked in the report) |
76
+ | LOC-07 | CLAUDE.md/.cursorrules ordering the agent to never ask |
77
+
78
+ Read-only, no network, secret values never printed.
79
+
80
+ Clinejection-class demo (issue title → Claude in Actions → npm token):
81
+
82
+ ```
83
+ agentpipe scan examples/clinejection-repo
84
+ ```
85
+
86
+ ## What the scanner flags
87
+
88
+ | id | chain | since |
89
+ |---|---|---|
90
+ | AWI-01 | untrusted trigger (`issues`, `issue_comment`, `pull_request_target`, …) + agent step + secret/write/publish | 0.1 |
91
+ | AWI-02 | `${{ github.event.issue.title }}` (or body/comment/PR) interpolated into the agent step | 0.1 |
92
+ | AWI-03 | `pull_request_target` + agent + checkout of PR head | 0.1 |
93
+ | AWI-04 | agent job can `issues: write` / `gh issue comment` (GitLost exfil) | 0.1 |
94
+ | AWI-05 | `--dangerously-skip-permissions` / YOLO on that agent | 0.1 |
95
+ | AWI-06 | `actions/cache` written on an untrusted-trigger workflow next to an agent/release | 0.3 |
96
+ | AWI-07 | agent/release job downloads artifacts across workflow boundaries (`workflow_run`) | 0.3 |
97
+ | AWI-08 | agent + `gh` CLI + `contents`/`actions: write` (workflow persistence) | 0.2 |
98
+ | AWI-09 | OIDC / cloud login on the untrusted-prompt job | 0.2 |
99
+ | AWI-10 | agent + untrusted trigger on a self-hosted runner | 0.2 |
100
+ | AWI-11 | agent hidden in a local composite action or reusable workflow (recursed, caller triggers inherited) | 0.2 |
101
+ | AWI-12 | GitHub Agentic Workflows: markdown `engine:` + untrusted `on:` + write surface | 0.3 |
102
+ | AWI-13 | Dependabot/Renovate in repo + agent merges PRs with no `dependabot[bot]` actor guard | 0.3 |
103
+ | AWI-14 | publish after/alongside an agent job with no `environment:` gate | 0.2 |
104
+ | AWI-15 | agent step handed `mcp_config` / MCP servers (CI trifecta) | 0.3 |
105
+
106
+ Findings carry real `file:line` of the agent step. A workflow that does not parse is a loud warning, not a silent skip.
107
+
108
+ Not yet: INS-01..04 (instruction-file hygiene in repos), GitHub Action wrapper, `--follow-remote`.
109
+
110
+ ## What you will not see
111
+
112
+ A 0–100 score. A badge. Telemetry. A working exploit. An Airlock pitch.
113
+
114
+ The report ends with **what this scan cannot see** — that list *is* the pentest offer.
115
+
116
+ ## Verdicts
117
+
118
+ `reachable` (trigger + agent + sink) · `plausible` (untrusted field in the prompt) · `adjacent` (one piece of the chain). Severity only on the first two.
119
+
120
+ MIT. Python ≥ 3.11. PyYAML.
121
+
122
+ ```
123
+ python3 tests/run.py # regression suite (41 checks)
124
+ python3 tests/adversarial.py # parser fuzz, FP/FN matrix, recursion, ReDoS, CLI
125
+ python3 tests/matrix.py # negative matrix per detector, GitHub semantics, live corpus
126
+ ```
@@ -0,0 +1,105 @@
1
+ # agentpipe
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/agentpipe-scan?color=8b7cf6)](https://pypi.org/project/agentpipe-scan/)
4
+ [![tests](https://github.com/cyberbobas/agentpipe/actions/workflows/tests.yml/badge.svg)](https://github.com/cyberbobas/agentpipe/actions/workflows/tests.yml)
5
+ [![Python](https://img.shields.io/pypi/pyversions/agentpipe-scan)](https://pypi.org/project/agentpipe-scan/)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
7
+
8
+ Find **CI agents that eat untrusted GitHub events and hold keys**. A repo lets a
9
+ stranger's issue title drive an AI agent step that carries an npm token, and now
10
+ an issue is a publish. agentpipe finds those chains statically, before anyone
11
+ opens the issue.
12
+
13
+ Not an Actions linter. Not gitleaks. It reports preconditions and never exploits.
14
+
15
+ ![agentpipe finds an untrusted issue -> AI agent -> npm token publish chain](docs/agentpipe-scan.gif)
16
+
17
+ Part of [Agentoffense](https://agentoffense.com). The recon front of the line:
18
+ find the exposure here, close it at runtime with
19
+ [Airlock](https://github.com/cyberbobas/airlock) and
20
+ [Countersign](https://github.com/cyberbobas/countersign).
21
+
22
+ ```
23
+ pip install agentpipe-scan
24
+ agentpipe scan . # local clone, no network
25
+ agentpipe scan github.com/org/repo # public workflows via GitHub API
26
+ agentpipe scan github.com/org # whole org, aggregated report
27
+ agentpipe prove . # canary kit: prove each finding harmlessly
28
+ # (token: GITHUB_TOKEN env or --token)
29
+ ```
30
+
31
+ ## The killer bit: `prove`
32
+
33
+ A finding says "preconditions exist". `agentpipe prove` turns each high/medium
34
+ finding into a **harmless canary kit**: a unique token, the exact issue/PR text
35
+ to paste into a fork you own, the three places to watch (comment, step summary,
36
+ job log), what a positive result proves — and what it still doesn't (that part
37
+ is the pentest). Every payload is echo/read-only by construction.
38
+
39
+ The report also groups flat findings into **attack chains**
40
+ (entry → amplify → impact, one per job, severity-tagged).
41
+
42
+ ## `agentpipe local` — the laptop half
43
+
44
+ CI is only half the surface. `agentpipe local` audits agent configs on the
45
+ machine itself (`~/.claude.json`, `.mcp.json`, cursor/gemini/windsurf configs):
46
+
47
+ | id | finding |
48
+ |---|---|
49
+ | LOC-01 | confirmations weakened/off (`bypassPermissions`, unscoped tool grants) |
50
+ | LOC-02 | MCP server via unpinned `npx -y pkg` (rug-pull channel) |
51
+ | LOC-03 | filesystem MCP rooted at `/` or `~` |
52
+ | LOC-04 | remote MCP over plaintext `http://` or with no auth header |
53
+ | LOC-05 | hook piping the network into a shell (`curl … \| sh`) |
54
+ | LOC-06 | plaintext credential in an MCP env block (values are masked in the report) |
55
+ | LOC-07 | CLAUDE.md/.cursorrules ordering the agent to never ask |
56
+
57
+ Read-only, no network, secret values never printed.
58
+
59
+ Clinejection-class demo (issue title → Claude in Actions → npm token):
60
+
61
+ ```
62
+ agentpipe scan examples/clinejection-repo
63
+ ```
64
+
65
+ ## What the scanner flags
66
+
67
+ | id | chain | since |
68
+ |---|---|---|
69
+ | AWI-01 | untrusted trigger (`issues`, `issue_comment`, `pull_request_target`, …) + agent step + secret/write/publish | 0.1 |
70
+ | AWI-02 | `${{ github.event.issue.title }}` (or body/comment/PR) interpolated into the agent step | 0.1 |
71
+ | AWI-03 | `pull_request_target` + agent + checkout of PR head | 0.1 |
72
+ | AWI-04 | agent job can `issues: write` / `gh issue comment` (GitLost exfil) | 0.1 |
73
+ | AWI-05 | `--dangerously-skip-permissions` / YOLO on that agent | 0.1 |
74
+ | AWI-06 | `actions/cache` written on an untrusted-trigger workflow next to an agent/release | 0.3 |
75
+ | AWI-07 | agent/release job downloads artifacts across workflow boundaries (`workflow_run`) | 0.3 |
76
+ | AWI-08 | agent + `gh` CLI + `contents`/`actions: write` (workflow persistence) | 0.2 |
77
+ | AWI-09 | OIDC / cloud login on the untrusted-prompt job | 0.2 |
78
+ | AWI-10 | agent + untrusted trigger on a self-hosted runner | 0.2 |
79
+ | AWI-11 | agent hidden in a local composite action or reusable workflow (recursed, caller triggers inherited) | 0.2 |
80
+ | AWI-12 | GitHub Agentic Workflows: markdown `engine:` + untrusted `on:` + write surface | 0.3 |
81
+ | AWI-13 | Dependabot/Renovate in repo + agent merges PRs with no `dependabot[bot]` actor guard | 0.3 |
82
+ | AWI-14 | publish after/alongside an agent job with no `environment:` gate | 0.2 |
83
+ | AWI-15 | agent step handed `mcp_config` / MCP servers (CI trifecta) | 0.3 |
84
+
85
+ Findings carry real `file:line` of the agent step. A workflow that does not parse is a loud warning, not a silent skip.
86
+
87
+ Not yet: INS-01..04 (instruction-file hygiene in repos), GitHub Action wrapper, `--follow-remote`.
88
+
89
+ ## What you will not see
90
+
91
+ A 0–100 score. A badge. Telemetry. A working exploit. An Airlock pitch.
92
+
93
+ The report ends with **what this scan cannot see** — that list *is* the pentest offer.
94
+
95
+ ## Verdicts
96
+
97
+ `reachable` (trigger + agent + sink) · `plausible` (untrusted field in the prompt) · `adjacent` (one piece of the chain). Severity only on the first two.
98
+
99
+ MIT. Python ≥ 3.11. PyYAML.
100
+
101
+ ```
102
+ python3 tests/run.py # regression suite (41 checks)
103
+ python3 tests/adversarial.py # parser fuzz, FP/FN matrix, recursion, ReDoS, CLI
104
+ python3 tests/matrix.py # negative matrix per detector, GitHub semantics, live corpus
105
+ ```
@@ -0,0 +1,11 @@
1
+ """agentpipe — scan agentic CI for untrusted-text -> agent -> secret chains."""
2
+ # Single source of truth is pyproject; read from installed metadata so
3
+ # `agentpipe --version` never drifts from the released package.
4
+ try:
5
+ from importlib.metadata import PackageNotFoundError, version as _v
6
+ try:
7
+ __version__ = _v("agentpipe-scan")
8
+ except PackageNotFoundError:
9
+ __version__ = "0.0.0+source"
10
+ except Exception: # pragma: no cover
11
+ __version__ = "0.0.0+source"
@@ -0,0 +1,164 @@
1
+ """agentpipe — untrusted GitHub text → CI agent → secret/write."""
2
+ from __future__ import annotations
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ from . import __version__
9
+ from . import prove, remote, local
10
+ from .detect import scan_tree
11
+ from .report import render
12
+
13
+
14
+ def _resolve(target: str, token: str | None) -> tuple[Path, str] | None:
15
+ """Local path or remote repo → (root, label). Prints errors, None on fail."""
16
+ if remote.is_remote_target(target):
17
+ try:
18
+ root, ref = remote.fetch_repo(target, token=token)
19
+ except remote.RemoteError as e:
20
+ print(f"agentpipe: {e}", file=sys.stderr)
21
+ return None
22
+ print(f"agentpipe: remote scan {ref} — public files only", file=sys.stderr)
23
+ return root, target
24
+ root = Path(target)
25
+ if not root.exists():
26
+ print(f"agentpipe: {root} not found "
27
+ f"(for remote: agentpipe scan github.com/owner/repo)", file=sys.stderr)
28
+ return None
29
+ return root, target
30
+
31
+
32
+ def _scan_one(root: Path) -> tuple[list, list[str]]:
33
+ errors: list[str] = []
34
+ findings = scan_tree(root, errors=errors)
35
+ for e in errors:
36
+ print(f"agentpipe: warning: {e}", file=sys.stderr)
37
+ return findings, errors
38
+
39
+
40
+ def _fail_code(findings, fail_on: str) -> int:
41
+ highs = any(f.severity == "high" for f in findings)
42
+ meds = any(f.severity == "medium" for f in findings)
43
+ if fail_on == "high" and highs:
44
+ return 1
45
+ if fail_on == "medium" and (highs or meds):
46
+ return 1
47
+ return 0
48
+
49
+
50
+ def _scan_org(target: str, token: str | None, max_repos: int,
51
+ json_out: bool) -> int:
52
+ org = remote.org_name(target)
53
+ try:
54
+ repos = remote.list_org_repos(org, token=token, max_repos=max_repos)
55
+ except remote.RemoteError as e:
56
+ print(f"agentpipe: {e}", file=sys.stderr)
57
+ return 2
58
+ print(f"agentpipe: org {org} — {len(repos)} public repos queued",
59
+ file=sys.stderr)
60
+ agg: dict[str, list] = {}
61
+ any_high = False
62
+ for full in repos:
63
+ try:
64
+ root, ref = remote.fetch_repo(f"github.com/{full}", token=token)
65
+ except remote.RemoteError as e:
66
+ print(f"agentpipe: {full}: {e}", file=sys.stderr)
67
+ continue
68
+ findings, _err = _scan_one(root)
69
+ agg[full] = findings
70
+ sev = [f for f in findings if f.severity]
71
+ if sev:
72
+ h = sum(1 for f in sev if f.severity == "high")
73
+ m = sum(1 for f in sev if f.severity == "medium")
74
+ any_high = any_high or h > 0
75
+ print(f" {full}: {h} high {m} medium "
76
+ f"({', '.join(sorted({f.id for f in sev}))})", file=sys.stderr)
77
+ if json_out:
78
+ print(json.dumps({r: [f.to_dict() for f in fs] for r, fs in agg.items()},
79
+ indent=2))
80
+ else:
81
+ print(f"\n== {org} org scan ==")
82
+ for full, fs in agg.items():
83
+ sev = [f for f in fs if f.severity]
84
+ if not sev:
85
+ continue
86
+ print(f"\n### {full}")
87
+ print(render(sev + [f for f in fs if not f.severity]))
88
+ return 1 if any_high else 0
89
+
90
+
91
+ def main(argv: list[str] | None = None) -> int:
92
+ p = argparse.ArgumentParser(
93
+ prog="agentpipe",
94
+ description="Find CI agents that eat untrusted GitHub events and hold keys.")
95
+ p.add_argument("--version", action="version", version=f"agentpipe {__version__}")
96
+ sub = p.add_subparsers(dest="cmd")
97
+ sc = sub.add_parser("scan", help="scan a repo, github.com/owner/repo or github.com/org")
98
+ sc.add_argument("path", nargs="?", default=".")
99
+ sc.add_argument("--json", action="store_true")
100
+ sc.add_argument("--token", default=None,
101
+ help="GitHub token for remote scan (or GITHUB_TOKEN/GH_TOKEN env)")
102
+ sc.add_argument("--max-repos", type=int, default=50,
103
+ help="org scan: cap on repos fetched")
104
+ sc.add_argument("--fail-on", default="high",
105
+ choices=["never", "high", "medium"],
106
+ help="exit 1 if findings at this severity exist")
107
+ pv = sub.add_parser("prove", help="generate a harmless canary kit for each finding")
108
+ pv.add_argument("path", nargs="?", default=".")
109
+ pv.add_argument("--token", default=None)
110
+ pv.add_argument("--json", action="store_true")
111
+ lc = sub.add_parser("local", help="audit agent configs on this machine (MCP, permissions, hooks)")
112
+ lc.add_argument("--root", default=None,
113
+ help="home dir to audit (default: your $HOME)")
114
+ lc.add_argument("--cwd", default=".",
115
+ help="project dir to audit (default: .)")
116
+ lc.add_argument("--json", action="store_true")
117
+ args = p.parse_args(sys.argv[1:] if argv is None else argv)
118
+ if args.cmd not in ("scan", "prove", "local"):
119
+ p.print_help()
120
+ return 2
121
+
122
+ if args.cmd == "local":
123
+ root = Path(args.root).expanduser() if args.root else Path.home()
124
+ cwd = Path(args.cwd).resolve()
125
+ errors: list[str] = []
126
+ findings = local.scan_local(root, cwd, errors=errors)
127
+ for e in errors:
128
+ print(f"agentpipe: warning: {e}", file=sys.stderr)
129
+ if args.json:
130
+ print(json.dumps([f.to_dict() for f in findings], indent=2))
131
+ else:
132
+ print(render(findings))
133
+ return _fail_code(findings, "high")
134
+
135
+ if args.cmd == "prove":
136
+ r = _resolve(args.path, args.token)
137
+ if r is None:
138
+ return 2
139
+ root, label = r
140
+ findings, _ = _scan_one(root)
141
+ if args.json:
142
+ print(json.dumps([prove.build(f) for f in findings
143
+ if f.severity in ("high", "medium")], indent=2))
144
+ else:
145
+ print(prove.render_kit(findings, label))
146
+ return 0
147
+
148
+ if remote.is_org_target(args.path) and not remote.is_remote_target(args.path):
149
+ return _scan_org(args.path, args.token, args.max_repos, args.json)
150
+
151
+ r = _resolve(args.path, args.token)
152
+ if r is None:
153
+ return 2
154
+ root, _label = r
155
+ findings, _ = _scan_one(root)
156
+ if args.json:
157
+ print(json.dumps([f.to_dict() for f in findings], indent=2))
158
+ else:
159
+ print(render(findings))
160
+ return _fail_code(findings, args.fail_on)
161
+
162
+
163
+ if __name__ == "__main__":
164
+ raise SystemExit(main())