Skip to main content
Glama
README.md
<p align="center">
  <img src="docs/icon.png" alt="llm-web-guard icon" width="96" height="96">
</p>

# llm-web-guard

**Defensive security checks for the AI features you ship.**

[![CI](https://github.com/htsecurity/llm-web-guard/actions/workflows/ci.yml/badge.svg)](https://github.com/htsecurity/llm-web-guard/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/)

`llm-web-guard` is a CLI, GitHub Action and MCP server for Claude, Cursor and
other AI assistants. It finds security and cost mistakes in LLM-powered web
apps, maps them to the OWASP LLM Top 10 and can ask a real model for a second
opinion.

It is defensive by design: it reads local source files, never sends a request to
your application and never executes project code.

<p align="center">
  <img src="docs/terminal.png" alt="llm-web-guard output with findings and an AI review" width="860">
</p>

## What it catches

| ID | Severity | Check |
| --- | --- | --- |
| LWG001 | Critical | Hardcoded OpenAI, Anthropic, OpenRouter, Google, Groq, Perplexity or xAI keys. |
| LWG002 | Critical | Provider keys exposed through `NEXT_PUBLIC_`, `VITE_` or browser-side code. |
| LWG003 | Medium | Model calls without `max_tokens`, `maxTokens`, `maxOutputTokens` or equivalent. |
| LWG004 | Low | Model calls without a timeout or abort signal. |
| LWG005 | High | User input interpolated into a system prompt. |
| LWG006 | High | Model output passed to `dangerouslySetInnerHTML` without sanitization. |
| LWG007 | Medium | AI API routes with no obvious authentication check. |
| LWG008 | Medium | AI API routes with no obvious rate limit, quota or credit check. |
| LWG009 | High | Wildcard CORS on an AI endpoint. |

Checks are deterministic and run locally. LWG007 and LWG008 are explicitly
heuristic: they tell you to review, not that a vulnerability is proven.

## Install

With [uv](https://docs.astral.sh/uv/):

```sh
uv tool install git+https://github.com/htsecurity/llm-web-guard.git
```

Or with pipx:

```sh
pipx install git+https://github.com/htsecurity/llm-web-guard.git
```

## CLI

```sh
# Scan the current project
llm-web-guard scan

# Scan a specific app
llm-web-guard scan ./apps/web

# JSON or SARIF for CI/code scanning
llm-web-guard scan --format json --output report.json
llm-web-guard scan --format sarif --output llm-web-guard.sarif

# Fail only on critical findings, or do not fail at all
llm-web-guard scan --fail-on critical
llm-web-guard scan --fail-on none

# See available local and hosted models
llm-web-guard models
```

Exit codes:

- `0`: no finding at or above the `--fail-on` threshold.
- `1`: a finding reached the threshold.
- `2`: invalid input, path or AI configuration.

## AI review (real models, optional)

The deterministic scan never needs an API key. To get a second opinion on the
highest-severity findings:

```sh
# Local first: uses an installed Ollama model when available
llm-web-guard scan --ai-review --ai-max 3

# Pick a specific local model
llm-web-guard scan --ai-review --ai-provider ollama --model qwen2.5:14b

# Or use OpenRouter
export OPENROUTER_API_KEY=...
llm-web-guard scan --ai-review --ai-provider openrouter
```

What happens:

1. Ollama is tried first when `--ai-provider auto` is used.
2. If no local model is available, OpenRouter is used when `OPENROUTER_API_KEY`
   is set.
3. Only the finding and a small code window are sent, not the whole project.
4. The model must return structured JSON with a verdict, confidence, rationale,
   remediation and an optional patch hint.
5. Results are cached by input hash. `--ai-max` defaults to 3 and is capped at 20.

Example with a local model:

```text
AI (ollama/qwen2.5:14b): confirmed (100%) — The API key is exposed in the
client-side code, which is a critical security issue as it can be accessed by
any user of the web application.
```

The CLI prints the provider, model and token usage in JSON output. No AI call is
made unless `--ai-review` or the MCP `review` tool is explicitly used.

### Environment

Copy `.env.example` to `.env` for local use. Real `.env` files are gitignored.

| Variable | Purpose |
| --- | --- |
| `OPENROUTER_API_KEY` | Optional OpenRouter key. |
| `OPENROUTER_DEFAULT_MODEL` | Optional model ID. If empty, a low-cost model is selected from the live catalog. |
| `OLLAMA_BASE_URL` | Local OpenAI-compatible endpoint. Default: `http://localhost:11434/v1`. |
| `OLLAMA_MODEL` | Optional local model ID. |

The `models` command reads the live OpenRouter catalog and shows prices per 1M
input/output tokens. OpenRouter results are cached for one hour.

## Use it from Claude and other MCP clients

The MCP server exposes four tools:

| Tool | Purpose |
| --- | --- |
| `scan(path)` | Deterministic local scan. No AI calls. |
| `review(finding, code_context, provider?, model?)` | Real LLM second opinion on one finding. |
| `models(provider?)` | List local Ollama models and live OpenRouter models. |
| `rules()` | List the checks and OWASP mappings. |

Claude Code:

```sh
claude mcp add llm-web-guard -- uvx --from git+https://github.com/htsecurity/llm-web-guard llm-web-guard-mcp
```

Claude Desktop, Cursor and other stdio MCP clients:

```json
{
  "mcpServers": {
    "llm-web-guard": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/htsecurity/llm-web-guard",
        "llm-web-guard-mcp"
      ]
    }
  }
}
```

Then ask:

> Scan this project for LLM security issues. Do not send code to a model yet.

> Review the highest-severity finding with my local Ollama model.

## GitHub Action

The action is deterministic and makes no AI calls in CI:

```yaml
- uses: htsecurity/llm-web-guard@v0.1.0
  with:
    path: .
    fail-on: high
```

SARIF output for GitHub code scanning:

```yaml
- uses: htsecurity/llm-web-guard@v0.1.0
  id: llm-security
  with:
    path: .
    fail-on: none
    format: sarif
    output: llm-web-guard.sarif

- uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: llm-web-guard.sarif
```

## Privacy and safety

- The scanner reads source files only. It does not execute code, install
  dependencies, browse your app or send HTTP requests to it.
- Secret-looking values are redacted in output.
- AI review is opt-in and sends only the finding and a small code window.
- Use `--ai-provider ollama` to keep review data on your machine.
- No telemetry, analytics or background jobs.

## Limitations

- This is a static heuristic scanner, not a penetration test or a guarantee that
  an app is secure.
- It does not prove exploitability. Findings marked `medium` confidence need a
  human review.
- It does not understand every framework, custom wrapper or authorization model.
- It does not replace dependency scanning, secret scanning, auth testing or a
  full OWASP ASVS review.

## Development

```sh
git clone https://github.com/htsecurity/llm-web-guard.git
cd llm-web-guard
uv sync
uv run pytest
uv run ruff check .
uv run ruff format --check .
```

The test suite includes a deliberately vulnerable Next.js fixture, a safe
fixture, SARIF validation, an MCP stdio client test and mocked AI responses.
CI runs on Python 3.11 and 3.13.

## License

MIT. See [LICENSE](LICENSE).

TDQS

A3.5/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct role: scan runs the deterministic static pass, review does a single LLM-backed deep dive on one finding, while models and rules are pure informational lookups. The scan vs. review boundary is spelled out explicitly (read-only/no AI calls vs. snippet sent to a provider), so misselection is unlikely.

Naming Consistency4/5

All names are single lowercase tokens with no case/style drift, which is predictable. The only inconsistency is grammatical: scan/review are verbs while models/rules are bare nouns that implicitly mean list_models/list_rules.

Tool Count5/5

Four tools is a tight, well-scoped surface for a small security scanner: detection, AI-assisted triage, provider discovery, and rule enumeration. No tool looks redundant or like filler, and nothing essential is obviously missing at this scale.

Completeness4/5

The lifecycle (list rules -> scan -> inspect providers -> review a finding) is coherent and has no dead ends. Minor gaps: no way to enumerate/export the findings from a scan in structured form, and no configuration/baseline management for suppressions or provider defaults.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues