Metadata-Version: 2.4
Name: vetgate
Version: 0.3.1
Summary: Fast local security & quality gate for LLM-generated code (C# first). Deterministic, explainable, millisecond diff mode.
License: MIT License
        
        Copyright (c) 2026 vetgate contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/stuckerbsas/vetgate
Project-URL: Issues, https://github.com/stuckerbsas/vetgate/issues
Keywords: security,sast,csharp,dotnet,llm,code-review,claude-code
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: C#
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tree-sitter>=0.23
Requires-Dist: tree-sitter-c-sharp>=0.23
Dynamic: license-file

# vetgate

> **Beta.** C# only for now. Calibrated on a private 1,200-file .NET codebase and on public repos (eShop, nopCommerce, Bitwarden server, Jellyfin). Issues with false positives are very welcome.

A fast, local, low-noise security and quality vetgate for code written or changed by LLM coding agents.
C# / ASP.NET Core first (code, Razor views and appsettings/web.config); more languages plug into the same
architecture.

- **Deterministic and explainable.** Every finding says where the data comes from (`source`), which control is
  missing (`guard`), where it lands (`sink`) and why that is exploitable (`reason`).
- **Fast.** Milliseconds per file, no server, no model download. `--diff` scans only what changed.
- **Low noise by design.** Intra-procedural taint with guard recognition. The default vetgate is calibrated to
  0 medium+ findings on a large real-world .NET codebase (1,200+ files).
- **Built for agents.** A post-edit hook feeds findings back to the coding agent after every edit, and the
  `compact` format uses one line per finding.

It is a pre-filter, not a full SAST: data is followed within one file (including its private helpers) but not
across files, and there is no business-logic or IDOR analysis. Use it to catch the
obvious things cheaply, and keep human or LLM review for what needs reasoning.

## Install

```bash
pip install vetgate      # Python 3.10+; depends only on tree-sitter + tree-sitter-c-sharp
```

## Use

```bash
vetgate src/                                   # security focus, blocks on medium+
vetgate src/ --focus all --format text         # security + debug + quality + practices
vetgate . --diff                               # only files changed vs HEAD (+ untracked)
vetgate . --diff origin/main --format sarif > gate.sarif
git diff --name-only | vetgate --files-from -
```

| Option | Meaning |
|---|---|
| `--focus security,debug,quality,practices,all` | which checks to run (default `security`) |
| `--min-severity low/medium/high` | default `medium` for security only, `low` otherwise |
| `--format json/text/compact/sarif` | SARIF works with GitHub code scanning |
| `--disable RULE,...` | skip rules |
| `--include-tests` | also scan test projects (skipped by default) |
| `--include-dapper` | C#: also check dynamic Dapper SQL |
| `--no-fail` | always exit 0 |

Exit code: `0` clean, `1` findings at or above the threshold, `2` error.

Suppress one finding: `// vetgate-ignore: RULE -- reason` on the line or the line above.

## Rules (C#)

**security** (default gate): `SQL_INJ`, `CMD_INJ`, `PATH_TRAVERSAL`, `INSECURE_DESERIALIZATION`,
`HARDCODED_SECRET`, `ENDPOINT_NO_AUTH`, `WEAK_CRYPTO`, `SSRF`, `OPEN_REDIRECT`, `XSS_RAW_HTML`, `XXE`,
`CERT_VALIDATION_DISABLED`, `JWT_VALIDATION_DISABLED`, `INSECURE_RANDOM`, `CORS_PERMISSIVE`, `LDAP_INJ`,
`XPATH_INJ`, `REGEX_INJECTION`, `INSECURE_COOKIE`, `LOG_SENSITIVE_DATA`, `JWT_HTTPS_METADATA_DISABLED`,
`EXCEPTION_DETAILS_IN_RESPONSE`
(`ENDPOINT_NO_AUTH` is reported as low: many apps expose public endpoints without `[AllowAnonymous]`.)

**debug** (low): `DEBUG_CONSOLE_OUTPUT`, `SECURITY_BYPASS_TODO`, `TEST_STUB_LEAK`
**quality** (low): `ASYNC_NO_TRY_CATCH`, `EMPTY_CATCH_BLOCK`, `OVERLONG_METHOD`
**practices** (low): `ASYNC_VOID`, `SYNC_OVER_ASYNC`, `THREAD_SLEEP_IN_ASYNC`, `LOG_INTERPOLATION`,
`HTTPCLIENT_PER_CALL`, `THROW_EX_RESETS_STACK`, `STRING_CONCAT_IN_LOOP`, `DISPOSABLE_NOT_DISPOSED`,
`COUNT_INSTEAD_OF_ANY`, `GC_COLLECT`, `FIRE_AND_FORGET_TASK`, `DEV_EXCEPTION_PAGE_UNGUARDED`

**Razor views** (`.cshtml`, `.razor`): `XSS_RAW_HTML` for `Html.Raw` / `MarkupString`.
**Config files** (`appsettings*.json`, `web.config`, `app.config`): `HARDCODED_SECRET`.

Full reference (what is flagged, what is not, how to fix): [docs/rules/csharp.md](docs/rules/csharp.md)

## Example

```
$ vetgate Controllers/ToolsController.cs --format text
Controllers/ToolsController.cs:19: [HIGH] CMD_INJ (deterministic, 1.0)
    source: request parameter 'tool' ([FromQuery])
    guard : no allowlist / argument escaping before process start
    sink  : process execution (executable: tool)
    reason: Request-controlled text becomes part of the executable or its command line; ...
```

## Coding-agent integration

- **Post-edit hook (Claude Code):** the `vetgate-hook` command runs as a `PostToolUse` hook on `Edit|Write`.
  It reports medium+ findings anywhere in the edited file and low findings only on lines changed vs git `HEAD`,
  so legacy noise does not flood the context. It says nothing when the file is clean and never blocks the edit.
  ```json
  { "hooks": { "PostToolUse": [ { "matcher": "Edit|Write|MultiEdit", "hooks": [
      { "type": "command", "command": "vetgate-hook", "timeout": 30 } ] } ] } }
  ```
- **Skill:** [SKILL.md](SKILL.md) tells an agent when to run the vetgate and how to act on the results.

## Feedback and data

- **Report a false positive or a missed issue:** `vetgate report Path/File.cs:42` (add `--kind missed-issue`,
  `--open` to open the browser). It prints the prefilled issue so you can review or trim the snippet; nothing is
  sent automatically.
- **Local case log:** the post-edit hook appends each finding it reports to `~/.vetgate/findings.jsonl` (local
  only; `VETGATE_NO_LOG=1` disables it, `VETGATE_HOME` moves it). `vetgate feedback` labels cases as *fixed*
  (likely true positive) or *suppressed* (likely false positive), and `vetgate feedback --export cases.jsonl`
  writes them as a dataset for training a learned second layer.

## Development

```bash
python -m unittest discover -s tests       # fixtures + core tests
python run_fixtures.py                     # fixtures + false-positive check on real codebases
```

Each rule has a fixture in `fixtures/<lang>/` with a `FIXTURE-RULES: ...` header and an `EXPECT: RULE` marker on
every line that must be flagged. Vulnerable and safe cases sit side by side, and the reported set must match
exactly. Real-codebase false-positive targets come from `--fp-target`, `$VETGATE_FP_TARGETS` or a gitignored
`vetgate.local.json` (`{"fp_targets": ["..."]}`). They must give 0 medium+ findings.

New rule: fixture first, then the rule, then `run_fixtures.py` must be all green.

New language: add `vetgate/languages/<lang>/` exposing `NAME`, `EXTENSIONS`, `FOCUSES`, `is_test_file`,
`analyze(path, source, focuses, options)` and register it in `vetgate/languages/__init__.py`.

```
vetvetgate/cli.py, core.py      CLI, finding schema, suppressions, diff mode, json/text/compact/sarif
vetvetgate/languages/csharp/    common (parser + taint), security, security_web, debug, quality, practices
fixtures/                    regression fixtures per language
hooks/post_edit_gate.py      Claude Code post-edit hook
```
