Skip to main content

CodeGuard

Fast, offline static analysis that finds security anti-patterns in Python, JavaScript, and TypeScript — and drops into every gate of your workflow (editor, pre-commit, PR/CI, scheduled audit) from a single config file.

Status: 2.0 (beta). Rule IDs, the Finding/JSON schema, config keys, and exit codes are a stable contract from 2.0. See migration notes if you used the 0.1 alpha.

License Python CI PyPI


What it does

CodeGuard scans Python, JavaScript, and TypeScript and reports security findings. Each finding has a stable rule ID, severity, CWE/OWASP mapping, and a plain-English fix suggestion.

Current rules (see docs/rules/ for detail):

ID What it catches Severity CWE Languages
CG-SEC-001 SQL built with f-strings / % / .format() HIGH CWE-89 Python
CG-SEC-002 Hardcoded passwords, API keys, tokens HIGH CWE-798 Python
CG-SEC-003 eval() / exec() on non-literal input HIGH CWE-95 Python
CG-SEC-004 pickle.loads / yaml.load without SafeLoader HIGH CWE-502 Python
CG-SEC-005 subprocess(..., shell=True) with non-literal args HIGH CWE-78 Python
CG-SEC-101 eval / new Function / string timers on dynamic input HIGH CWE-95 JS, TS
CG-SEC-102 child_process.exec with a dynamic command HIGH CWE-78 JS, TS
CG-SEC-103 innerHTML / document.write assigned a non-literal HIGH CWE-79 JS, TS
CG-SEC-104 dangerouslySetInnerHTML with a non-literal value HIGH CWE-79 JS, TS
CG-SEC-105 Hardcoded passwords, API keys, tokens HIGH CWE-798 JS, TS
CG-SEC-106 Math.random() used for a token / secret / id MEDIUM CWE-338 JS, TS

What it does not do (yet)

  • Baseline / diff scanning, a CI-native command, packaged distribution (planned for v2.0)
  • AI-generated-code detection (deferred to a post-2.0 experimental module)
  • Web dashboard or REST API

Install

pipx install codeguard-cli      # or: uv tool install codeguard-cli
pip install codeguard-cli       # into the current environment

# or from source:
git clone https://github.com/mevichitra/codeguard
cd codeguard
pip install -e ".[dev]"

The PyPI project is codeguard-cli; the installed command is codeguard.

Requires Python 3.10+. No database, no Redis, no Docker needed.


Usage

# Scan a file or directory
codeguard scan myproject/

# Output as JSON
codeguard scan myproject/ --format json

# Output as SARIF (for GitHub code scanning)
codeguard scan myproject/ --format sarif > results.sarif

# Only run specific rules
codeguard scan myproject/ --rule CG-SEC-001 --rule CG-SEC-002

# Only report HIGH and above
codeguard scan myproject/ --severity high

Example output (human format):

myproject/auth.py:12:4  [CG-SEC-001] HIGH  SQL query built with string formatting
  → Use parameterized queries: cursor.execute("SELECT ... WHERE id = %s", (user_id,))

myproject/config.py:5:0  [CG-SEC-002] HIGH  Hardcoded secret: password
  → Load secrets from environment variables or a secrets manager.

2 findings  (2 high, 0 medium, 0 low)

Exit codes: 0 = no findings, 1 = findings found, 2 = error.

Inline suppression

query = f"SELECT * FROM users WHERE id = {uid}"  # codeguard: ignore[CG-SEC-001]

Suppressed findings still appear with suppressed: true in JSON/SARIF output.

Config file

Place a codeguard.toml in your project root:

[codeguard]
exclude = ["tests/", "migrations/"]
severity = "medium"   # ignore findings below this level

[codeguard.rules]
disabled = ["CG-SEC-002"]  # not yet

(Config file support is on the roadmap; not yet implemented.)


CI integration

GitHub Actions

- name: Run CodeGuard
  run: |
    pip install codeguard-cli
    codeguard scan src/ --format sarif > codeguard.sarif

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: codeguard.sarif

Contributing

See CONTRIBUTING.md for how to add a rule or file a bug.
Adding a rule requires: one rule file + two test fixtures (vulnerable + safe). See the rule authoring guide.


Project status and roadmap

2.0 (beta). Rule IDs, the Finding / JSON schema, config keys, and the exit-code contract are stable. Full details in the changelog and docs/.

On the roadmap:

  1. Light intraprocedural taint tracking (source → sink, sanitizer-aware) to cut false positives further
  2. A Semgrep-compatible YAML rule subset for custom rules
  3. Autofix (--fix) for the safe-fix rules
  4. Standalone single-file binaries and a Homebrew tap
  5. An LSP server for editor integration
  6. Optional, offline AI-assisted triage (confidence + rationale, no code leaves the machine)

License

Apache-2.0. See LICENSE.

Contributions are accepted under the Developer Certificate of Origin (DCO). Sign your commits with git commit -s.

Download files

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

Source Distribution

codeguard_cli-2.0.0.tar.gz (138.8 kB view details)

Uploaded Source

Built Distribution

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

codeguard_cli-2.0.0-py3-none-any.whl (76.3 kB view details)

Uploaded Python 3

File details

Details for the file codeguard_cli-2.0.0.tar.gz.

File metadata

  • Download URL: codeguard_cli-2.0.0.tar.gz
  • Upload date:
  • Size: 138.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for codeguard_cli-2.0.0.tar.gz
Algorithm Hash digest
SHA256 1211042a1fa9d82e69b09673731f60ca331512d310e8a285ed4bdef66bf1d2f7
MD5 a37663416c560168dda12bac4ef9010f
BLAKE2b-256 febdf8984f2b570618f71f1ab30a85da8b21244f945055c38819cebf5766d33c

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeguard_cli-2.0.0.tar.gz:

Publisher: release.yml on mevichitra/codeguard

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

File details

Details for the file codeguard_cli-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: codeguard_cli-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 76.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for codeguard_cli-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03429f9d41eb0eb786f06b82affe6511868a7d1a0a7814736ef3667a952ad172
MD5 d1ccf90a4808e19f1919c34b69174663
BLAKE2b-256 8090b3b763f784809ed7f7be21dd7b836530a73333531470c2dd15fff015fffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for codeguard_cli-2.0.0-py3-none-any.whl:

Publisher: release.yml on mevichitra/codeguard

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

Release history Release notifications | RSS feed

2.1.0

2 files

This release

2.0.0 This release

2 files

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