<> CodeGuard v2.0 SAST
● Product & Workflow Specification

CodeGuard

Fast, offline, zero-infrastructure static security analysis engineered to eliminate anti-patterns before code reaches production. Native support for Python, JavaScript, and TypeScript with single-configuration governance across your entire SDLC.

< 100ms
Execution latency per cycle
100%
Offline & air-gapped privacy
3 Targets
Python, JavaScript & TypeScript
5 Gates
Continuous SDLC checkpoints

01 Executive Summary & Product Vision

CodeGuard is a fast, developer-friendly static application security testing (SAST) tool engineered to eliminate security anti-patterns before code reaches production.

Following its v2.0 makeover, CodeGuard bridges the gap between lightweight linters and heavy enterprise SAST suites. It requires no server infrastructure, no database, no Docker daemon, and zero cloud API keys. Everything runs 100% offline, executing deterministic AST and Tree-sitter semantic analysis in milliseconds.

SDLC Architecture & Single-Policy Governance Unified Gates
       ┌────────────────────────────────────────────────────────────────────────┐
       │                             CodeGuard                                  │
       │   Fast • 100% Offline • Zero Noise • Unified Policy Across All Gates   │
       └───────────────────────────────────┬────────────────────────────────────┘
                                           │
         ┌───────────────────┬─────────────┴───────┬────────────────────┐
         ▼                   ▼                     ▼                    ▼
   [Local Editor]      [Pre-Commit]          [PR / CI Gate]      [Audit & Baseline]
   Sub-second scan     Block bad code        Diff-aware PR       Manage tech debt &
   while coding        before commit         checks & SARIF      track suppressions

02 Where CodeGuard Fits in Your Development Workflow

CodeGuard is designed around a multi-gated security model, ensuring that security validation happens continuously throughout the developer workflow rather than as a delayed gate at release time.

Multi-Stage SDLC Pipeline Flowchart Continuous Validation
flowchart TD subgraph S1["1. Local Development"] A["Developer writes code
(Python, JS, TS)"] --> B["Instant CLI scan / editor
codeguard scan src/"] B -->|Findings detected| C["Inline remediation with
plain-English suggestions"] C --> A end subgraph S2["2. Git Hooks"] A -->|git commit| D["pre-commit hook
(staged files only)"] D -->|Fail| E["Commit rejected locally"] D -->|Pass| F["git push / pre-push hook
(full tree check)"] end subgraph S3["3. Pull Request & CI Gate"] F --> G["Open Pull Request"] G --> H["codeguard ci / GitHub Action
(Diff-aware scan against base branch)"] H --> I{"Are there new findings
above fail-on threshold?"} I -->|Yes| J["Post inline PR annotations
Fail CI status check"] I -->|No / Baselined| K["CI check passes
Upload SARIF to Security Tab"] end subgraph S4["4. Continuous Audit & Debt Management"] K --> L["Merge to main"] L --> M["Scheduled nightly/weekly audit"] M --> N["codeguard baseline prune
(Track & ratchets down debt)"] M --> O["codeguard suppressions list --expired
(Enforce temporary waiver expiry)"] end
Stage 01
Inner Loop
Sub-second scan while coding with direct terminal carets & remediation snippets.
codeguard scan src/
Stage 02
Git Pre-Commit
Fails commits locally if vulnerabilities are introduced in staged changes.
pre-commit run codeguard
Stage 03
PR & CI Gate
Diff-aware scan ignores untouched legacy code; posts annotations & SARIF.
codeguard ci --sarif
Stage 04
Audit & Debt
Ratchets down baselined debt over time and flags expired temporary waivers.
codeguard baseline prune

The 5 Gates of CodeGuard

Security as continuous craft — five discrete validation thresholds eliminating risk at each phase of authoring, integration, and governance:

01
Inner Loop
Local Dev & IDE
Developers receive sub-second feedback in their terminal with exact line numbers, code carets, and direct remediation snippets before committing.
codeguard scan <path>
02
Pre-Commit
Git Commit Trigger
Catches mistakes before they enter git history; scans strictly modified/staged files in milliseconds to keep commits clean.
id: codeguard
03
Pull Request
CI Diff Pipeline
Scans only changed files/lines against the PR base branch. Baselined legacy issues are ignored; only newly introduced vulnerabilities fail the build.
codeguard ci
04
Platform Security
Scanning Dashboard
Emits OASIS SARIF 2.1.0 to feed directly into GitHub Code Scanning, GitLab Security Dashboard, Reviewdog, or JUnit test reporters.
--format sarif
05
Governance & Audit
Scheduled CI / Periodic
Ensures technical debt is ratcheted down over time and temporary waivers (until=YYYY-MM-DD) cannot be silently forgotten.
baseline prune
Gate Stage Trigger / Command User Experience & Outcome
Gate 1: Inner Loop Local Dev & IDE codeguard scan <path> Sub-second feedback in terminal with code carets and direct remediation snippets.
Gate 2: Pre-Commit Git Commit pre-commit hook (id: codeguard) Catches mistakes before committing to git history; scans only modified files.
Gate 3: Pull Request CI Pipeline codeguard ci or GitHub Action Scans only changed files/lines. Baselined issues are ignored; only new vulnerabilities fail.
Gate 4: Platform Security Code Scanning Dashboard --format sarif Feeds directly into GitHub Code Scanning, GitLab Dashboard, Reviewdog, or JUnit.
Gate 5: Governance & Audit Scheduled CI / Maintenance codeguard baseline prune
codeguard suppressions list
Ratchets down debt over time and ensures temporary waivers cannot expire unnoticed.

03 How CodeGuard Creates Value

1. Shift-Left Without Developer Friction
Inner Loop Velocity
The Problem
Traditional enterprise SAST tools take 15–45 minutes to run in CI, spit out hundreds of false positives, and deliver reports to security teams weeks after the code was written.
The CodeGuard Solution
CodeGuard runs in < 100 milliseconds locally or in CI. It gives developers immediate, deterministic feedback directly in their terminal and PR diffs, with concrete code fixes.
2. "Stop the Bleeding" Baseline Adoption
Zero Day-1 Friction
The Problem
Adding a new security tool to a legacy codebase often creates 500+ immediate alerts, causing teams to abandon the tool or disable critical rules entirely.
The CodeGuard Solution
Run codeguard baseline create. CodeGuard fingerprints existing issues into .codeguard-baseline.json. CI will never break on existing legacy code—it only blocks new vulnerabilities in active PRs. Teams prune debt incrementally over time.
3. Governed, Accountable Suppressions
No Rotting Waivers
The Problem
Developers routinely bypass security warnings with unmonitored # noqa or # ignore comments without justification, creating permanent, untracked security blind spots.
The CodeGuard Solution
  • Every suppression requires an explicit reason:
    # codeguard: ignore[CG-SEC-001] reason: sanitized by custom validator
    (Omitting a reason raises rule CG-META-001).
  • Suppressions can carry expiration dates: until=2026-12-31. (Once expired, the finding reactivates and raises CG-META-002).
  • Security leads can audit all waivers at any time with codeguard suppressions list.
4. 100% Offline, Privacy-First Architecture
Air-Gapped & Compliant
Enterprise Privacy Guarantee
  • Zero Data Ingestion: No source code or AST payload is ever sent over the internet or passed to an external LLM endpoint.
  • Regulatory Ready: Engineered specifically for air-gapped environments, strict compliance regimes (HIPAA, SOC2, FedRAMP, ISO 27001), and IP-sensitive proprietary codebases.
  • Zero Runtime Dependencies: No background daemons, external databases, or heavy container prerequisites required on worker nodes.
5. Predictable CI Contracts & Multi-Ecosystem Formats
Strict Exit Codes
Deterministic Pipeline Contract

Built with strict, semantic exit codes for battle-tested automation scripting:

Exit 0: Clean Exit 1: Findings Exit 2: Usage Error Exit 3: Config Error Exit 4: Internal Error

First-class native formatters: human, json (v1 schema envelope), sarif (OASIS 2.1.0), github (Actions workflow annotations), rdjson (Reviewdog), and junit (CI test runners).

04 Current Feature Catalog (v2.0)

4.1 Multi-Language Engine

CodeGuard features a unified, highly optimized analysis pipeline supporting:

Python AST
Python Engine

Standard deterministic AST analysis across .py and .pyi files with deep expression tracking.

Tree-sitter
JavaScript & TypeScript

High-performance semantic tree analysis supporting .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, and .cts.

Discovery
Smart Filtering

Automatically respects .gitignore, skips vendor trees (node_modules/, .venv/, dist/), and ignores minified code.

Parallelism
Multi-Core Pool

Worker process pool (--jobs / -j) for saturating multiple CPU cores across massive monorepos.

4.2 Security & Meta Rules

Every rule in CodeGuard has a permanent ID, standardized severity, CWE/OWASP classification, and actionable remediation guide:

Rule ID Description Severity CWE / Ref Languages
CG-SEC-001 SQL query constructed via f-strings, %, or .format() HIGH CWE-89 Python
CG-SEC-002 Hardcoded passwords, API keys, tokens, or credentials HIGH CWE-798 Python
CG-SEC-003 eval() or exec() execution on dynamic/non-literal input HIGH CWE-95 Python
CG-SEC-004 Unsafe deserialization (pickle.loads, yaml.load) HIGH CWE-502 Python
CG-SEC-005 subprocess() invoked with shell=True on dynamic args HIGH CWE-78 Python
CG-SEC-101 Dynamic evaluation: eval(), new Function, string timer HIGH CWE-95 JS, TS
CG-SEC-102 child_process.exec() invoked with a dynamic command HIGH CWE-78 JS, TS
CG-SEC-103 DOM XSS sink assignment (innerHTML, document.write) HIGH CWE-79 JS, TS
CG-SEC-104 React dangerouslySetInnerHTML with dynamic values HIGH CWE-79 JS, TS
CG-SEC-105 Hardcoded credentials, private keys, high-entropy API HIGH CWE-798 JS, TS
CG-SEC-106 Insecure randomness: Math.random() used for security MEDIUM CWE-338 JS, TS
CG-META-001 Governance: Suppression comment is missing reason: LOW Meta All
CG-META-002 Governance: Suppression comment until= date expired MEDIUM Meta All

4.3 CLI Commands & Tooling Capabilities

Command Purpose Example Usage
codeguard scan General scan of files, directories, or stdin codeguard scan src/ --fail-on high
codeguard ci Diff-aware PR scanning (auto-detects base branch) codeguard ci --sarif codeguard.sarif
codeguard baseline create Freeze all existing findings into a baseline JSON codeguard baseline create
codeguard baseline update Add newly found findings to existing baseline codeguard baseline update
codeguard baseline prune Clean out resolved findings to ratchet down debt codeguard baseline prune
codeguard suppressions list Audit and inspect suppression comments across repo codeguard suppressions list --expired
codeguard init Scaffold a fresh codeguard.toml configuration codeguard init
codeguard validate Validate codeguard.toml or pyproject.toml syntax codeguard validate
codeguard list-rules List available rules with language & category filters codeguard list-rules --language python
codeguard explain <ID> View full explanation, CWE references, and fix guides codeguard explain CG-SEC-001

4.4 Centralized Configuration (codeguard.toml)

CodeGuard can be configured via codeguard.toml, .codeguard.toml, or [tool.codeguard] inside pyproject.toml:

codeguard.toml
[codeguard]
include   = ["src/**", "lib/**"]
exclude   = ["**/*.min.js", "tests/fixtures/**"]
languages = ["python", "javascript", "typescript"]
gitignore = true
fail_on   = "high"              # exit 1 on "high" or "critical" findings
output    = "human"             # default output format
jobs      = 0                   # 0 = auto-detect CPU cores
baseline  = ".codeguard-baseline.json"

[codeguard.rules]
disable = []                    # disable specific rule IDs
enable  = []                    # specify an allowlist of rule IDs

[codeguard.rules.CG-SEC-001]
severity = "critical"          # remap rule severity

[[codeguard.overrides]]
path    = "legacy_scripts/**"   # monorepo path-specific override
disable = ["CG-SEC-002"]

4.5 Packaging & Distribution Formats

PyPI Package

pipx install codeguard-cli or pip install codeguard-cli

GitHub Action

Official reusable action: uses: mevichitra/codeguard/action@v2

Pre-Commit Hook

Ready hooks in .pre-commit-hooks.yaml for commit and push

Container Image

OCI image for GitLab CI, Tekton, CircleCI, and Jenkins

05 Quickstart: Rolling Out CodeGuard in 3 Steps

01
Initialize Configuration & Freeze Legacy Baseline

Install CodeGuard via pipx, generate the starter configuration, and snapshot any pre-existing issues so that CI remains green on Day 1.

Terminal
# 1. Install CodeGuard globally
pipx install codeguard-cli

# 2. Generate configuration
codeguard init

# 3. Snapshot existing findings so CI doesn't block on day 1
codeguard baseline create
02
Add Pre-Commit Protection (Local Gate)

Block vulnerable code before it is committed to local git history by adding the hook to .pre-commit-config.yaml:

.pre-commit-config.yaml
repos:
  - repo: https://github.com/mevichitra/codeguard
    rev: v2.0.0
    hooks:
      - id: codeguard
03
Add Pull Request Gate (GitHub Actions)

Create .github/workflows/codeguard.yml to run diff-aware scans on every PR against main:

.github/workflows/codeguard.yml
name: Security Scan (CodeGuard)
on:
  pull_request:
    branches: [main]

permissions:
  contents: read
  security-events: write

jobs:
  security-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Required for diff-aware scanning

      - name: Run CodeGuard
        uses: mevichitra/codeguard/action@v2
        with:
          fail-on: high

06 Why Developers & Security Teams Love CodeGuard

Developers
Instant Clarity

Sub-second feedback, zero cloud lag, no broken builds on untouched legacy code, and clear remediation suggestions directly in terminal.

Managers
Velocity Preserved

Rapid onboarding without slowing down delivery velocity or drowning engineering sprints in false-alarm triage and alert fatigue.

Security
Rigorous Policy

Continuous enforcement across Python, JS, and TS, transparent suppression audits with mandatory reasons, and native SARIF 2.1.0 dashboards.