buckthorn 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 (51) hide show
  1. buckthorn-0.1.0/.gitignore +2 -0
  2. buckthorn-0.1.0/.pre-commit-hooks.yaml +9 -0
  3. buckthorn-0.1.0/LICENSE +21 -0
  4. buckthorn-0.1.0/PKG-INFO +354 -0
  5. buckthorn-0.1.0/README.md +319 -0
  6. buckthorn-0.1.0/SPEC.md +197 -0
  7. buckthorn-0.1.0/buckthorn/__init__.py +1 -0
  8. buckthorn-0.1.0/buckthorn/__main__.py +3 -0
  9. buckthorn-0.1.0/buckthorn/cli.py +613 -0
  10. buckthorn-0.1.0/buckthorn/code.py +2018 -0
  11. buckthorn-0.1.0/buckthorn/env.py +191 -0
  12. buckthorn-0.1.0/buckthorn/findings.py +104 -0
  13. buckthorn-0.1.0/buckthorn/hf.py +745 -0
  14. buckthorn-0.1.0/buckthorn/js.py +1731 -0
  15. buckthorn-0.1.0/buckthorn/lock.py +345 -0
  16. buckthorn-0.1.0/buckthorn/mcp_config.py +1003 -0
  17. buckthorn-0.1.0/buckthorn/mcp_server.py +125 -0
  18. buckthorn-0.1.0/buckthorn/npm.py +891 -0
  19. buckthorn-0.1.0/buckthorn/scan.py +1270 -0
  20. buckthorn-0.1.0/docs/beyond-python-plan.md +151 -0
  21. buckthorn-0.1.0/docs/hf-remote-code.md +45 -0
  22. buckthorn-0.1.0/docs/rules.md +803 -0
  23. buckthorn-0.1.0/pyproject.toml +81 -0
  24. buckthorn-0.1.0/tests/conftest.py +77 -0
  25. buckthorn-0.1.0/tests/test_binaries.py +93 -0
  26. buckthorn-0.1.0/tests/test_call_time.py +276 -0
  27. buckthorn-0.1.0/tests/test_cli.py +180 -0
  28. buckthorn-0.1.0/tests/test_code.py +673 -0
  29. buckthorn-0.1.0/tests/test_diff.py +130 -0
  30. buckthorn-0.1.0/tests/test_docs.py +30 -0
  31. buckthorn-0.1.0/tests/test_env.py +186 -0
  32. buckthorn-0.1.0/tests/test_exfil.py +176 -0
  33. buckthorn-0.1.0/tests/test_false_clean.py +256 -0
  34. buckthorn-0.1.0/tests/test_findings.py +26 -0
  35. buckthorn-0.1.0/tests/test_hardening.py +103 -0
  36. buckthorn-0.1.0/tests/test_hf.py +585 -0
  37. buckthorn-0.1.0/tests/test_import.py +580 -0
  38. buckthorn-0.1.0/tests/test_integrity.py +105 -0
  39. buckthorn-0.1.0/tests/test_js.py +462 -0
  40. buckthorn-0.1.0/tests/test_lock.py +308 -0
  41. buckthorn-0.1.0/tests/test_mcp_config.py +641 -0
  42. buckthorn-0.1.0/tests/test_mcp_server.py +99 -0
  43. buckthorn-0.1.0/tests/test_npm.py +1267 -0
  44. buckthorn-0.1.0/tests/test_pth.py +226 -0
  45. buckthorn-0.1.0/tests/test_reader.py +59 -0
  46. buckthorn-0.1.0/tests/test_receipt.py +102 -0
  47. buckthorn-0.1.0/tests/test_report.py +202 -0
  48. buckthorn-0.1.0/tests/test_review_fixes.py +188 -0
  49. buckthorn-0.1.0/tests/test_sdist.py +796 -0
  50. buckthorn-0.1.0/tests/test_sdist_reader.py +76 -0
  51. buckthorn-0.1.0/tests/test_startup.py +71 -0
@@ -0,0 +1,2 @@
1
+ __pycache__/
2
+ .venv/
@@ -0,0 +1,9 @@
1
+ # files: matches the lockfiles `buckthorn check` reads; tests/test_report.py
2
+ # checks the pattern. Update both together.
3
+ - id: buckthorn-check
4
+ name: buckthorn check
5
+ description: Fetch every artifact a changed lockfile pins, check its hash, and scan it
6
+ entry: buckthorn check --
7
+ language: python
8
+ pass_filenames: true
9
+ files: '(^|/)(uv\.lock|poetry\.lock|requirements[^/]*\.txt)$'
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hedgerow
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,354 @@
1
+ Metadata-Version: 2.5
2
+ Name: buckthorn
3
+ Version: 0.1.0
4
+ Summary: Static checks for open-source Python and npm packages: finds install-time, start-up and import-time code before you install.
5
+ Project-URL: Homepage, https://github.com/hedgerow-dev/buckthorn
6
+ Project-URL: Source, https://github.com/hedgerow-dev/buckthorn
7
+ Project-URL: Issues, https://github.com/hedgerow-dev/buckthorn/issues
8
+ Author-email: Hedgerow <hello@hedgerow.dev>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: huggingface,lockfile,malware,mcp,npm,pypi,sarif,security,static-analysis,supply-chain
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Natural Language :: English
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Quality Assurance
26
+ Requires-Python: >=3.11
27
+ Requires-Dist: packaging>=24
28
+ Provides-Extra: dev
29
+ Requires-Dist: mcp<3,>=2.3; extra == 'dev'
30
+ Requires-Dist: pytest<9.0,>=8.0; extra == 'dev'
31
+ Requires-Dist: ruff<1.0,>=0.4; extra == 'dev'
32
+ Provides-Extra: mcp
33
+ Requires-Dist: mcp<3,>=2.3; extra == 'mcp'
34
+ Description-Content-Type: text/markdown
35
+
36
+ <!-- mcp-name: io.github.hedgerow-dev/buckthorn -->
37
+
38
+ <div align="center">
39
+
40
+ # Buckthorn
41
+
42
+ **See what a package runs before you install it.**
43
+
44
+ Static checks for Python and npm packages, MCP configs and Hugging Face remote code.<br>
45
+ Nothing is installed, imported or run.
46
+
47
+ ![License MIT](https://img.shields.io/badge/license-MIT-013D5A?style=flat-square&labelColor=013D5A)
48
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-013D5A?style=flat-square&labelColor=013D5A)
49
+ ![Status 0.1 preview](https://img.shields.io/badge/status-0.1_preview-708C69?style=flat-square&labelColor=013D5A)
50
+ ![Code it runs: none](https://img.shields.io/badge/code_it_runs-none-F4A25B?style=flat-square&labelColor=013D5A)
51
+
52
+ </div>
53
+
54
+ ```console
55
+ $ buckthorn scan colourful_logs-1.4.2-py3-none-any.whl
56
+ colourful_logs-1.4.2-py3-none-any.whl: flagged
57
+ high BKT-HIDE-001 colourful_logs/__init__.py:2 exec of data decoded by base64.b64decode
58
+ medium BKT-PTH-001 colourful_logs-1.4.2.pth:1 .pth line runs code at every Python start
59
+
60
+ 1 scanned: 1 flagged
61
+ ```
62
+
63
+ A package can run code the moment you install it, every time Python starts,
64
+ or as soon as you import it. Buckthorn reads that code first, straight from
65
+ the wheel, sdist or npm tarball, and tells you what it does.
66
+
67
+ ## What it is for
68
+
69
+ **A quiet CI gate.** `buckthorn check uv.lock` reads every pinned file before
70
+ anything is installed. On packages it had never seen, it raised about a
71
+ quarter of GuardDog's false alarms ([numbers below](#how-well-it-works)).
72
+
73
+ **Upgrades.** `buckthorn diff requests==2.32.3 requests==2.32.4` shows only
74
+ what the new version adds. If a maintainer account is taken over, the new
75
+ code is in that diff.
76
+
77
+ **Your agent's MCP config** (preview). An agent starts every server in
78
+ `.mcp.json` with your credentials, and `uvx some-server` pulls whatever was
79
+ released that day, dependencies included. `buckthorn check .mcp.json` reads
80
+ that install set.
81
+
82
+ ## Install
83
+
84
+ Needs Python 3.11 or newer.
85
+
86
+ ```bash
87
+ pipx install buckthorn # or: pip install buckthorn
88
+ uvx buckthorn --help # or run it without installing
89
+ ```
90
+
91
+ ```bash
92
+ buckthorn scan pkg-1.2.0-py3-none-any.whl # one wheel or sdist
93
+ buckthorn scan ./dist # a folder of them
94
+ buckthorn scan left-pad-1.3.0.tgz # an npm tarball (preview)
95
+ buckthorn check uv.lock # every pinned dependency
96
+ buckthorn check .mcp.json # an agent's MCP servers (preview)
97
+ buckthorn diff requests==2.32.3 requests==2.32.4 # only what an upgrade adds
98
+ buckthorn scan --format json ./dist # machine-readable
99
+ ```
100
+
101
+ - `check` reads `requirements.txt` with hashes, `uv.lock` and `poetry.lock`.
102
+ - `check` and `diff` fetch from PyPI over https only (pypi.org and
103
+ files.pythonhosted.org), and check each file's sha256 before reading it.
104
+ - By default `check` reads the file this machine would install for each
105
+ package. `--all-files` reads every platform's.
106
+
107
+ ## What the verdict means
108
+
109
+ | Verdict | Meaning |
110
+ |---|---|
111
+ | `clean` | Nothing flagged in what runs at install, at start-up or at import. Code that only runs when you call it is not read, so `clean` is not "safe". |
112
+ | `flagged` | At least one finding above info. Read it, then fix or accept it. |
113
+ | `not_verified` | Something could not be read. Never reported as clean. |
114
+
115
+ Exit codes: 0 clean, 1 flagged or not_verified (`--allow-not-verified` lets
116
+ not_verified pass), 2 a usage or input error.
117
+
118
+ ## In CI
119
+
120
+ The GitHub Action checks a lockfile before anything is installed. It fails
121
+ the build on a finding and writes SARIF for code scanning:
122
+
123
+ ```yaml
124
+ permissions:
125
+ contents: read
126
+ security-events: write # for the SARIF upload
127
+
128
+ steps:
129
+ - uses: actions/checkout@v4
130
+ - uses: hedgerow-dev/buckthorn@v0.1.0
131
+ with:
132
+ lockfile: uv.lock
133
+ - uses: github/codeql-action/upload-sarif@v3
134
+ if: always()
135
+ with:
136
+ sarif_file: buckthorn.sarif
137
+ ```
138
+
139
+ - **Python version.** The check reads the files pip would pick for your
140
+ project's Python: the repository's `.python-version`, or 3.12 when there is
141
+ none. Set `python-version` if your project installs with another one.
142
+ - **Pin by SHA.** Tags are shown here for reading. For a security check, pin
143
+ each action to a commit SHA instead, as `action.yml` does for its own steps.
144
+ - **All inputs**, including `allowlist` and signed receipts, are in
145
+ [action.yml](https://github.com/hedgerow-dev/buckthorn/blob/main/action.yml).
146
+
147
+ **The first run.** A real lockfile often has a package or two that does one
148
+ of these things on purpose, like setuptools' `.pth` file. Accept what is
149
+ there today once, then only new behaviour fails the build:
150
+
151
+ ```bash
152
+ buckthorn check uv.lock --write-allowlist buckthorn-allow.json
153
+ ```
154
+
155
+ Read the file before you commit it, and pass it as the action's `allowlist`.
156
+ Each entry is pinned to the version it was found in, so an upgrade that keeps
157
+ the same behaviour shows up again for review.
158
+
159
+ **Pre-commit.** The hook runs whenever `uv.lock`, `poetry.lock` or a
160
+ `requirements*.txt` changes:
161
+
162
+ ```yaml
163
+ repos:
164
+ - repo: https://github.com/hedgerow-dev/buckthorn
165
+ rev: v0.1.0
166
+ hooks:
167
+ - id: buckthorn-check
168
+ ```
169
+
170
+ ## How well it works
171
+
172
+ We tested it on packages it had never seen, with the plan committed before
173
+ the first scan
174
+ ([PROTOCOL.md](https://github.com/hedgerow-dev/buckthorn/blob/main/eval/heldout/PROTOCOL.md)).
175
+ That run used commit `c80b090`, from before the last fixes in 0.1.0.
176
+
177
+ | On unseen packages | Buckthorn | GuardDog 3.2.0 |
178
+ |---|---|---|
179
+ | Malicious archives flagged (430) | 52.3% | 68.6% |
180
+ | Benign files flagged (5,723) | 5.4% | 23.7% |
181
+
182
+ - **Quiet on real projects.** Per project, Buckthorn flagged 8.8% of PyPI's
183
+ ranks 1,001 to 3,000 and 5.4% of recently updated projects. So expect a
184
+ flag or two on a real lockfile the first time; `--write-allowlist` is for
185
+ that.
186
+ - **It misses more malware than GuardDog.** Most of what it misses runs only
187
+ when you call a function, like a downloader behind `fetch(url)`. Of 50
188
+ misses we looked at, only one was install, start-up or import code a rule
189
+ should have caught. In our view it works best next to a feed of known
190
+ malware, such as OSV's malicious-packages data, and a broader scanner.
191
+ - **Tuning data is not the headline.** On the corpora we tuned on, it flags
192
+ about 90% of pypi_malregistry and 85% of DataDog's malicious PyPI samples.
193
+ The rules were written against that data, so those numbers say less.
194
+
195
+ The full write-up is in
196
+ [eval/heldout/RESULTS.md](https://github.com/hedgerow-dev/buckthorn/blob/main/eval/heldout/RESULTS.md).
197
+
198
+ `BUCKTHORN_CALL_TIME=1` also reads code that only runs when called, and flags
199
+ five combinations, such as fetching code and running it. It is off by
200
+ default, because it has not been tested on unseen data yet.
201
+
202
+ ## Also in preview
203
+
204
+ ### An agent's MCP config
205
+
206
+ An agent starts every MCP server in its config as soon as it loads it, with
207
+ your credentials, and nobody looks at what `uvx some-server` pulls in that
208
+ day. Point `check` at the config:
209
+
210
+ ```bash
211
+ buckthorn check .mcp.json # Claude Code
212
+ buckthorn check .vscode/mcp.json # VS Code
213
+ buckthorn check ~/.cursor/mcp.json # Cursor (Windsurf and Claude Desktop too)
214
+ ```
215
+
216
+ - For each server launched with `uvx`, `uv run --with` or `pipx run`, it
217
+ fetches the PyPI release that would run and scans it, then every package
218
+ that `uvx` or `pipx` would install with it.
219
+ - Dependencies come from the release's static metadata (`Requires-Dist`),
220
+ never from installing or building the package.
221
+ - A dependency with no exact version pin is counted in the summary: the
222
+ newest match was checked, and a later release is what the next start
223
+ installs. Servers with no version pinned are counted too.
224
+ - npm and Docker servers are reported as not checked yet.
225
+ - Values from `env`, arguments and URLs are never printed.
226
+
227
+ ### npm packages
228
+
229
+ `scan` reads npm tarballs too: the `.tgz` the registry serves, or what
230
+ `npm pack` writes.
231
+
232
+ ```bash
233
+ npm pack left-pad@1.3.0 && buckthorn scan left-pad-1.3.0.tgz
234
+ ```
235
+
236
+ It reads the scripts in `package.json`, the JavaScript that `preinstall`,
237
+ `install` and `postinstall` run, and the code that runs when the package is
238
+ loaded. `package-lock.json` is not read yet. npm support is newer than the
239
+ Python side: it was tuned on the top 1,000 npm packages and 200 malicious
240
+ ones, and has not been tested on unseen packages. The rules are the
241
+ `BKT-NPM-*` ones in
242
+ [docs/rules.md](https://github.com/hedgerow-dev/buckthorn/blob/main/docs/rules.md#npm).
243
+
244
+ ### Model repos with remote code
245
+
246
+ `trust_remote_code=True` runs the model repo's own Python when you load it.
247
+ Buckthorn reads that code first: the files `auto_map` names, what they import,
248
+ and the methods transformers calls while loading (`__init__`, `post_init`,
249
+ `_init_weights` and the rest). This part is new, and we have not published
250
+ an evaluation on real repos yet.
251
+
252
+ ```bash
253
+ buckthorn hf org/name@<commit> # fetch config and code only, never weights
254
+ buckthorn hf org/name # reads main today, tells you its commit
255
+ buckthorn scan ./my-model # a downloaded repo or a Hub cache snapshot
256
+ ```
257
+
258
+ `hf` talks to huggingface.co only, fetches by commit and checks each file
259
+ against the Hub's blob id. Pin that commit in `from_pretrained(revision=...)`,
260
+ since a verdict for one commit says nothing about the next. `forward` and
261
+ `generate` run only when you call them, so they are not read. Rules are in
262
+ [docs/rules.md](https://github.com/hedgerow-dev/buckthorn/blob/main/docs/rules.md#hugging-face-remote-code); how this could plug
263
+ into Hayward is in [docs/hf-remote-code.md](https://github.com/hedgerow-dev/buckthorn/blob/main/docs/hf-remote-code.md).
264
+
265
+ ## Reference
266
+
267
+ <details>
268
+ <summary><b>Accepting a finding</b></summary>
269
+
270
+ <br>
271
+
272
+ Some real packages do what Buckthorn looks for on purpose: setuptools and
273
+ coverage.py install `.pth` files that run at start-up. Once you have looked
274
+ at one, record it in an allowlist and pass `--allowlist allow.json`:
275
+
276
+ ```json
277
+ {
278
+ "allow": [
279
+ {
280
+ "rule": "BKT-PTH-001",
281
+ "package": "setuptools",
282
+ "file": "distutils-precedence.pth",
283
+ "reason": "setuptools' distutils shim; reviewed 2026-11-03"
284
+ }
285
+ ]
286
+ }
287
+ ```
288
+
289
+ `rule`, `package` and `reason` are required. `file` is a glob, matched with
290
+ the version folder taken out (`*/setup.py` matches `pkg-2.0/setup.py`), and
291
+ `version` pins the entry to one release. Allowed findings leave the verdict
292
+ but stay in the JSON report with their reason. Coverage gaps (`BKT-SKIP-*`,
293
+ `BKT-LOCK-002`) cannot be allowed: they mean something was not read.
294
+
295
+ For an npm tarball, `package` is the name in the file name. The registry
296
+ names `@scope/pkg` as `pkg-1.0.0.tgz`, so an entry for `pkg` also covers
297
+ another scope's `pkg`. Pin `version` to keep it narrow.
298
+
299
+ </details>
300
+
301
+ <details>
302
+ <summary><b>Output formats</b></summary>
303
+
304
+ <br>
305
+
306
+ `--format text` (default), `json`, or `sarif` for GitHub code scanning.
307
+
308
+ The JSON report carries a `schema_version`. It goes up when a key changes
309
+ meaning or is removed. New keys can appear in any release.
310
+
311
+ </details>
312
+
313
+ <details>
314
+ <summary><b>Scan receipts</b></summary>
315
+
316
+ <br>
317
+
318
+ `--receipt FILE` also writes an unsigned in-toto statement: each artifact's
319
+ sha256 and what Buckthorn found in it, taken before `--allowlist`. It has the
320
+ same shape as Hayward's receipts. It is analysis evidence, not a safety
321
+ certificate. In GitHub Actions, set the action's `receipt` and `attest:
322
+ "true"` inputs to have GitHub sign it with Sigstore.
323
+
324
+ </details>
325
+
326
+ <details>
327
+ <summary><b>For coding agents (MCP server)</b></summary>
328
+
329
+ <br>
330
+
331
+ ```bash
332
+ pip install "buckthorn[mcp]"
333
+ buckthorn mcp
334
+ ```
335
+
336
+ A stdio MCP server with three read-only tools, all returning the same JSON as
337
+ `--format json`:
338
+
339
+ - `scan_path`: a wheel, sdist or folder of them, no network.
340
+ - `check_release`: a PyPI `name` and `version`. The file this machine would
341
+ install, fetched and hash-checked as `check` does.
342
+ - `check_mcp_config`: the text of an MCP config, checked as `check` does.
343
+
344
+ </details>
345
+
346
+ Every rule is listed in
347
+ [docs/rules.md](https://github.com/hedgerow-dev/buckthorn/blob/main/docs/rules.md),
348
+ and the design is in
349
+ [SPEC.md](https://github.com/hedgerow-dev/buckthorn/blob/main/SPEC.md).
350
+
351
+ ---
352
+
353
+ Buckthorn is MIT licensed and part of [Hedgerow](https://hedgerow.dev), next
354
+ to [Hayward](https://github.com/hedgerow-dev/hayward) for model files.