Skip to main content

ai-sec-gate

CI PyPI Release License: Apache 2.0 Docs: CC BY 4.0

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.

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.

The 4-Level Maturity Scale

Level Label Meaning
1 LEVEL_1_BROKEN Toy/reversible cipher, broken hash (md5/sha1), unsafe eval/Math.random() token/TLS bypass, CRITICAL finding, or leaked/unignored .env.
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.
3 LEVEL_3_HARDENED Clean semantic + SAST scan, salted slow KDFs (scrypt/bcrypt/argon2), secret scanning (gitleaks), and 40-char SHA-pinned GitHub Actions.
4 LEVEL_4_VERIFIED All Level 3 controls plus CI dependency vulnerability auditing (pip-audit / `npm

Install & Integration (pre-commit & uvx)

1. Commit-time gate via .pre-commit-config.yaml

Pin ai-sec-gate to an immutable 40-char commit SHA (or release tag) alongside ruff and gitleaks:

repos:
  - repo: https://github.com/rctruta/ai-sec-gate
    rev: v0.2.2  # or 40-char commit SHA
    hooks:
      - id: ai-sec-gate
        # Use args: [--min-level=2] for local-only repos without .github/workflows/ yet
        # (while CI enforces --prove --with-deps-audit --min-level 4).

2. CI Level-4 verification via uvx

# Run directly from PyPI
uvx ai-sec-gate check . --prove --with-deps-audit --min-level 4

# Or pin to an immutable git tag / 40-char commit SHA
uvx --from git+https://github.com/rctruta/ai-sec-gate@v0.2.2 ai-sec-gate check . --prove --with-deps-audit --min-level 4

3. Local CLI & Module Invocation

uv sync

# Console entrypoint or module execution (requires Level 3+ by default)
uv run ai-sec-gate check .
uv run python3 -m ai_sec_gate check . --with-clippy

# Full Level 4 verification (runs isolated red-team hook probes + JSON output)
uv run ai-sec-gate check /path/to/repo --prove --min-level 4 --format json

# Run only the isolated hook prover against a repository
uv run ai-sec-gate prove /path/to/repo

Behavioral KDF & Verifier Test Helpers (ai_sec_gate.testing)

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:

import hashlib
import hmac
import os
import secrets
from ai_sec_gate.testing import (
    assert_constant_time_verifier,
    assert_salted_kdf,
    assert_token_entropy,
)

def hash_pw(pw: bytes) -> tuple[bytes, bytes]:
    salt = os.urandom(16)
    return salt, hashlib.scrypt(pw, salt=salt, n=2**14, r=8, p=1)

def verify_pw(pw: bytes, stored: tuple[bytes, bytes]) -> bool:
    salt, expected = stored
    candidate = hashlib.scrypt(pw, salt=salt, n=2**14, r=8, p=1)
    return hmac.compare_digest(expected, candidate)

assert_salted_kdf(hash_pw, verify_pw)
assert_token_entropy(lambda: secrets.token_urlsafe(24))
assert_constant_time_verifier(hmac.compare_digest, expected=b"mac-tag-bytes")

Semantic Rules & Language Adapters

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.

Rule / Adapter Language What it checks
PY-CRYPTO-001 Python Broken hash (md4, md5, sha1) used without usedforsecurity=False.
PY-CRYPTO-002 Python Fast hash (sha256, sha512, blake2b, etc.) applied to password material instead of scrypt / bcrypt / argon2.
PY-CRYPTO-003 Python Toy character-shift / XOR cipher (caesar, rot13, modular ord()) on secret or cipher functions.
PY-AUTH-004 Python Direct == / != comparison on digest, HMAC, signature, or token identifiers instead of hmac.compare_digest.
RUFF-S* / PY-DEP-* Python Delegates general SAST to ruff check --select S (when on PATH) and pip-audit (--with-deps-audit).
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.
JS-CRYPTO-001 / JS-CRYPTO-002 JS / TS Catches broken hashes (md5/sha1) and fast hashes (createHash('sha256') / subtle.digest) applied to passwords.
JS-RAND-001 / JS-AUTH-004 JS / TS Flags Math.random() on tokens/secrets/nonces and === / == on digests/signatures instead of crypto.timingSafeEqual.
JS-EXEC-001 / JS-TLS-001 JS / TS Flags eval(), new Function(), shell: true, and rejectUnauthorized: false / NODE_TLS_REJECT_UNAUTHORIZED=0.
RS-SUPPLY-001 / RS-DEP-* Rust Checks workspace Cargo.toml manifests for * versions or unpinned git deps (missing rev) and integrates cargo audit.
RS-UNSAFE-001 / RS-CLIPPY-* Rust Requires preceding // SAFETY: comments on production unsafe blocks/fns/impls and integrates cargo clippy (--with-clippy).
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.

Repository Scaffolding

Seeded with init-agent-project from ai-agent-utils, enforcing stdlib claim/hygiene gates (.gates/), ruff (E9, F, B, S), gitleaks, external scratch/ symlink, and SHA-pinned CI.

uv run pytest
sh .gates/tests/prove_gates.sh

License

Copyright 2026 Ramona C. Truta. Code is licensed under the Apache License 2.0. Documentation is licensed under CC BY 4.0.

Metadata

Release files for ai-sec-gate 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-sec-gate 0.2.2
File Size Uploaded Provenance Actions
ai_sec_gate-0.2.2.tar.gz 36.7 kB Without provenance Details for ai_sec_gate-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ai-sec-gate 0.2.2
File Interpreter ABI Platform Actions
ai_sec_gate-0.2.2-py3-none-any.whl Python 3 none any Details for ai_sec_gate-0.2.2-py3-none-any.whl

Total release size: 78.8 kB

Release files / ai_sec_gate-0.2.2.tar.gz

Download URL ai_sec_gate-0.2.2.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ec6e464cd961feb797829e2ebfbbf2d9105def27e97aaf90a41b19f4cf6155ce
BLAKE2b-256 checksum
How to use checksums
0faa83e270a782b98972545ecbe7419049ba49c25f63d6be13d59fec204875ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ai_sec_gate-0.2.2-py3-none-any.whl

Download URL ai_sec_gate-0.2.2-py3-none-any.whl
Size 42.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f58e4c293a7f36b6b4b4b6b7d7a4bbcfa8ad3812037cf4dd0dbf2edba678d533
BLAKE2b-256 checksum
How to use checksums
13011bf3a1e839efa2e76e0f7d7d81ba62b8f01d3a5bd389082020ea9c65963d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ai-sec-gate 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page