ai-sec-gate 0.2.2__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,11 @@
1
+ .venv/
2
+ node_modules/
3
+ .env
4
+ __pycache__/
5
+ *.pyc
6
+ .pytest_cache/
7
+ .vscode/
8
+ .agent_lock
9
+ scratch
10
+ .gates/checkpoints/
11
+ .gates/ledger.jsonl
@@ -0,0 +1,194 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, patent trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Work; and
105
+
106
+ (d) If the Work includes a "NOTICE" file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Work, in at least one of the
111
+ following places: within a NOTICE file distributed as part of
112
+ the Derivative Works; within the Source form or documentation,
113
+ if provided along with the Derivative Works; or, within a
114
+ display generated by the Derivative Works, if and wherever such
115
+ third-party notices normally appear. The contents of the NOTICE
116
+ file are for informational purposes only and do not modify the
117
+ License. You may add Your own NOTICE text within Derivative
118
+ Works that You distribute, alongside or as an addendum to the
119
+ NOTICE file from the Work, provided that such additional
120
+ NOTICE text cannot be construed as modifying the License.
121
+
122
+ You may add Your own copyright notice to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided that Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement that You may have
135
+ executed with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and fair use in describing the
140
+ origin of the Work and reproducing the content of the License.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contribution) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
145
+ OF ANY KIND, either express or implied. You are solely responsible for
146
+ determining the appropriateness of using or redistributing the Work
147
+ and assume any risks associated with Your use of permissions under
148
+ this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise,
152
+ unless required by applicable law (such as deliberate and grossly
153
+ negligent acts) or agreed to in writing, shall any Contributor be
154
+ liable to You for any damages, including any direct, indirect,
155
+ special, incidental, or consequential damages of any character arising
156
+ as of this License or out of the use or inability to use the Work
157
+ (including but not limited to damages for loss of goodwill, work
158
+ stoppage, computer failure or malfunction, or any and all other
159
+ commercial damages or losses), even if such Contributor has been
160
+ advised of the possibility of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing
163
+ the Work or Derivative Works thereof, You may knowingly accept
164
+ support, warranty, indemnity, or other liability obligations and/or
165
+ rights consistent with this License. However, in accepting such
166
+ obligations, You may act only on Your own behalf and on Your own
167
+ responsibility, and not on behalf of any other Contributor, and only
168
+ if You agree to indemnify, defend, and hold Licensor harmless for
169
+ any liability incurred by, or reason of, any liability claimed by
170
+ reason of such Contributor, if any.
171
+
172
+ END OF TERMS AND CONDITIONS
173
+
174
+ APPENDIX: How to apply the Apache License to your work.
175
+
176
+ To apply the Apache License to your work, attach the following
177
+ boilerplate notice, with the fields enclosed by brackets "[]"
178
+ replaced with your own identifying information. (Don't include
179
+ brackets!) The text should be enclosed in the following
180
+ brackets:
181
+
182
+ Copyright 2026 Ramona C. Truta
183
+
184
+ Licensed under the Apache License, Version 2.0 (the "License");
185
+ you may not use this file except in compliance with the License.
186
+ You may obtain a copy of the License at
187
+
188
+ http://www.apache.org/licenses/LICENSE-2.0
189
+
190
+ Unless required by applicable law or agreed to in writing, software
191
+ distributed under the License is distributed on an "AS IS" BASIS,
192
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193
+ See the License for the specific language governing permissions and
194
+ limitations under the License.
@@ -0,0 +1,347 @@
1
+ Metadata-Version: 2.5
2
+ Name: ai-sec-gate
3
+ Version: 0.2.2
4
+ Summary: Zero-dependency security posture verifier, semantic crypto/auth analyzer, behavioral KDF test helpers, and active hook prover.
5
+ Project-URL: Homepage, https://github.com/rctruta/ai-sec-gate
6
+ Project-URL: Repository, https://github.com/rctruta/ai-sec-gate
7
+ Project-URL: Issues, https://github.com/rctruta/ai-sec-gate/issues
8
+ Project-URL: Changelog, https://github.com/rctruta/ai-sec-gate/releases
9
+ Author: Ramona C. Truta
10
+ License: Apache License
11
+ Version 2.0, January 2004
12
+ http://www.apache.org/licenses/
13
+
14
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
15
+
16
+ 1. Definitions.
17
+
18
+ "License" shall mean the terms and conditions for use, reproduction,
19
+ and distribution as defined by Sections 1 through 9 of this document.
20
+
21
+ "Licensor" shall mean the copyright owner or entity authorized by
22
+ the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all
25
+ other entities that control, are controlled by, or are under common
26
+ control with that entity. For the purposes of this definition,
27
+ "control" means (i) the power, direct or indirect, to cause the
28
+ direction or management of such entity, whether by contract or
29
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
30
+ outstanding shares, or (iii) beneficial ownership of such entity.
31
+
32
+ "You" (or "Your") shall mean an individual or Legal Entity
33
+ exercising permissions granted by this License.
34
+
35
+ "Source" form shall mean the preferred form for making modifications,
36
+ including but not limited to software source code, documentation
37
+ source, and configuration files.
38
+
39
+ "Object" form shall mean any form resulting from mechanical
40
+ transformation or translation of a Source form, including but
41
+ not limited to compiled object code, generated documentation,
42
+ and conversions to other media types.
43
+
44
+ "Work" shall mean the work of authorship, whether in Source or
45
+ Object form, made available under the License, as indicated by a
46
+ copyright notice that is included in or attached to the work
47
+ (an example is provided in the Appendix below).
48
+
49
+ "Derivative Works" shall mean any work, whether in Source or Object
50
+ form, that is based on (or derived from) the Work and for which the
51
+ editorial revisions, annotations, elaborations, or other modifications
52
+ represent, as a whole, an original work of authorship. For the purposes
53
+ of this License, Derivative Works shall not include works that remain
54
+ separable from, or merely link (or bind by name) to the interfaces of,
55
+ the Work and Derivative Works thereof.
56
+
57
+ "Contribution" shall mean any work of authorship, including
58
+ the original version of the Work and any modifications or additions
59
+ to that Work or Derivative Works thereof, that is intentionally
60
+ submitted to Licensor for inclusion in the Work by the copyright owner
61
+ or by an individual or Legal Entity authorized to submit on behalf of
62
+ the copyright owner. For the purposes of this definition, "submitted"
63
+ means any form of electronic, verbal, or written communication sent
64
+ to the Licensor or its representatives, including but not limited to
65
+ communication on electronic mailing lists, source code control systems,
66
+ and issue tracking systems that are managed by, or on behalf of, the
67
+ Licensor for the purpose of discussing and improving the Work, but
68
+ excluding communication that is conspicuously marked or otherwise
69
+ designated in writing by the copyright owner as "Not a Contribution."
70
+
71
+ "Contributor" shall mean Licensor and any individual or Legal Entity
72
+ on behalf of whom a Contribution has been received by Licensor and
73
+ subsequently incorporated within the Work.
74
+
75
+ 2. Grant of Copyright License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ copyright license to reproduce, prepare Derivative Works of,
79
+ publicly display, publicly perform, sublicense, and distribute the
80
+ Work and such Derivative Works in Source or Object form.
81
+
82
+ 3. Grant of Patent License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ (except as stated in this section) patent license to make, have made,
86
+ use, offer to sell, sell, import, and otherwise transfer the Work,
87
+ where such license applies only to those patent claims licensable
88
+ by such Contributor that are necessarily infringed by their
89
+ Contribution(s) alone or by combination of their Contribution(s)
90
+ with the Work to which such Contribution(s) was submitted. If You
91
+ institute patent litigation against any entity (including a
92
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
93
+ or a Contribution incorporated within the Work constitutes direct
94
+ or contributory patent infringement, then any patent licenses
95
+ granted to You under this License for that Work shall terminate
96
+ as of the date such litigation is filed.
97
+
98
+ 4. Redistribution. You may reproduce and distribute copies of the
99
+ Work or Derivative Works thereof in any medium, with or without
100
+ modifications, and in Source or Object form, provided that You
101
+ meet the following conditions:
102
+
103
+ (a) You must give any other recipients of the Work or
104
+ Derivative Works a copy of this License; and
105
+
106
+ (b) You must cause any modified files to carry prominent notices
107
+ stating that You changed the files; and
108
+
109
+ (c) You must retain, in the Source form of any Derivative Works
110
+ that You distribute, all copyright, patent, patent trademark, and
111
+ attribution notices from the Source form of the Work,
112
+ excluding those notices that do not pertain to any part of
113
+ the Work; and
114
+
115
+ (d) If the Work includes a "NOTICE" file as part of its
116
+ distribution, then any Derivative Works that You distribute must
117
+ include a readable copy of the attribution notices contained
118
+ within such NOTICE file, excluding those notices that do not
119
+ pertain to any part of the Work, in at least one of the
120
+ following places: within a NOTICE file distributed as part of
121
+ the Derivative Works; within the Source form or documentation,
122
+ if provided along with the Derivative Works; or, within a
123
+ display generated by the Derivative Works, if and wherever such
124
+ third-party notices normally appear. The contents of the NOTICE
125
+ file are for informational purposes only and do not modify the
126
+ License. You may add Your own NOTICE text within Derivative
127
+ Works that You distribute, alongside or as an addendum to the
128
+ NOTICE file from the Work, provided that such additional
129
+ NOTICE text cannot be construed as modifying the License.
130
+
131
+ You may add Your own copyright notice to Your modifications and
132
+ may provide additional or different license terms and conditions
133
+ for use, reproduction, or distribution of Your modifications, or
134
+ for any such Derivative Works as a whole, provided that Your use,
135
+ reproduction, and distribution of the Work otherwise complies with
136
+ the conditions stated in this License.
137
+
138
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
139
+ any Contribution intentionally submitted for inclusion in the Work
140
+ by You to the Licensor shall be under the terms and conditions of
141
+ this License, without any additional terms or conditions.
142
+ Notwithstanding the above, nothing herein shall supersede or modify
143
+ the terms of any separate license agreement that You may have
144
+ executed with Licensor regarding such Contributions.
145
+
146
+ 6. Trademarks. This License does not grant permission to use the trade
147
+ names, trademarks, service marks, or product names of the Licensor,
148
+ except as required for reasonable and fair use in describing the
149
+ origin of the Work and reproducing the content of the License.
150
+
151
+ 7. Disclaimer of Warranty. Unless required by applicable law or
152
+ agreed to in writing, Licensor provides the Work (and each
153
+ Contribution) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
154
+ OF ANY KIND, either express or implied. You are solely responsible for
155
+ determining the appropriateness of using or redistributing the Work
156
+ and assume any risks associated with Your use of permissions under
157
+ this License.
158
+
159
+ 8. Limitation of Liability. In no event and under no legal theory,
160
+ whether in tort (including negligence), contract, or otherwise,
161
+ unless required by applicable law (such as deliberate and grossly
162
+ negligent acts) or agreed to in writing, shall any Contributor be
163
+ liable to You for any damages, including any direct, indirect,
164
+ special, incidental, or consequential damages of any character arising
165
+ as of this License or out of the use or inability to use the Work
166
+ (including but not limited to damages for loss of goodwill, work
167
+ stoppage, computer failure or malfunction, or any and all other
168
+ commercial damages or losses), even if such Contributor has been
169
+ advised of the possibility of such damages.
170
+
171
+ 9. Accepting Warranty or Additional Liability. While redistributing
172
+ the Work or Derivative Works thereof, You may knowingly accept
173
+ support, warranty, indemnity, or other liability obligations and/or
174
+ rights consistent with this License. However, in accepting such
175
+ obligations, You may act only on Your own behalf and on Your own
176
+ responsibility, and not on behalf of any other Contributor, and only
177
+ if You agree to indemnify, defend, and hold Licensor harmless for
178
+ any liability incurred by, or reason of, any liability claimed by
179
+ reason of such Contributor, if any.
180
+
181
+ END OF TERMS AND CONDITIONS
182
+
183
+ APPENDIX: How to apply the Apache License to your work.
184
+
185
+ To apply the Apache License to your work, attach the following
186
+ boilerplate notice, with the fields enclosed by brackets "[]"
187
+ replaced with your own identifying information. (Don't include
188
+ brackets!) The text should be enclosed in the following
189
+ brackets:
190
+
191
+ Copyright 2026 Ramona C. Truta
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
204
+ License-File: LICENSE
205
+ Keywords: ai-agents,ast,cryptography,kdf,pre-commit,sast,security
206
+ Classifier: Development Status :: 4 - Beta
207
+ Classifier: Environment :: Console
208
+ Classifier: Intended Audience :: Developers
209
+ Classifier: License :: OSI Approved :: Apache Software License
210
+ Classifier: Operating System :: OS Independent
211
+ Classifier: Programming Language :: Python :: 3
212
+ Classifier: Programming Language :: Python :: 3 :: Only
213
+ Classifier: Programming Language :: Python :: 3.11
214
+ Classifier: Programming Language :: Python :: 3.12
215
+ Classifier: Programming Language :: Python :: 3.13
216
+ Classifier: Programming Language :: Python :: 3.14
217
+ Classifier: Topic :: Security
218
+ Classifier: Topic :: Security :: Cryptography
219
+ Classifier: Topic :: Software Development :: Quality Assurance
220
+ Classifier: Topic :: Software Development :: Testing
221
+ Classifier: Typing :: Typed
222
+ Requires-Python: >=3.11
223
+ Description-Content-Type: text/markdown
224
+
225
+ # ai-sec-gate
226
+
227
+ [![CI](https://github.com/rctruta/ai-sec-gate/actions/workflows/ci.yml/badge.svg)](https://github.com/rctruta/ai-sec-gate/actions/workflows/ci.yml)
228
+ [![PyPI](https://img.shields.io/pypi/v/ai-sec-gate?color=blue)](https://pypi.org/project/ai-sec-gate/)
229
+ [![Release](https://img.shields.io/github/v/tag/rctruta/ai-sec-gate?label=release&color=blue)](https://github.com/rctruta/ai-sec-gate/releases)
230
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-green.svg)](https://github.com/rctruta/ai-sec-gate/blob/main/LICENSE)
231
+ [![Docs: CC BY 4.0](https://img.shields.io/badge/Docs-CC_BY_4.0-8b5cf6.svg)](https://creativecommons.org/licenses/by/4.0/)
232
+
233
+ Zero-dependency security posture verifier, semantic crypto/auth analyzer, behavioral KDF test helper library, and active hook prover for repositories written with AI coding agents.
234
+
235
+ General-purpose linters (`ruff --select S`, Bandit, ESLint, Clippy) catch broken primitives like `md5` or `eval`, yet miss semantic AI failure modes such as hashing user passwords with plain `sha256` (safe for checksums, brute-forceable for passwords), comparing digests with `==`, or skipping `// SAFETY:` invariants on Rust `unsafe` blocks. `ai-sec-gate` pairs semantic source checks across Python, JS/TS, and Rust with repository posture verification and isolated red-team hook probes.
236
+
237
+ ## The 4-Level Maturity Scale
238
+
239
+ | Level | Label | Meaning |
240
+ | --- | --- | --- |
241
+ | **1** | `LEVEL_1_BROKEN` | Toy/reversible cipher, broken hash (`md5`/`sha1`), unsafe `eval`/`Math.random()` token/TLS bypass, CRITICAL finding, or leaked/unignored `.env`. |
242
+ | **2** | `LEVEL_2_NAIVE` | Fast-hash password trap (`sha256(password)`), timing-unsafe secret comparison, undocumented Rust `unsafe`, unpinned dependencies, or missing SAST / secret scanning / SHA-pinned CI. |
243
+ | **3** | `LEVEL_3_HARDENED` | Clean semantic + SAST scan, salted slow KDFs (`scrypt`/`bcrypt`/`argon2`), secret scanning (`gitleaks`), and 40-char SHA-pinned GitHub Actions. |
244
+ | **4** | `LEVEL_4_VERIFIED` | All Level 3 controls **plus** CI dependency vulnerability auditing (`pip-audit` / `npm|pnpm|yarn audit` / `cargo audit`) and active red-team hook verification (`--prove`). |
245
+
246
+ ## Install & Integration (`pre-commit` & `uvx`)
247
+
248
+ ### 1. Commit-time gate via `.pre-commit-config.yaml`
249
+
250
+ Pin `ai-sec-gate` to an immutable 40-char commit SHA (or release tag) alongside `ruff` and `gitleaks`:
251
+
252
+ ```yaml
253
+ repos:
254
+ - repo: https://github.com/rctruta/ai-sec-gate
255
+ rev: v0.2.2 # or 40-char commit SHA
256
+ hooks:
257
+ - id: ai-sec-gate
258
+ # Use args: [--min-level=2] for local-only repos without .github/workflows/ yet
259
+ # (while CI enforces --prove --with-deps-audit --min-level 4).
260
+ ```
261
+
262
+ ### 2. CI Level-4 verification via `uvx`
263
+
264
+ ```bash
265
+ # Run directly from PyPI
266
+ uvx ai-sec-gate check . --prove --with-deps-audit --min-level 4
267
+
268
+ # Or pin to an immutable git tag / 40-char commit SHA
269
+ uvx --from git+https://github.com/rctruta/ai-sec-gate@v0.2.2 ai-sec-gate check . --prove --with-deps-audit --min-level 4
270
+ ```
271
+
272
+ ### 3. Local CLI & Module Invocation
273
+
274
+ ```bash
275
+ uv sync
276
+
277
+ # Console entrypoint or module execution (requires Level 3+ by default)
278
+ uv run ai-sec-gate check .
279
+ uv run python3 -m ai_sec_gate check . --with-clippy
280
+
281
+ # Full Level 4 verification (runs isolated red-team hook probes + JSON output)
282
+ uv run ai-sec-gate check /path/to/repo --prove --min-level 4 --format json
283
+
284
+ # Run only the isolated hook prover against a repository
285
+ uv run ai-sec-gate prove /path/to/repo
286
+ ```
287
+
288
+ ## Behavioral KDF & Verifier Test Helpers (`ai_sec_gate.testing`)
289
+
290
+ Verify in `pytest` that password KDFs apply fresh per-call random salts (catching deterministic `sha256` or static-salt bugs), CSPRNG token generators have high entropy, and constant-time verifiers safely reject mutated or mismatched-length inputs:
291
+
292
+ ```python
293
+ import hashlib
294
+ import hmac
295
+ import os
296
+ import secrets
297
+ from ai_sec_gate.testing import (
298
+ assert_constant_time_verifier,
299
+ assert_salted_kdf,
300
+ assert_token_entropy,
301
+ )
302
+
303
+ def hash_pw(pw: bytes) -> tuple[bytes, bytes]:
304
+ salt = os.urandom(16)
305
+ return salt, hashlib.scrypt(pw, salt=salt, n=2**14, r=8, p=1)
306
+
307
+ def verify_pw(pw: bytes, stored: tuple[bytes, bytes]) -> bool:
308
+ salt, expected = stored
309
+ candidate = hashlib.scrypt(pw, salt=salt, n=2**14, r=8, p=1)
310
+ return hmac.compare_digest(expected, candidate)
311
+
312
+ assert_salted_kdf(hash_pw, verify_pw)
313
+ assert_token_entropy(lambda: secrets.token_urlsafe(24))
314
+ assert_constant_time_verifier(hmac.compare_digest, expected=b"mac-tag-bytes")
315
+ ```
316
+
317
+ ## Semantic Rules & Language Adapters
318
+
319
+ Declarative defaults live in `src/ai_sec_gate/rules.toml` and can be overridden per target repository under `[tool.ai_sec_gate]` in `pyproject.toml` or `.ai-sec-gate.toml`.
320
+
321
+ | Rule / Adapter | Language | What it checks |
322
+ | --- | --- | --- |
323
+ | `PY-CRYPTO-001` | Python | Broken hash (`md4`, `md5`, `sha1`) used without `usedforsecurity=False`. |
324
+ | `PY-CRYPTO-002` | Python | Fast hash (`sha256`, `sha512`, `blake2b`, etc.) applied to password material instead of `scrypt` / `bcrypt` / `argon2`. |
325
+ | `PY-CRYPTO-003` | Python | Toy character-shift / XOR cipher (`caesar`, `rot13`, modular `ord()`) on secret or cipher functions. |
326
+ | `PY-AUTH-004` | Python | Direct `==` / `!=` comparison on digest, HMAC, signature, or token identifiers instead of `hmac.compare_digest`. |
327
+ | `RUFF-S*` / `PY-DEP-*` | Python | Delegates general SAST to `ruff check --select S` (when on `PATH`) and `pip-audit` (`--with-deps-audit`). |
328
+ | `JS-SUPPLY-001` / `JS-DEP-*` | JS / TS | Verifies lockfile presence (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lock`) and runs `npm` / `pnpm` / `yarn` audit. |
329
+ | `JS-CRYPTO-001` / `JS-CRYPTO-002` | JS / TS | Catches broken hashes (`md5`/`sha1`) and fast hashes (`createHash('sha256')` / `subtle.digest`) applied to passwords. |
330
+ | `JS-RAND-001` / `JS-AUTH-004` | JS / TS | Flags `Math.random()` on tokens/secrets/nonces and `===` / `==` on digests/signatures instead of `crypto.timingSafeEqual`. |
331
+ | `JS-EXEC-001` / `JS-TLS-001` | JS / TS | Flags `eval()`, `new Function()`, `shell: true`, and `rejectUnauthorized: false` / `NODE_TLS_REJECT_UNAUTHORIZED=0`. |
332
+ | `RS-SUPPLY-001` / `RS-DEP-*` | Rust | Checks workspace `Cargo.toml` manifests for `*` versions or unpinned `git` deps (missing `rev`) and integrates `cargo audit`. |
333
+ | `RS-UNSAFE-001` / `RS-CLIPPY-*` | Rust | Requires preceding `// SAFETY:` comments on production `unsafe` blocks/fns/impls and integrates `cargo clippy` (`--with-clippy`). |
334
+ | `RS-CRYPTO-001` / `RS-CRYPTO-002` / `RS-AUTH-004` | Rust | Catches MD5/SHA-1 calls, fast SHA-2/BLAKE hashes on passwords, and non-constant-time `==` on signatures/tokens. |
335
+
336
+ ## Repository Scaffolding
337
+
338
+ Seeded with `init-agent-project` from [ai-agent-utils](https://github.com/rctruta/ai-agent-utils), enforcing stdlib claim/hygiene gates (`.gates/`), `ruff` (`E9`, `F`, `B`, `S`), `gitleaks`, external `scratch/` symlink, and SHA-pinned CI.
339
+
340
+ ```bash
341
+ uv run pytest
342
+ sh .gates/tests/prove_gates.sh
343
+ ```
344
+
345
+ ## License
346
+
347
+ Copyright 2026 Ramona C. Truta. Code is licensed under the [Apache License 2.0](https://github.com/rctruta/ai-sec-gate/blob/main/LICENSE). Documentation is licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).