aicaudit 0.2.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.
- aicaudit-0.2.0/LICENSE +21 -0
- aicaudit-0.2.0/PKG-INFO +461 -0
- aicaudit-0.2.0/README.md +430 -0
- aicaudit-0.2.0/aicaudit/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/__main__.py +3 -0
- aicaudit-0.2.0/aicaudit/audit.py +167 -0
- aicaudit-0.2.0/aicaudit/cli.py +256 -0
- aicaudit-0.2.0/aicaudit/config.py +120 -0
- aicaudit-0.2.0/aicaudit/fix.py +213 -0
- aicaudit-0.2.0/aicaudit/graph.py +168 -0
- aicaudit-0.2.0/aicaudit/llm/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/llm/client.py +249 -0
- aicaudit-0.2.0/aicaudit/llm/prompts.py +195 -0
- aicaudit-0.2.0/aicaudit/output/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/output/json_output.py +34 -0
- aicaudit-0.2.0/aicaudit/output/markdown_output.py +52 -0
- aicaudit-0.2.0/aicaudit/output/sarif_output.py +121 -0
- aicaudit-0.2.0/aicaudit/rules/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/rules/base.py +90 -0
- aicaudit-0.2.0/aicaudit/rules/performance/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/rules/performance/complexity.py +57 -0
- aicaudit-0.2.0/aicaudit/rules/performance/nesting_depth.py +49 -0
- aicaudit-0.2.0/aicaudit/rules/quality/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/rules/quality/bare_except.py +30 -0
- aicaudit-0.2.0/aicaudit/rules/quality/magic_numbers.py +85 -0
- aicaudit-0.2.0/aicaudit/rules/quality/todo_comment.py +29 -0
- aicaudit-0.2.0/aicaudit/rules/quality/undefined_name.py +80 -0
- aicaudit-0.2.0/aicaudit/rules/quality/unused_variable.py +55 -0
- aicaudit-0.2.0/aicaudit/rules/security/__init__.py +1 -0
- aicaudit-0.2.0/aicaudit/rules/security/dangerous_functions.py +89 -0
- aicaudit-0.2.0/aicaudit/rules/security/insecure_random.py +58 -0
- aicaudit-0.2.0/aicaudit/rules/security/path_traversal.py +107 -0
- aicaudit-0.2.0/aicaudit/rules/security/secret_leak.py +71 -0
- aicaudit-0.2.0/aicaudit/rules/security/sql_injection.py +114 -0
- aicaudit-0.2.0/aicaudit/rules/security/ssrf.py +66 -0
- aicaudit-0.2.0/aicaudit/rules/security/weak_crypto.py +57 -0
- aicaudit-0.2.0/aicaudit/rules/security/xml_xxe.py +132 -0
- aicaudit-0.2.0/aicaudit/scan.py +266 -0
- aicaudit-0.2.0/aicaudit/web/__init__.py +5 -0
- aicaudit-0.2.0/aicaudit/web/server.py +495 -0
- aicaudit-0.2.0/aicaudit/web/static/app.css +416 -0
- aicaudit-0.2.0/aicaudit/web/static/app.js +440 -0
- aicaudit-0.2.0/aicaudit/web/templates/base.html +52 -0
- aicaudit-0.2.0/aicaudit/web/templates/config.html +48 -0
- aicaudit-0.2.0/aicaudit/web/templates/index.html +33 -0
- aicaudit-0.2.0/aicaudit/web/templates/results.html +34 -0
- aicaudit-0.2.0/aicaudit/web/templates/rules.html +29 -0
- aicaudit-0.2.0/aicaudit/web/templates/scan.html +48 -0
- aicaudit-0.2.0/aicaudit.egg-info/PKG-INFO +461 -0
- aicaudit-0.2.0/aicaudit.egg-info/SOURCES.txt +82 -0
- aicaudit-0.2.0/aicaudit.egg-info/dependency_links.txt +1 -0
- aicaudit-0.2.0/aicaudit.egg-info/entry_points.txt +2 -0
- aicaudit-0.2.0/aicaudit.egg-info/requires.txt +9 -0
- aicaudit-0.2.0/aicaudit.egg-info/top_level.txt +1 -0
- aicaudit-0.2.0/pyproject.toml +59 -0
- aicaudit-0.2.0/setup.cfg +4 -0
- aicaudit-0.2.0/tests/test_ai.py +89 -0
- aicaudit-0.2.0/tests/test_ai_harness.py +137 -0
- aicaudit-0.2.0/tests/test_ai_integration.py +116 -0
- aicaudit-0.2.0/tests/test_audit.py +50 -0
- aicaudit-0.2.0/tests/test_audit_ext.py +102 -0
- aicaudit-0.2.0/tests/test_collab.py +117 -0
- aicaudit-0.2.0/tests/test_config.py +74 -0
- aicaudit-0.2.0/tests/test_cov_edge.py +116 -0
- aicaudit-0.2.0/tests/test_coverage.py +167 -0
- aicaudit-0.2.0/tests/test_cwe_rules.py +142 -0
- aicaudit-0.2.0/tests/test_dx.py +173 -0
- aicaudit-0.2.0/tests/test_extended_coverage.py +243 -0
- aicaudit-0.2.0/tests/test_fix.py +112 -0
- aicaudit-0.2.0/tests/test_fix_cov.py +64 -0
- aicaudit-0.2.0/tests/test_graph.py +82 -0
- aicaudit-0.2.0/tests/test_insecure_random.py +63 -0
- aicaudit-0.2.0/tests/test_integration.py +87 -0
- aicaudit-0.2.0/tests/test_integration_edge.py +87 -0
- aicaudit-0.2.0/tests/test_llm_mock.py +117 -0
- aicaudit-0.2.0/tests/test_performance_rules.py +65 -0
- aicaudit-0.2.0/tests/test_quality_rules.py +123 -0
- aicaudit-0.2.0/tests/test_relay.py +59 -0
- aicaudit-0.2.0/tests/test_sarif_output.py +72 -0
- aicaudit-0.2.0/tests/test_security_rules.py +131 -0
- aicaudit-0.2.0/tests/test_suppression.py +72 -0
- aicaudit-0.2.0/tests/test_taint_engine.py +179 -0
- aicaudit-0.2.0/tests/test_taint_rules.py +114 -0
- aicaudit-0.2.0/tests/test_web.py +235 -0
aicaudit-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IhateStomachProblems
|
|
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.
|
aicaudit-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aicaudit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: AI-powered code audit CLI for Python projects. Static analysis + AI verification with evidence chains.
|
|
5
|
+
Author: IhateStomachProblems
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/IhateStomachProblems/aicaudit
|
|
8
|
+
Project-URL: Repository, https://github.com/IhateStomachProblems/aicaudit
|
|
9
|
+
Project-URL: Documentation, https://github.com/IhateStomachProblems/aicaudit
|
|
10
|
+
Keywords: code-audit,security,static-analysis,code-quality,ai,vulnerability-scanning
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: click>=8.0
|
|
24
|
+
Requires-Dist: tomli>=2.0; python_version < "3.11"
|
|
25
|
+
Requires-Dist: anthropic>=0.40.0
|
|
26
|
+
Requires-Dist: fastapi>=0.115.0
|
|
27
|
+
Requires-Dist: uvicorn>=0.30.0
|
|
28
|
+
Requires-Dist: jinja2>=3.0
|
|
29
|
+
Requires-Dist: pygments>=2.16
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# AICAudit 🛡️
|
|
33
|
+
|
|
34
|
+
> Evidence-driven AI code audit for Python — every verdict ships with a machine-checkable taint path.
|
|
35
|
+
>
|
|
36
|
+
> 证据链驱动的 Python 代码审计:每个判定都附带可复核的污点传播路径(source → … → sink)
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=flat&logo=python&logoColor=white" alt="Python"/>
|
|
40
|
+
<img src="https://img.shields.io/badge/tests-305%20passed-brightgreen" alt="Tests"/>
|
|
41
|
+
<img src="https://img.shields.io/badge/coverage-92%25-brightgreen" alt="Coverage"/>
|
|
42
|
+
<img src="https://img.shields.io/badge/license-MIT-blue" alt="License"/>
|
|
43
|
+
<img src="https://img.shields.io/badge/rules-15-brightgreen" alt="Rules"/>
|
|
44
|
+
<img src="https://img.shields.io/badge/SARIF-2.1-blue" alt="SARIF"/>
|
|
45
|
+
<img src="https://img.shields.io/github/stars/IhateStomachProblems/aicaudit?style=social" alt="Stars"/>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Why AICAudit
|
|
51
|
+
|
|
52
|
+
Other tools give you a verdict. AICAudit gives you the **evidence**:
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
S001 app.py:16 SQL injection risk
|
|
56
|
+
taint path: app.py:14 request.args (Flask user input)
|
|
57
|
+
-> app.py:14 assigned to 'uid'
|
|
58
|
+
-> app.py:15 assigned to 'query'
|
|
59
|
+
-> app.py:16 conn.execute()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- **Taint engine** (pure Python, zero plugins): tracks user input from source
|
|
63
|
+
(Flask/Django/FastAPI request, `input()`, `os.environ`, `sys.argv`) through
|
|
64
|
+
assignments, f-strings, concatenation, and **across function boundaries** to
|
|
65
|
+
the sink — and proves constants safe, killing the classic false-positive
|
|
66
|
+
classes (`open(BASE_DIR/"x")`, constant SQL variables, `eval("1+1")`)
|
|
67
|
+
- **AI verdicts with receipts**: the LLM sees the full function and the taint
|
|
68
|
+
path, not a one-line snippet — hallucination-resistant by construction
|
|
69
|
+
- **SARIF codeFlows**: taint paths render natively in the GitHub Security tab
|
|
70
|
+
- **Zero config**: `pip install` and scan; works offline, local LLMs supported
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Quick Start
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# From source (PyPI package arrives with v0.2.0)
|
|
78
|
+
pip install git+https://github.com/IhateStomachProblems/aicaudit.git
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Scan a file or directory
|
|
83
|
+
aicaudit scan ./src
|
|
84
|
+
|
|
85
|
+
# Markdown report (default)
|
|
86
|
+
aicaudit scan ./src --output markdown
|
|
87
|
+
|
|
88
|
+
# JSON output (for CI / scripts / AI agent integration)
|
|
89
|
+
aicaudit scan ./src --output json
|
|
90
|
+
|
|
91
|
+
# SARIF 2.1 output (GitHub Code Scanning compatible)
|
|
92
|
+
aicaudit scan ./src --output sarif
|
|
93
|
+
|
|
94
|
+
# Chinese language
|
|
95
|
+
aicaudit scan ./src --lang zh
|
|
96
|
+
|
|
97
|
+
# CI gate: exit 1 when any finding is error or worse (0 clean / 2 usage error)
|
|
98
|
+
aicaudit scan ./src --fail-on error
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## CI & Git Integration
|
|
104
|
+
|
|
105
|
+
**One-line GitHub Action** (this repo ships a composite action at its root):
|
|
106
|
+
|
|
107
|
+
```yaml
|
|
108
|
+
- uses: IhateStomachProblems/aicaudit@main
|
|
109
|
+
with:
|
|
110
|
+
path: .
|
|
111
|
+
fail-on: error # optional: fail the job at this severity
|
|
112
|
+
sarif: "true" # optional: upload SARIF to Code Scanning
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**pre-commit** (local hook until the PyPI release):
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
repos:
|
|
119
|
+
- repo: local
|
|
120
|
+
hooks:
|
|
121
|
+
- id: aicaudit
|
|
122
|
+
name: aicaudit
|
|
123
|
+
entry: aicaudit scan --fail-on error
|
|
124
|
+
language: system
|
|
125
|
+
types: [python]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Project config** — generate it interactively:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
aicaudit init # writes [tool.aicaudit] into pyproject.toml
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Custom Rules (Python files, no DSL)
|
|
137
|
+
|
|
138
|
+
Drop rule files into `.aicaudit/rules/` (auto-discovered) or list extra dirs
|
|
139
|
+
under `[tool.aicaudit] rule-dirs`. Rules are ordinary Python using the public
|
|
140
|
+
API — a later registration with the same id overrides the builtin:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
# .aicaudit/rules/no_print.py
|
|
144
|
+
import ast
|
|
145
|
+
from aicaudit.rules.base import Finding, Rule, Severity, register
|
|
146
|
+
|
|
147
|
+
@register
|
|
148
|
+
class NoPrint(Rule):
|
|
149
|
+
id = "Q100"
|
|
150
|
+
name = "no-print"
|
|
151
|
+
severity = Severity.INFO
|
|
152
|
+
description = "Detect print() calls"
|
|
153
|
+
|
|
154
|
+
def check(self, tree, context):
|
|
155
|
+
return [Finding(rule_id=self.id, message="print() — prefer logging",
|
|
156
|
+
message_zh="print()——建议改用 logging",
|
|
157
|
+
file=str(context.file_path), line=n.lineno,
|
|
158
|
+
severity=self.severity)
|
|
159
|
+
for n in ast.walk(tree)
|
|
160
|
+
if isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
|
|
161
|
+
and n.func.id == "print"]
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
A ready-to-copy example lives at
|
|
165
|
+
[examples/custom_rule_example.py](examples/custom_rule_example.py).
|
|
166
|
+
(A declarative YAML rule format is planned for v0.3 — the loader is ready.)
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Rules
|
|
171
|
+
|
|
172
|
+
### Security
|
|
173
|
+
|
|
174
|
+
| ID | Rule | Severity |
|
|
175
|
+
|----|------|----------|
|
|
176
|
+
| S001 | SQL injection detection | CRITICAL |
|
|
177
|
+
| S002 | Hardcoded secret detection | CRITICAL |
|
|
178
|
+
| S003 | Dangerous functions (eval, exec, pickle, os.system) | ERROR |
|
|
179
|
+
| S004 | Path traversal detection | ERROR |
|
|
180
|
+
| S005 | SSRF detection | ERROR |
|
|
181
|
+
| S006 | Weak cryptography detection | WARNING |
|
|
182
|
+
| S007 | XML External Entity (XXE) detection | ERROR |
|
|
183
|
+
| S008 | Insecure random (non-crypto PRNG) | WARNING |
|
|
184
|
+
|
|
185
|
+
### Quality
|
|
186
|
+
|
|
187
|
+
| ID | Rule | Severity |
|
|
188
|
+
|----|------|----------|
|
|
189
|
+
| Q001 | Bare except detection | WARNING |
|
|
190
|
+
| Q002 | Magic number detection | INFO |
|
|
191
|
+
| Q003 | Undefined name detection | ERROR |
|
|
192
|
+
| Q004 | TODO/FIXME comment detection | INFO |
|
|
193
|
+
| Q005 | Unused variable detection | WARNING |
|
|
194
|
+
|
|
195
|
+
### Performance
|
|
196
|
+
|
|
197
|
+
| ID | Rule | Severity |
|
|
198
|
+
|----|------|----------|
|
|
199
|
+
| P001 | Cyclomatic complexity | WARNING |
|
|
200
|
+
| P002 | Nesting depth | WARNING |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Inline Suppression
|
|
205
|
+
|
|
206
|
+
Suppress specific findings with inline comments:
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
# Ignore a specific rule on this line
|
|
210
|
+
query = f"SELECT * FROM users WHERE id={user_id}" # aicaudit: ignore S001
|
|
211
|
+
|
|
212
|
+
# Ignore all rules on this line
|
|
213
|
+
eval(user_input) # aicaudit: ignore
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Web UI
|
|
219
|
+
|
|
220
|
+
Prefer a browser over the terminal? Start the built-in web interface:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
aicaudit web # http://127.0.0.1:8080
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The UI is vendored and offline-first — no CDN, no build step, works air-gapped:
|
|
227
|
+
|
|
228
|
+
- **Results browser**: code context with syntax highlighting (server-side
|
|
229
|
+
pygments), the **taint path as a visual stepper** (source → hops → sink),
|
|
230
|
+
AI verdict card with confidence, and diff-preview/apply/rollback for fixes
|
|
231
|
+
- **Live scan progress**: per-file streaming (SSE), no fake progress bars
|
|
232
|
+
- **Scan history**: sessions persist under `.aicaudit/web/`, dashboard shows
|
|
233
|
+
trends across runs
|
|
234
|
+
- Rules browser and AI provider config (relay / OpenAI / Claude / OpenRouter /
|
|
235
|
+
local ollama)
|
|
236
|
+
|
|
237
|
+
API docs at `/docs` (Swagger UI). Found something rough? [Open an issue](https://github.com/IhateStomachProblems/aicaudit/issues).
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## GitHub Code Scanning Integration
|
|
242
|
+
|
|
243
|
+
AICAudit produces [SARIF 2.1](https://sarifweb.azurewebsites.net/) output compatible with GitHub Code Scanning:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
aicaudit scan ./src --output sarif > aicaudit.sarif
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Upload the result in a GitHub Actions workflow:
|
|
250
|
+
|
|
251
|
+
```yaml
|
|
252
|
+
- name: Run AICAudit
|
|
253
|
+
run: aicaudit scan . --output sarif > aicaudit.sarif
|
|
254
|
+
|
|
255
|
+
- name: Upload SARIF
|
|
256
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
257
|
+
with:
|
|
258
|
+
sarif_file: aicaudit.sarif
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Caveats
|
|
264
|
+
|
|
265
|
+
AICAudit is a young project. Here are some honest limitations:
|
|
266
|
+
|
|
267
|
+
- **Python only** for now — other languages are planned
|
|
268
|
+
- **Static analysis** — not a runtime security tool
|
|
269
|
+
- **Best-effort** — no tool catches every bug ; please review findings critically
|
|
270
|
+
- The rules reflect common patterns but may not fit every codebase
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Performance
|
|
275
|
+
|
|
276
|
+
| Scenario | Time |
|
|
277
|
+
|----------|------|
|
|
278
|
+
| 35 files directory | ~0.13s |
|
|
279
|
+
| Single file | ~0.01s |
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Benchmarks
|
|
284
|
+
|
|
285
|
+
Labeled corpus (104 cases: function-level samples + a realistic Flask app with
|
|
286
|
+
planted vulnerabilities), scored against ground truth with an honest
|
|
287
|
+
methodology — including the categories where aicaudit is deliberately
|
|
288
|
+
conservative or deliberately silent. Bandit runs on the same corpus for
|
|
289
|
+
reference; buckets Bandit does not cover are marked.
|
|
290
|
+
|
|
291
|
+
| Rule | aicaudit P/R | Bandit P/R (comparable bucket) |
|
|
292
|
+
|------|-------------|-------------------------------|
|
|
293
|
+
| S001 SQL injection | 100% / 100% | 100% / 86% |
|
|
294
|
+
| S003 dangerous functions | 100% / 100% | 92% / 75% |
|
|
295
|
+
| S004 path traversal | 100% / 100% | no coverage |
|
|
296
|
+
| S005 SSRF | 100% / 100% | no coverage |
|
|
297
|
+
| S007 XXE | 100% / 100% | 100% / 50% |
|
|
298
|
+
|
|
299
|
+
Full table with F1, timing, and the honest-notes section (design tiers,
|
|
300
|
+
conservative flags): [benchmarks/RESULTS.md](benchmarks/RESULTS.md).
|
|
301
|
+
Reproduce and challenge it yourself:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
python benchmarks/run.py
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Testing
|
|
310
|
+
|
|
311
|
+
- 305 unit tests (pytest)
|
|
312
|
+
- 92% code coverage (pytest-cov)
|
|
313
|
+
- Taint engine: 17 dedicated tests (sources, constness, sanitizers, interprocedural)
|
|
314
|
+
- AI pipeline: fail-safe parsing, transport retry, category-aware prompts all tested
|
|
315
|
+
- Integration tests for CLI, JSON, Markdown, SARIF, Web UI, Chinese output
|
|
316
|
+
- Self-scan validation: we audit our own codebase
|
|
317
|
+
- CI: GitHub Actions on Python 3.10–3.13 (ruff + mypy + coverage + self-scan)
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## AI Verdicts (evidence-grounded, fail-safe)
|
|
322
|
+
|
|
323
|
+
`aicaudit scan ./src --ai` attaches a verdict to every finding. The LLM sees
|
|
324
|
+
the full enclosing function, the file's imports, and the engine-traced taint
|
|
325
|
+
path — not a one-line snippet — and answers with a structured verdict
|
|
326
|
+
(`is_real`, `confidence`, `cwe`, `reason`, `suggested_fix`).
|
|
327
|
+
|
|
328
|
+
Three verdict states, by design:
|
|
329
|
+
|
|
330
|
+
| status | meaning |
|
|
331
|
+
|--------|---------|
|
|
332
|
+
| `confirmed` | AI agrees it is real, confidence ≥ 0.5 |
|
|
333
|
+
| `false_positive` | AI judged it noise (reason always included) |
|
|
334
|
+
| `unverified` | missing/failed/low-confidence response — **never** auto-confirmed |
|
|
335
|
+
|
|
336
|
+
Why not auto-filter? The best published LLM-verifier configurations still
|
|
337
|
+
wrongly suppress ~22% of true vulnerabilities ([arXiv 2601.22952](https://arxiv.org/abs/2601.22952)),
|
|
338
|
+
so verdicts mark findings instead of deleting them. If you want aggressive
|
|
339
|
+
filtering anyway, it is an explicit opt-in:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
aicaudit scan ./src --ai --ai-strict # keep only AI-confirmed findings
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Prompts are category-aware: injection-class findings (S001/S003/S004/S005/S007)
|
|
346
|
+
get dataflow verification instructions anchored on the taint path;
|
|
347
|
+
policy-class findings (S002/S006/S008) get usage-context instructions —
|
|
348
|
+
targeting the documented failure modes of LLM verifiers (surface pattern
|
|
349
|
+
matching, CWE mislabeling, crypto/policy dismissals).
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## AI Configuration
|
|
354
|
+
|
|
355
|
+
AICAudit supports multiple LLM providers for AI-powered verification.
|
|
356
|
+
|
|
357
|
+
### Direct API
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# OpenAI
|
|
361
|
+
export AICAUDIT_AI_PROVIDER=openai
|
|
362
|
+
export AICAUDIT_AI_KEY=sk-xxx
|
|
363
|
+
aicaudit scan ./src --ai
|
|
364
|
+
|
|
365
|
+
# Claude
|
|
366
|
+
export AICAUDIT_AI_PROVIDER=claude
|
|
367
|
+
export ANTHROPIC_API_KEY=sk-ant-xxx
|
|
368
|
+
aicaudit scan ./src --ai
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Relay / Proxy Service (中转接口)
|
|
372
|
+
|
|
373
|
+
Any OpenAI-compatible relay service works. Set the provider to `relay` and point to your relay endpoint:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
# Example: API2D, OhMyGPT, NewAPI, OneAPI, etc.
|
|
377
|
+
export AICAUDIT_AI_PROVIDER=relay
|
|
378
|
+
export AICAUDIT_AI_BASE=https://your-relay.com/v1
|
|
379
|
+
export AICAUDIT_AI_KEY=sk-your-key
|
|
380
|
+
export AICAUDIT_AI_MODEL=gpt-4o-mini
|
|
381
|
+
aicaudit scan ./src --ai
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Also accepts `custom` or `proxy` as provider names for the same behavior.
|
|
385
|
+
|
|
386
|
+
### Local Models
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
export AICAUDIT_AI_PROVIDER=ollama
|
|
390
|
+
aicaudit scan ./src --ai
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## License
|
|
396
|
+
|
|
397
|
+
MIT © IhateStomachProblems
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
<div align="center">
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
# AICAudit 中文版
|
|
406
|
+
|
|
407
|
+
## 快速开始
|
|
408
|
+
|
|
409
|
+
```bash
|
|
410
|
+
# 源码安装(v0.2.0 将上架 PyPI)
|
|
411
|
+
pip install git+https://github.com/IhateStomachProblems/aicaudit.git
|
|
412
|
+
aicaudit scan ./项目目录 # 扫描项目
|
|
413
|
+
aicaudit scan ./src --lang zh # 使用中文输出
|
|
414
|
+
aicaudit scan ./src --output json # JSON 输出
|
|
415
|
+
aicaudit scan ./src --output sarif # SARIF 输出(GitHub Code Scanning 兼容)
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 规则列表
|
|
419
|
+
|
|
420
|
+
**安全**:SQL注入检测、硬编码密钥检测、危险函数检测、路径遍历、SSRF、弱加密、XXE、不安全随机数
|
|
421
|
+
**质量**:裸except、魔法数字、未定义变量、TODO注释、未使用变量
|
|
422
|
+
**性能**:圈复杂度、嵌套深度
|
|
423
|
+
|
|
424
|
+
## 行内抑制
|
|
425
|
+
|
|
426
|
+
```python
|
|
427
|
+
# 忽略特定规则
|
|
428
|
+
query = f"SELECT * FROM users WHERE id={user_id}" # aicaudit: ignore S001
|
|
429
|
+
|
|
430
|
+
# 忽略该行所有规则
|
|
431
|
+
eval(user_input) # aicaudit: ignore
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## GitHub Code Scanning 集成
|
|
435
|
+
|
|
436
|
+
```bash
|
|
437
|
+
aicaudit scan ./src --output sarif > aicaudit.sarif
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
在 GitHub Actions 中上传结果:
|
|
441
|
+
|
|
442
|
+
```yaml
|
|
443
|
+
- name: Run AICAudit
|
|
444
|
+
run: aicaudit scan . --output sarif > aicaudit.sarif
|
|
445
|
+
|
|
446
|
+
- name: Upload SARIF
|
|
447
|
+
uses: github/codeql-action/upload-sarif@v3
|
|
448
|
+
with:
|
|
449
|
+
sarif_file: aicaudit.sarif
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## 注意事项
|
|
453
|
+
|
|
454
|
+
- 目前仅支持 Python — 更多语言正在规划中
|
|
455
|
+
- 纯静态分析,不是运行时安全工具
|
|
456
|
+
- 没有工具能发现所有问题,请结合人工审查
|
|
457
|
+
- 规则反映常见模式,可能不适用于所有代码库
|
|
458
|
+
|
|
459
|
+
## 测试
|
|
460
|
+
|
|
461
|
+
305 个单元测试,92% 代码覆盖率:污点引擎专项、AI 判定管线(fail-safe/重试/类别感知 prompt)、Web UI(SSE/pygments/修复回滚/会话持久化)、CI 退出码/init 向导/外部规则目录、CLI/JSON/Markdown/SARIF/中文输出全覆盖。
|