Tools

SQL-Guardian

Detect SQL injection vectors, dangerous patterns, and misconfigured queries before they reach your database.

Overview

SQL-Guardian is an MPP-signed MCP tool for detecting SQL injection vectors, dangerous query patterns, and misconfigured database access in agent-generated or user-supplied SQL.

It runs entirely within a WASM sandbox — no database connection is required. SQL-Guardian analyses query structure and patterns without executing anything.

Installation

mpp install @q2x/sql-guardian

Requires an MPP Registry account with at least a Free plan. Verify the installation:

mpp verify @q2x/sql-guardian

MCP Tools Provided

analyzeQuery

Analyses a single SQL query or statement for security issues.

Input:

{
  "query": "SELECT * FROM users WHERE id = '${userId}'",
  "dialect": "postgresql",
  "strictMode": true
}

Output:

{
  "safe": false,
  "risk": "HIGH",
  "findings": [
    {
      "type": "SQL_INJECTION_VECTOR",
      "severity": "HIGH",
      "location": { "start": 42, "end": 53 },
      "description": "Unparameterised string interpolation in WHERE clause",
      "remediation": "Use parameterised query: WHERE id = $1"
    }
  ],
  "parameterisedForm": "SELECT * FROM users WHERE id = $1"
}

analyzeQueryBatch

Analyse multiple queries in a single call. Useful for reviewing a migration file or a batch of agent-generated queries.

Input:

{
  "queries": ["SELECT ...", "UPDATE ..."],
  "dialect": "mysql"
}

Output: Array of analyzeQuery results, one per input query.

checkPermissions

Validates that a SQL statement only accesses tables and columns declared in an allowlist. Useful for enforcing least-privilege access in agent-driven queries.

Input:

{
  "query": "SELECT email FROM users",
  "allowedTables": ["users"],
  "allowedColumns": { "users": ["id", "name", "email"] }
}

Output:

{
  "permitted": true,
  "violations": []
}

Supported Dialects

  • PostgreSQL
  • MySQL / MariaDB
  • SQLite
  • Microsoft SQL Server (T-SQL)
  • Oracle SQL (partial)

Detection Patterns

SQL-Guardian detects:

  • Injection vectors — unparameterised interpolation, tautological conditions (1=1), comment injection
  • Privilege escalationGRANT, REVOKE, CREATE USER, DDL statements in unexpected contexts
  • Data exfiltration patternsUNION SELECT with mismatched column counts, INTO OUTFILE
  • Destructive operationsDROP TABLE, TRUNCATE, DELETE without WHERE
  • Stacked queries — multiple statements separated by semicolons in a single query parameter

Capability Manifest

SQL-Guardian requires no filesystem, network, or environment access. Its WASM sandbox is fully isolated:

{
  "capabilities": {
    "filesystem": {},
    "network": {},
    "env": []
  }
}

Integration Example

import { MppRuntime } from "@q2x/mpp-runtime";

const runtime = new MppRuntime({ apiToken: process.env.MPP_API_TOKEN });

// Before executing any agent-generated SQL:
const result = await runtime.invoke({
  package: "@q2x/sql-guardian@latest",
  method: "analyzeQuery",
  args: {
    query: agentGeneratedSql,
    dialect: "postgresql",
    strictMode: true,
  },
});

if (!result.safe || result.risk === "HIGH") {
  throw new Error(`SQL-Guardian blocked query: ${result.findings[0].description}`);
}

// Proceed with executing the verified query
await db.query(result.parameterisedForm, params);

Changelog

v2.1.0 — Added checkPermissions method, T-SQL dialect support v2.0.0 — WASM runtime migration, removed network dependency v1.3.0 — Batch analysis endpoint, MySQL dialect v1.0.0 — Initial release (PostgreSQL, SQLite)