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.
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:
- Light intraprocedural taint tracking (source → sink, sanitizer-aware) to cut false positives further
- A Semgrep-compatible YAML rule subset for custom rules
- Autofix (
--fix) for the safe-fix rules - Standalone single-file binaries and a Homebrew tap
- An LSP server for editor integration
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1211042a1fa9d82e69b09673731f60ca331512d310e8a285ed4bdef66bf1d2f7
|
|
| MD5 |
a37663416c560168dda12bac4ef9010f
|
|
| BLAKE2b-256 |
febdf8984f2b570618f71f1ab30a85da8b21244f945055c38819cebf5766d33c
|
Provenance
The following attestation bundles were made for codeguard_cli-2.0.0.tar.gz:
Publisher:
release.yml on mevichitra/codeguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeguard_cli-2.0.0.tar.gz -
Subject digest:
1211042a1fa9d82e69b09673731f60ca331512d310e8a285ed4bdef66bf1d2f7 - Sigstore transparency entry: 2666677238
- Sigstore integration time:
-
Permalink:
mevichitra/codeguard@10781b21533e4d406ebd76b35265be7255c85c24 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/mevichitra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10781b21533e4d406ebd76b35265be7255c85c24 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03429f9d41eb0eb786f06b82affe6511868a7d1a0a7814736ef3667a952ad172
|
|
| MD5 |
d1ccf90a4808e19f1919c34b69174663
|
|
| BLAKE2b-256 |
8090b3b763f784809ed7f7be21dd7b836530a73333531470c2dd15fff015fffe
|
Provenance
The following attestation bundles were made for codeguard_cli-2.0.0-py3-none-any.whl:
Publisher:
release.yml on mevichitra/codeguard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codeguard_cli-2.0.0-py3-none-any.whl -
Subject digest:
03429f9d41eb0eb786f06b82affe6511868a7d1a0a7814736ef3667a952ad172 - Sigstore transparency entry: 2666677286
- Sigstore integration time:
-
Permalink:
mevichitra/codeguard@10781b21533e4d406ebd76b35265be7255c85c24 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/mevichitra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10781b21533e4d406ebd76b35265be7255c85c24 -
Trigger Event:
push
-
Statement type: