modelbom 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 (50) hide show
  1. modelbom-0.1.0/.gitignore +27 -0
  2. modelbom-0.1.0/CHANGELOG.md +29 -0
  3. modelbom-0.1.0/CITATION.cff +33 -0
  4. modelbom-0.1.0/LICENSE +202 -0
  5. modelbom-0.1.0/NOTICE +14 -0
  6. modelbom-0.1.0/PKG-INFO +265 -0
  7. modelbom-0.1.0/README.md +232 -0
  8. modelbom-0.1.0/docs/demo.svg +9 -0
  9. modelbom-0.1.0/docs/methodology.md +128 -0
  10. modelbom-0.1.0/docs/rules.md +206 -0
  11. modelbom-0.1.0/examples/safe-app/app.py +23 -0
  12. modelbom-0.1.0/examples/safe-app/requirements.txt +5 -0
  13. modelbom-0.1.0/examples/vulnerable-app/data.py +12 -0
  14. modelbom-0.1.0/examples/vulnerable-app/download.py +10 -0
  15. modelbom-0.1.0/examples/vulnerable-app/rag.py +7 -0
  16. modelbom-0.1.0/examples/vulnerable-app/requirements.txt +8 -0
  17. modelbom-0.1.0/examples/vulnerable-app/serve.py +14 -0
  18. modelbom-0.1.0/examples/vulnerable-app/tokenizer_config.json +4 -0
  19. modelbom-0.1.0/examples/vulnerable-app/train.py +21 -0
  20. modelbom-0.1.0/pyproject.toml +86 -0
  21. modelbom-0.1.0/src/modelbom/__init__.py +9 -0
  22. modelbom-0.1.0/src/modelbom/__main__.py +5 -0
  23. modelbom-0.1.0/src/modelbom/artifacts.py +696 -0
  24. modelbom-0.1.0/src/modelbom/attack_paths.py +202 -0
  25. modelbom-0.1.0/src/modelbom/cli.py +202 -0
  26. modelbom-0.1.0/src/modelbom/code_rules.py +642 -0
  27. modelbom-0.1.0/src/modelbom/deps.py +461 -0
  28. modelbom-0.1.0/src/modelbom/discovery.py +126 -0
  29. modelbom-0.1.0/src/modelbom/graph.py +257 -0
  30. modelbom-0.1.0/src/modelbom/models.py +201 -0
  31. modelbom-0.1.0/src/modelbom/pickle_scan.py +417 -0
  32. modelbom-0.1.0/src/modelbom/py.typed +0 -0
  33. modelbom-0.1.0/src/modelbom/report/__init__.py +16 -0
  34. modelbom-0.1.0/src/modelbom/report/cyclonedx.py +219 -0
  35. modelbom-0.1.0/src/modelbom/report/jsonfmt.py +78 -0
  36. modelbom-0.1.0/src/modelbom/report/sarif.py +110 -0
  37. modelbom-0.1.0/src/modelbom/report/text.py +60 -0
  38. modelbom-0.1.0/src/modelbom/rules.py +350 -0
  39. modelbom-0.1.0/src/modelbom/scanner.py +77 -0
  40. modelbom-0.1.0/tests/__init__.py +1 -0
  41. modelbom-0.1.0/tests/fixtures.py +144 -0
  42. modelbom-0.1.0/tests/test_artifacts.py +160 -0
  43. modelbom-0.1.0/tests/test_cli.py +100 -0
  44. modelbom-0.1.0/tests/test_code_rules.py +239 -0
  45. modelbom-0.1.0/tests/test_deps.py +157 -0
  46. modelbom-0.1.0/tests/test_discovery.py +64 -0
  47. modelbom-0.1.0/tests/test_graph_paths.py +141 -0
  48. modelbom-0.1.0/tests/test_pickle_scan.py +116 -0
  49. modelbom-0.1.0/tests/test_reports.py +116 -0
  50. modelbom-0.1.0/tests/test_safety.py +46 -0
@@ -0,0 +1,27 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ .python-version
11
+
12
+ # Tooling
13
+ .pytest_cache/
14
+ .ruff_cache/
15
+ .mypy_cache/
16
+ .coverage
17
+ htmlcov/
18
+
19
+ # modelbom output
20
+ *.sarif
21
+ aibom*.json
22
+ *.cdx.json
23
+
24
+ # Editors / OS
25
+ .idea/
26
+ .vscode/
27
+ .DS_Store
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-11-30
10
+
11
+ ### Added
12
+
13
+ - Notebook scanning neutralises IPython magics and multi-line shell escapes before parsing.
14
+ - Syntax warnings raised by scanned code are no longer printed.
15
+ - MB301 reports unpinned ranges in `pyproject.toml` as `info` (library metadata) and keeps
16
+ `low` for requirements files.
17
+
18
+ - `modelbom scan` with text, JSON and SARIF 2.1.0 output, `--fail-on` thresholds and documented exit codes.
19
+ - Source-code rules MB100–MB110 for Python files and Jupyter notebooks (`ast`-based, alias-aware).
20
+ - Artifact inspection for pickle, PyTorch (zip, TorchScript, legacy), joblib (zlib/gzip/bz2/xz), NumPy, Keras (`.keras`, `.h5`), safetensors, GGUF, ONNX, model configs, chat templates and dataset files (MB201–MB208).
21
+ - Static pickle analysis with `pickletools.genops` and a stack model that resolves `GLOBAL`, `INST` and `STACK_GLOBAL` (including memoized operands).
22
+ - Dependency parsing for requirements files, `pyproject.toml`, `Pipfile` and lock files; pinning rule MB301; optional OSV.dev lookups (MB302/MB303).
23
+ - Dependency graph and attack-path engine with eight path rules; Mermaid, DOT and JSON export (`modelbom graph`).
24
+ - CycloneDX 1.6 AI-BOM output (`modelbom bom`).
25
+ - Inline (`# modelbom: ignore[...]`) and `.modelbomignore` suppressions, including rule-scoped globs.
26
+ - Composite GitHub Action and pre-commit hook.
27
+
28
+ [Unreleased]: https://github.com/rajyavardhan01/modelbom/compare/v0.1.0...HEAD
29
+ [0.1.0]: https://github.com/rajyavardhan01/modelbom/releases/tag/v0.1.0
@@ -0,0 +1,33 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below, and cite the article it implements."
3
+ type: software
4
+ title: "modelbom: AI supply-chain scanner and CycloneDX AI-BOM generator"
5
+ version: 0.1.0
6
+ date-released: 2026-11-30
7
+ license: Apache-2.0
8
+ repository-code: "https://github.com/rajyavardhan01/modelbom"
9
+ keywords:
10
+ - ai-security
11
+ - supply-chain-security
12
+ - machine-learning
13
+ - sbom
14
+ - cyclonedx
15
+ authors:
16
+ - family-names: Handa
17
+ given-names: Rajyavardhan
18
+ orcid: "https://orcid.org/0000-0002-5247-7880"
19
+ references:
20
+ - type: article
21
+ title: "Securing the Intelligent Software Supply Chain: Vulnerability Detection and Exploit Pathways in AI-Integrated Systems"
22
+ authors:
23
+ - family-names: Handa
24
+ given-names: Rajyavardhan
25
+ orcid: "https://orcid.org/0000-0002-5247-7880"
26
+ journal: "Journal of Computational Analysis and Applications"
27
+ volume: 34
28
+ issue: 12
29
+ start: 46
30
+ end: 56
31
+ year: 2025
32
+ doi: "10.48047/jocaaa.2025.34.12.06"
33
+ url: "https://eudoxuspress.com/index.php/pub/article/view/4301"
modelbom-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
modelbom-0.1.0/NOTICE ADDED
@@ -0,0 +1,14 @@
1
+ modelbom
2
+ Copyright 2026 Rajyavardhan Handa
3
+
4
+ This product includes software developed by Rajyavardhan Handa
5
+ (https://github.com/rajyavardhan01).
6
+
7
+ Third-party references:
8
+ - MITRE ATLAS technique identifiers (https://atlas.mitre.org/; data licensed under
9
+ Apache-2.0, (c) The MITRE Corporation) are referenced by ID only.
10
+ - OWASP Top 10 for LLM Applications 2025 and OWASP Top 10 for Agentic Applications 2026
11
+ (https://genai.owasp.org/; CC BY-SA 4.0) are referenced by ID and title only.
12
+ - CWE identifiers (https://cwe.mitre.org/) are referenced by ID only.
13
+ - CycloneDX (https://cyclonedx.org/) and SARIF (OASIS) are open specifications implemented
14
+ as output formats; no specification text is included.
@@ -0,0 +1,265 @@
1
+ Metadata-Version: 2.5
2
+ Name: modelbom
3
+ Version: 0.1.0
4
+ Summary: Find unsafe model loading, poisoned artifacts and unpinned AI dependencies, and emit a CycloneDX AI-BOM. Zero dependencies; never loads what it scans.
5
+ Project-URL: Homepage, https://github.com/rajyavardhan01/modelbom
6
+ Project-URL: Repository, https://github.com/rajyavardhan01/modelbom
7
+ Project-URL: Issues, https://github.com/rajyavardhan01/modelbom/issues
8
+ Project-URL: Documentation, https://github.com/rajyavardhan01/modelbom/tree/main/docs
9
+ Project-URL: Changelog, https://github.com/rajyavardhan01/modelbom/blob/main/CHANGELOG.md
10
+ Author: Rajyavardhan Handa
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ License-File: NOTICE
14
+ Keywords: ai-security,aibom,cyclonedx,huggingface,ml-security,pickle,pytorch,sarif,sbom,supply-chain-security
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Information Technology
19
+ Classifier: Intended Audience :: Science/Research
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Programming Language :: Python :: 3.14
27
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
28
+ Classifier: Topic :: Security
29
+ Classifier: Topic :: Software Development :: Quality Assurance
30
+ Classifier: Typing :: Typed
31
+ Requires-Python: >=3.11
32
+ Description-Content-Type: text/markdown
33
+
34
+ # modelbom
35
+
36
+ **Find unsafe model loading, poisoned artifacts and unpinned AI dependencies, and emit a CycloneDX AI-BOM. Zero dependencies; never loads what it scans.**
37
+
38
+ [![CI](https://github.com/rajyavardhan01/modelbom/actions/workflows/ci.yml/badge.svg)](https://github.com/rajyavardhan01/modelbom/actions/workflows/ci.yml)
39
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
40
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)
41
+
42
+ <p align="center"><img src="docs/demo.svg" alt="modelbom scanning an example project and reporting findings and attack paths" width="860"></p>
43
+
44
+ Status: alpha (v0.1.0). Rule IDs and the JSON schema may still change before 1.0.
45
+
46
+ ---
47
+
48
+ AI systems pull code and data through channels that classic dependency scanners don't see:
49
+ model weights downloaded from a hub, `trust_remote_code=True`, pickled checkpoints, tokenizer
50
+ chat templates, vector indexes saved with pickle, and datasets fetched at training time.
51
+ `modelbom` inventories those components and flags the ones that can execute code or silently
52
+ change underneath you. It covers three layers in one pass:
53
+
54
+ | Layer | What modelbom looks at |
55
+ |---|---|
56
+ | **Source code** (`.py`, `.ipynb`) | `trust_remote_code`, hub loads without a pinned `revision`, `torch.load` without `weights_only=True`, pickle-family loaders, Keras `safe_mode=False`, unsafe YAML, unverified downloads, `torch.hub.load`, `allow_dangerous_deserialization=True` |
57
+ | **Artifacts** | Pickle, PyTorch (zip and legacy), joblib (incl. zlib/gzip/bz2/xz), NumPy `.npy`/`.npz`, Keras `.keras`/`.h5`, safetensors, GGUF, ONNX, model `config.json`, tokenizer chat templates, dataset files |
58
+ | **Dependencies** | `requirements*.txt`, `pyproject.toml` (PEP 621, PEP 735, Poetry), `Pipfile`, and `uv.lock` / `poetry.lock` / `pdm.lock` / `Pipfile.lock`; optional OSV.dev lookups |
59
+
60
+ It then connects the findings into **attack paths** (for example *unpinned hub model* +
61
+ *`trust_remote_code=True`* in the same call ⇒ *upstream repository change executes code at load
62
+ time*), and writes text, JSON, SARIF 2.1.0 or a CycloneDX 1.6 AI-BOM.
63
+
64
+ **Safety model.** modelbom never imports, unpickles, or otherwise loads what it scans. Pickles
65
+ are decoded opcode by opcode with `pickletools.genops`; archives are read with `zipfile`;
66
+ headers are parsed with `struct` and `json`. The package has no runtime dependencies, and a
67
+ test asserts that its own source never calls a deserializer.
68
+
69
+ ## Quickstart
70
+
71
+ ```bash
72
+ pip install git+https://github.com/rajyavardhan01/modelbom
73
+ modelbom scan path/to/your/project
74
+ ```
75
+
76
+ From a source checkout, nothing needs to be installed:
77
+
78
+ ```bash
79
+ git clone https://github.com/rajyavardhan01/modelbom && cd modelbom
80
+ PYTHONPATH=src python -m modelbom scan examples/vulnerable-app
81
+ ```
82
+
83
+ Excerpt of the output for the bundled, intentionally insecure example (run offline):
84
+
85
+ ```text
86
+ modelbom 0.1.0 · scanned examples/vulnerable-app
87
+ 7 files · 5 code files · 1 artifacts · 6 hub references · 8 dependencies
88
+
89
+ HIGH
90
+ MB103 download.py:10
91
+ torch.load(..., weights_only=False) unpickles arbitrary objects
92
+ fix: Call torch.load(path, weights_only=True) explicitly and prefer safetensors for weights.
93
+ MB109 rag.py:7
94
+ allow_dangerous_deserialization=True in FAISS.load_local() unpickles the stored index
95
+ ...
96
+ MB101 train.py:12
97
+ trust_remote_code=True in AutoModelForSequenceClassification.from_pretrained() executes code shipped with the model
98
+
99
+ MEDIUM
100
+ MB102 data.py:6
101
+ dataset 'example-org/product-reviews' loaded via load_dataset() without revision=
102
+ ...
103
+
104
+ ATTACK PATHS
105
+ AP-1 [critical] Upstream repository change executes code at load time
106
+ precondition: adversary can push to, take over or impersonate 'example-org/sentiment-model'
107
+ 1. MB102 train.py:12: model 'example-org/sentiment-model' loaded via from_pretrained() without revision=
108
+ 2. MB101 train.py:12: trust_remote_code=True in AutoModelForSequenceClassification.from_pretrained() executes code shipped with the model
109
+ impact: arbitrary code execution in the process that runs train.py
110
+ AP-5 [high] Unverified download is deserialized
111
+ precondition: adversary controls the download host, a mirror, DNS or the network path
112
+ 1. MB107 download.py:7: urllib.request.urlretrieve('https://models.example.com/releases/classifier.bin') fetches a model/data file without verifying a checksum
113
+ 2. MB103 download.py:10: torch.load(..., weights_only=False) unpickles arbitrary objects
114
+ impact: arbitrary code execution when download.py unpickles the substituted file
115
+
116
+ Summary: 8 high · 6 medium · 4 low · 5 attack paths (1 suppressed)
117
+ ```
118
+
119
+ `examples/safe-app` performs the same tasks safely and scans clean offline (exit code 0). With `--online` it reports the advisories published against its pinned versions.
120
+
121
+ ## Usage
122
+
123
+ ```text
124
+ modelbom scan PATH [--format text|json|sarif] [-o FILE] [--fail-on LEVEL] [--online]
125
+ [--exclude GLOB ...] [--no-hash] [--max-bytes N] [--verbose] [--no-color]
126
+ modelbom bom PATH [-o aibom.cdx.json] [--online] [--exclude GLOB ...]
127
+ modelbom graph PATH [--format mermaid|dot|json] [-o FILE]
128
+ modelbom rules [--format text|json|markdown]
129
+ modelbom version
130
+ ```
131
+
132
+ | Exit code | Meaning |
133
+ |---|---|
134
+ | 0 | No unsuppressed finding at or above `--fail-on` (default `high`) |
135
+ | 1 | At least one unsuppressed finding at or above `--fail-on` |
136
+ | 2 | Usage error (bad arguments, missing path) |
137
+
138
+ Inventory records (`MB206`) never affect the exit code.
139
+
140
+ ### Rules
141
+
142
+ 22 rules in three families: code (`MB1xx`), artifacts (`MB2xx`) and dependencies (`MB3xx`).
143
+ Each carries OWASP Top 10 for LLM Applications 2025, OWASP Top 10 for Agentic Applications
144
+ 2026, MITRE ATLAS and CWE references. See [docs/rules.md](docs/rules.md) or run
145
+ `modelbom rules`.
146
+
147
+ ### Suppressing findings
148
+
149
+ - Inline, on the flagged line (or any line of a multi-line call):
150
+ `torch.load(p) # modelbom: ignore[MB103]` or `# modelbom: ignore` for all rules.
151
+ The same comment works in `requirements.txt` and `pyproject.toml`.
152
+ - `.modelbomignore` in the scan root:
153
+
154
+ ```text
155
+ data/raw/ # skip a directory
156
+ *.ckpt # skip by name
157
+ MB202:models/*.pkl # keep scanning, but suppress MB202 for these files
158
+ ```
159
+
160
+ Suppressed findings are still counted in the summary and appear in SARIF with a
161
+ `suppressions` entry.
162
+
163
+ ### Output formats
164
+
165
+ - **text**: grouped by severity, with remediation and attack paths. Colors only on a TTY; respects `NO_COLOR`.
166
+ - **json**: stable `schema_version: 1` document with findings, artifacts, hub references, dependencies and attack paths.
167
+ - **sarif**: SARIF 2.1.0 with rule metadata, `security-severity` and partial fingerprints, ready for GitHub code scanning.
168
+ - **CycloneDX 1.6 AI-BOM** (`modelbom bom`): `machine-learning-model`, `data`, `file` and `library` components with SHA-256 hashes, `pkg:pypi` / `pkg:huggingface` purls and a `vulnerabilities` section for findings attached to components.
169
+ - **graph** (`modelbom graph`): Mermaid, Graphviz DOT or JSON. Attack paths are drawn as dashed `AP-n` edges and risky nodes are highlighted.
170
+
171
+ ### Online vulnerability lookups
172
+
173
+ `--online` queries [OSV.dev](https://osv.dev) for every exactly pinned dependency (from
174
+ manifests or lock files) and reports `MB302` with the advisory ID, CVE aliases and fixed
175
+ versions. Without `--online`, modelbom makes no network requests.
176
+
177
+ ## CI integration
178
+
179
+ GitHub Actions (uploads SARIF to code scanning):
180
+
181
+ ```yaml
182
+ jobs:
183
+ modelbom:
184
+ runs-on: ubuntu-latest
185
+ permissions:
186
+ contents: read
187
+ security-events: write
188
+ steps:
189
+ - uses: actions/checkout@v4
190
+ - uses: rajyavardhan01/modelbom@v0.1.0
191
+ with:
192
+ path: .
193
+ fail-on: high
194
+ ```
195
+
196
+ pre-commit:
197
+
198
+ ```yaml
199
+ repos:
200
+ - repo: https://github.com/rajyavardhan01/modelbom
201
+ rev: v0.1.0
202
+ hooks:
203
+ - id: modelbom
204
+ ```
205
+
206
+ ## Methodology
207
+
208
+ modelbom is a reference implementation of the automated vulnerability discovery framework and
209
+ exploit-pathway analysis described in:
210
+
211
+ > R. Handa, "Securing the Intelligent Software Supply Chain: Vulnerability Detection and Exploit
212
+ > Pathways in AI-Integrated Systems," *Journal of Computational Analysis and Applications*,
213
+ > vol. 34, no. 12, pp. 46–56, 2025. doi:10.48047/jocaaa.2025.34.12.06
214
+
215
+ [docs/methodology.md](docs/methodology.md) maps each feature to the paper's sections and
216
+ tables, and lists what is not implemented yet.
217
+
218
+ ### Related tools
219
+
220
+ Artifact scanners such as modelscan, picklescan and fickling focus on the model files
221
+ themselves. modelbom covers similar ground for pickle-based artifacts and adds source-code
222
+ rules, dependency pinning, attack paths and a CycloneDX AI-BOM in one zero-dependency CLI. The
223
+ tools can be used side by side.
224
+
225
+ ## Tested on real projects
226
+
227
+ Before release, modelbom was run against six popular open-source ML projects: training code,
228
+ inference servers, a RAG application and a notebook-heavy repository, from 1 MB to 140 MB
229
+ each, scanned statically. Every scan finished in under 3 seconds without errors. In a manual
230
+ review, the sampled findings were accurate: real `trust_remote_code=True` calls, `torch.load()`
231
+ without `weights_only`, `pickle.load()` and unpinned hub references. The same exercise turned
232
+ up two bugs, both fixed before release: syntax warnings from scanned code leaked to stderr,
233
+ and notebook cells with multi-line shell escapes failed to parse. Version ranges in a library's
234
+ `pyproject.toml` are now reported as informational, because ranges are correct practice for
235
+ libraries.
236
+
237
+ ## Limitations
238
+
239
+ - Code analysis is intra-file and literal-based. A hub ID or URL held in a variable, built with
240
+ string formatting, or passed through a config file is not resolved.
241
+ - A pickle allowlist cannot prove a file safe. A clean result means no known-dangerous import
242
+ was found, not that loading the file is harmless.
243
+ - `.h5` inspection is a bounded byte search, not a full HDF5 parse.
244
+ - No ML-based anomaly detection or behavioral (runtime) analysis yet. See the roadmap.
245
+
246
+ ## Roadmap
247
+
248
+ - Cross-file data flow for model IDs and paths (config files, constants modules)
249
+ - ONNX external-data and custom-operator checks; TensorFlow SavedModel inspection
250
+ - Model card / license extraction into the AI-BOM
251
+ - Statistical anomaly detection over artifact inventories across commits (P2, "Dependency Mapping and Anomaly Detection")
252
+ - Optional signature verification (Sigstore model signing) when signatures are present
253
+
254
+ ## Contributing
255
+
256
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Security issues: see [SECURITY.md](SECURITY.md).
257
+
258
+ ## License
259
+
260
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
261
+
262
+ ## Citation
263
+
264
+ If you use modelbom in research, please cite the software (see [CITATION.cff](CITATION.cff))
265
+ and the paper above.