Skip to main content

Run Bandit and Semgrep, normalize findings, and produce deterministic security audit reports.

Project description

ai-code-sec-audit

ai-code-sec-audit is a lightweight Python package and CLI that runs Bandit and Semgrep, normalizes findings into a stable JSON schema, computes a deterministic score, and writes a reproducible report.

Install

pip install ai-code-sec-audit

CLI usage

ai-code-sec-audit audit path/to/file.py -o report.json
ai-code-sec-audit audit path/to/dir -o report.json -f high

Options use short flags:

  • -o: output JSON path (required)
  • -p: profile (default: default)
  • -f: fail threshold (critical|high|medium|low|info)
  • -P: pretty-print JSON

Python API

from ai_code_sec_audit import audit_path

report = audit_path("path/to/file.py", profile="default", fail_on="high")
print(report.summary.score)

Output schema

Canonical JSON report fields:

  • meta: tool_version, timestamp, target, profile, how_to_reproduce
  • summary: score, total_findings, counts, should_fail
  • findings[]: tool, rule_id, title, description, severity, confidence, cwe, file, start_line, end_line, fingerprint, references

Reproducible command

meta.how_to_reproduce contains the exact command with resolved target/output paths and selected flags to reproduce the same report.

Sample JSON snippet

{
  "meta": {
    "tool_version": "0.1.0",
    "target": "/abs/path/examples/vuln_python/app.py",
    "profile": "default",
    "how_to_reproduce": "ai-code-sec-audit audit /abs/path/examples/vuln_python/app.py -o /abs/path/report.json -p default"
  },
  "summary": {
    "score": 86,
    "total_findings": 2,
    "counts": {
      "critical": 0,
      "high": 1,
      "medium": 1,
      "low": 0,
      "info": 0
    },
    "should_fail": true
  }
}

Scoring

Score starts at 100 and deducts:

  • critical: 20
  • high: 10
  • medium: 4
  • low: 1
  • info: 0

Final score is clamped to 0..100.

Fail-on behavior

  • critical: fail if any critical findings
  • high: fail if any critical/high
  • medium: fail if any critical/high/medium
  • low: fail if any critical/high/medium/low
  • info: fail if any finding exists

CLI exits with status code 2 when threshold is met.

Scanner behavior

  • Bandit command:
    • directory: bandit -r <target> -f json
    • file: bandit <target> -f json
  • Semgrep command: semgrep --config auto --json <target>
  • If scanner binaries are missing, warnings are printed and scanning continues.

Limitations (v0.1.0)

  • No HTML reports
  • No SARIF output
  • Only Bandit + Semgrep are supported
  • No advanced configuration system

Roadmap

  • Additional scanner integrations
  • Config file support
  • Optional report enrichments and diff mode

Sample run artifacts

This repository includes sample-run inputs and outputs:

  • Vulnerable input: examples/vuln_python/app.py
  • Safer input: examples/safe_python/app.py
  • Reproducible run script: examples/sample_runs/run_samples.sh
  • Captured run logs: examples/sample_runs/vuln_run.txt, examples/sample_runs/safe_run.txt
  • Generated reports: examples/sample_runs/vuln_report.json, examples/sample_runs/safe_report.json

Run from repo root:

./examples/sample_runs/run_samples.sh

Publish to PyPI

This project is now configured for PyPI publishing with:

  • package metadata in pyproject.toml
  • reproducible sdist + wheel builds via hatchling
  • a GitHub Actions workflow at .github/workflows/publish.yml that uploads on release

One-time setup

  1. Create a project on PyPI named ai-code-sec-audit.
  2. In the PyPI project settings, enable Trusted Publishing for your GitHub repository and the workflow file .github/workflows/publish.yml.
  3. Update project.urls in pyproject.toml if your repository URL differs.

Release flow (recommended)

  1. Bump src/ai_code_sec_audit/version.py.
  2. Commit and tag a release in GitHub.
  3. Publish a GitHub Release (or run the workflow manually).
  4. The workflow builds, validates, and uploads the package to PyPI.

Manual upload (fallback)

python -m pip install --upgrade build twine
python -m build
twine check dist/*
twine upload dist/*

Development

ruff check .
ruff format .
mypy src
pytest
python -m build
twine check dist/*

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_code_sec_audit-0.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_code_sec_audit-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file ai_code_sec_audit-0.1.0.tar.gz.

File metadata

  • Download URL: ai_code_sec_audit-0.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_code_sec_audit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d2f1b126589502fa1121a6166f0fd7543699e093f8446dd7f7fbdac6bfd62ba6
MD5 d9bcfd04c54dbdc47b6c43f7146d11c7
BLAKE2b-256 81b10b39adca697a6ecd7fdb91bee8ce08e93fe6e4d5ff1e5aea86b3afa90a95

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_code_sec_audit-0.1.0.tar.gz:

Publisher: publish.yml on widdendream/ai-code-sec-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_code_sec_audit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_code_sec_audit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16ef7c9594e1ba6e59e8a2fed41a5bbc9490e843a6bdd44b59584be43ef7639a
MD5 ae87aac928076a8384f75c710acdde20
BLAKE2b-256 cf441010f30731f78b9983c329246cd27b806d22d56c506e7b29e1605b189b70

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_code_sec_audit-0.1.0-py3-none-any.whl:

Publisher: publish.yml on widdendream/ai-code-sec-audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page