Inter-procedural call graph & summaries
Cycle-safe module-level FunctionSummary analysis (up to 3 hops) propagates query taint, parameter mutations, commit delegation, and row-lock sanitizers across helper functions.
cguard is a deterministic, offline semantic SAST for Python. It traces concurrency hazards across FastAPI, Django ORM, SQLAlchemy 2.0, SQLModel, Tortoise ORM, Celery, Redis / Memcached, asyncio.TaskGroup, anyio, and threading—stresses the invariant, and offers source-preserving repairs.
Both requests read the same balance.
cguard follows the read, the check, and the write — even when they are separated by application code.
--confidence highFilters low-noise deterministic hazards# cguard: ignore[CG-001]Rule-scoped pragma suppression01def deduct(user_id, amount):02 wallet = Wallet.objects.get(id=user_id)03 if wallet.balance < amount:04 raise InsufficientFunds()05 wallet.balance -= amount06 wallet.save()
Every stage leaves deterministic evidence and verified artifacts you can inspect locally.
Cycle-safe module-level FunctionSummary analysis (up to 3 hops) propagates query taint, parameter mutations, commit delegation, and row-lock sanitizers across helper functions.
Strict def-use taint verification with walrus operator (:=) and starred unpacking support. Exact span-bounded lock sanitization is isolated within lexical scope boundaries (_walk_local_nodes).
cguard simulate extracts AST timeline steps (READ/CHECK → YIELD await → MUTATE → COMMIT) to simulate multi-coroutine races (--workers), and exports standalone runnable pytest suites via --export-test using asyncio.Barrier (no flaky sleep).
Syntax-gated source repairs with --diff ANSI unified preview, --check non-destructive CI gates, selective -r patching, and JSON payloads verified against in-memory AST scanner gates.
# comments & layout preservedCoverage is specific by design: modern Python concurrency primitives, framework semantics, and the evidence to act on a finding.
First-class static analysis for SQLAlchemy 2.0, Django ORM, SQLModel, and Tortoise ORM with row-lock and F() expression verification.
cguard simulate --export-test generates standalone pytest suites using asyncio.Barrier to deterministically reproduce races without flaky sleep().
Line-shift-resilient .cguard-baseline.json snapshots with CI ratcheting (--baseline, --update-baseline, --fail-on-stale-baseline) for tech debt management.
Hierarchical discovery for .cguard.toml > cguard.toml > pyproject.toml ([tool.cguard]) supporting select, ignore, per_file_ignores, and baseline.
Inter-procedural self-deadlocks, sync locks in coroutines, asyncio.TaskGroup, anyio task groups, and BackgroundTasks session leaks.
Syntax-gated source transforms with --diff preview, --check CI gates, selective -r patching, and 100% offline local analysis.
Twenty-one named checks across ORM, runtime, filesystem, cache, and lock behavior. Filter the catalog or open a rule for its detection rationale.
| Rule | Surface | Pattern | Severity | Repair |
|---|---|---|---|---|
| CG-001 | FastAPI / SQLAlchemy / SQLModel / Tortoise | Unlocked read-modify-write | Critical | Auto-fix |
| CG-002 | FastAPI | Missing idempotency guard | High | Auto-fix |
| CG-003 | asyncio / SQLAlchemy | Query inside async loop | Medium | Guidance |
| CG-004 | SQLAlchemy / SQLModel | Check-then-act uniqueness | High | Auto-fix |
| CG-005 | Celery | Non-idempotent retry | High | Guidance |
| CG-006 | asyncio | Shared-state mutation | High | Auto-fix |
| CG-007 | threading | Threaded collection mutation | High | Auto-fix |
| CG-008 | Python | In-memory RMW | High | Guidance |
| CG-009 | Filesystem | Concurrent file write | Medium | Auto-fix |
| CG-010 | Filesystem | Predictable tempfile | Medium | Guidance |
| CG-011 | Redis / cache | Cache check-then-act | High | Guidance |
| CG-012 | Cache | Non-atomic invalidation | High | Guidance |
| CG-013 | Locks | Lock-order inversion | Critical | Guidance |
| CG-014 | Python | Cross-file call-chain race | High | Guidance |
| CG-015 | Python | Tainted shared-state mutation | High | Guidance |
| CG-016 | Django | Unlocked ORM mutation | Critical | Auto-fix |
| CG-017 | Django / Tortoise | In-memory arithmetic vs F() | High | Auto-fix |
| CG-018 | Redis / cache | Unsafe lock deletion | Critical | Guidance |
| CG-019 | FastAPI | BackgroundTasks session leak | High | Guidance |
| CG-020 | Locks / HTTP | Unbounded lock across network I/O | Critical | Guidance |
| CG-021 | asyncio / threading | Generator lock leak (yield) | High | Guidance |
Run deterministic checks in pull requests, export OASIS SARIF v2.1.0 findings for GitHub Security, or stop regressions before the commit leaves a laptop.
Scan code in pull requests, upload SARIF v2.1.0 to GitHub CodeQL / Security, and gate merges with line-level findings and suggested patches.
Use maintained pre-commit hooks to scan staged Python files, verify baselines, and preview safe diffs without touching formatting.
- run: pip install --upgrade concurrency-guard
- run: cguard scan . --format sarif -o cguard.sarif || true
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: cguard.sarif
category: concurrency-guardJoin early access for the GitHub App: deterministic findings, line-level evidence, and suggested source-preserving patches before code merges.
Early access only. Your source stays in your repository.