Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Local wire-protocol SQL firewall, dry-run blast-radius sandbox, and non-blocking
### Try it in 10 seconds

```bash
# Run the 45-second disaster prevented demo (blocks DROP TABLE, full scan + PII, emits Slack Approve/Reject card)
npx @ritualdev-lab/dbshield demo

# Start the local wire-protocol firewall proxy (points at your local Postgres on :5432)
npx @ritualdev-lab/dbshield proxy --port 5433 --tier STRICT

Expand All @@ -21,16 +24,23 @@ npx @ritualdev-lab/dbshield mcp

```text
[DBShield :5433] Intercepted Extended Query (Parse/Bind/Execute):
SQL: DELETE FROM accounts WHERE created_at < '2026-01-01';
SQL: DELETE FROM customers WHERE plan = 'trial';
DryRun: 14,820 rows affected (ROLLBACK executed in 3.1ms — 0 DB locks held)
Action: BLOCKED -> Sent replay-proof HMAC approval card to Slack (#db-approvals)
```

<p align="center">
<img src="assets/demo.gif" alt="DBShield Live Terminal Demo" width="820" />
<img src="assets/demo.gif" alt="DBShield Live Terminal & Cursor Demo" width="820" />
</p>

> Recorded with [Charm VHS](https://github.com/charmbracelet/vhs) from [`assets/demo.tape`](assets/demo.tape).
> Recorded directly from `npx @ritualdev-lab/dbshield demo` (see [`assets/demo.tape`](assets/demo.tape)): `DROP TABLE` blocked, unindexed full scan blocked, PII email redacted, and Slack `[Approve Mutation]` / `[Reject Mutation]` buttons dispatched.

### 🏢 Team Rollout / AI Agent Security & SOC 2 Audit Setup ($299–$999/team)

Companies using Cursor, Claude Code, and production MCP servers deploy DBShield to pass **SOC 2, HIPAA, PCI-DSS v4.0, GDPR, and EU AI Act** database change-control reviews without slowing engineers down:

- **Turnkey Team Setup ($299–$999/team):** Production Postgres/MySQL wire-proxy deployment, Slack `#db-approvals` / MS Teams Two-Man Rule setup, HMAC-signed append-only ledger, and auditor-ready **SOC 2 / PCI-DSS / HIPAA / GDPR / EU AI Act compliance PDF bundles**.
- 👉 [**Book Team Rollout / SOC 2 Audit Setup (`security@ritualdev.in`)**](mailto:security@ritualdev.in?subject=DBShield%20Team%20Rollout%20%26%20SOC%202%20Audit%20Setup) &nbsp;·&nbsp; [**Enterprise Pricing & Architecture**](https://ritualdev.in/dbshield/enterprise) &nbsp;·&nbsp; [**AgentShield Security Suite**](https://agentshield.ritualdev.in/#pricing)

### Why simple regex SQL proxies fail

Expand Down
Binary file modified assets/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 12 additions & 16 deletions assets/demo.tape
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Charm VHS script — generates a crisp 15-second terminal GIF for DBShield
# Charm VHS script — DBShield 45-second real disaster prevented demo
# Install VHS: https://github.com/charmbracelet/vhs
# Run: vhs assets/demo.tape

Output assets/demo.gif

Set Shell "powershell"
Set FontSize 16
Set Width 1100
Set Height 640
Set FontSize 15
Set Width 1160
Set Height 680
Set Padding 24
Set Theme "TokyoNight"
Set TypingSpeed 35ms
Set TypingSpeed 30ms

Hide
Type "function prompt { '$ ' }"
Expand All @@ -19,23 +19,19 @@ Type "function dbshield { node dist/cli.js @args }"
Enter
Type "Clear-Host"
Enter
Sleep 600ms
Sleep 500ms
Show

Type "# 1. Inspect DBShield wire-protocol SQL firewall & MCP guardrails"
Type "# Disaster #1: Agent runs DROP TABLE, unindexed scan + leaks PII -> Slack [Approve / Reject]"
Enter
Sleep 400ms
Type "dbshield --help"
Type "dbshield demo"
Enter
Sleep 3.5s
Sleep 5.5s

Type "Clear-Host"
Enter
Sleep 300ms

Type "# 2. Verify installed DBShield engine version"
Type "# Disaster #2: Export verifiable SOC 2 / PCI-DSS / HIPAA / GDPR / EU AI Act PDF audit pack"
Enter
Sleep 400ms
Type "dbshield --version"
Type "dbshield report --compliance soc2 --audit-pdf ./dbshield-soc2.pdf"
Enter
Sleep 2s
Sleep 3.5s
5 changes: 5 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ <h3>Can DBShield be used with ORMs like Prisma or Drizzle?</h3>
<h3>Is DBShield open source?</h3>
<p>Yes! DBShield is licensed under the permissive MIT license and maintained by RitualDev Lab.</p>
</div>

<div class="faq-item" id="team-rollout" style="border: 1px solid rgba(56, 189, 248, 0.35); background: rgba(14, 165, 233, 0.08);">
<h3>Team Rollout / AI Agent Security &amp; SOC 2 Audit Setup ($299–$999/team)</h3>
<p>Need turnkey DBShield wire-proxy setup, Slack/Teams Two-Man SQL Approvals, and signed <strong>SOC 2 / PCI-DSS v4.0 / HIPAA / GDPR / EU AI Act compliance PDF bundles</strong> for your engineering team? <a href="mailto:security@ritualdev.in?subject=DBShield%20Team%20Rollout%20%26%20SOC%202%20Audit%20Setup" style="color: #38bdf8; text-decoration: underline;">Book Team Rollout (security@ritualdev.in)</a> or explore <a href="https://agentshield.ritualdev.in/#pricing" style="color: #38bdf8; text-decoration: underline;">Team &amp; Enterprise Plans</a>.</p>
</div>
</div>
</section>

Expand Down
8 changes: 8 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const HELP_TEXT = `

COMMANDS:
start Launch the MCP server on stdio transport (default)
demo Run live SQL block, PII redaction & Slack approval demo
proxy Launch PostgreSQL wire-protocol proxy on TCP port (default: 5433)
top Launch live interactive terminal process & query monitor
audit [path] Audit SQL migration files & schemas for lock hazards & drops
Expand Down Expand Up @@ -106,6 +107,13 @@ async function main() {
}

switch (command) {
case "demo": {
const { runDbShieldDemo } = await import("./demo.js");
await runDbShieldDemo();
process.exit(0);
break;
}

case "report": {
const config = await loadConfig();
const compIdx = args.indexOf("--compliance");
Expand Down
142 changes: 142 additions & 0 deletions src/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import crypto from "node:crypto";
import { SqliteAdapter } from "./adapters/sqlite.js";
import { ChatOpsNotifier } from "./approval/chatops.js";
import { ApprovalQueue } from "./approval/queue.js";
import { loadConfig } from "./config/index.js";
import { CostGateEngine } from "./cost/index.js";
import { SqlGuardEngine } from "./guard/engine.js";
import { PiiRedactor } from "./pii/redactor.js";
import { MemoryStateStore } from "./state/store.js";

export interface DbShieldDemoResult {
dropBlocked: boolean;
fullScanBlocked: boolean;
piiRedactedText: string;
slackButtonLabels: string[];
approvalRequestId: string;
durationMs: number;
}

/**
* Runs a real, self-contained in-memory disaster-prevention demo exercising
* SqlGuardEngine, CostGateEngine, PiiRedactor, ApprovalQueue, and ChatOpsNotifier.
*/
export async function runDbShieldDemo(
options: { silent?: boolean } = {},
): Promise<DbShieldDemoResult> {
const start = performance.now();
const baseConfig = await loadConfig();
const config = {
...baseConfig,
dialect: "sqlite" as const,
storagePath: ":memory:",
safetyTier: "STRICT" as const,
enableCostGate: true,
enablePiiMasking: true,
};

const adapter = new SqliteAdapter(":memory:");
await adapter.connect();
await adapter.query(
"CREATE TABLE customers (id INTEGER PRIMARY KEY, email TEXT, plan TEXT, spend_cents INTEGER);",
);
await adapter.query("INSERT INTO customers (email, plan, spend_cents) VALUES (?, ?, ?)", [
"alice.ceo@acme-corp.com",
"enterprise",
99900,
]);

const guard = new SqlGuardEngine(config);
const costGate = new CostGateEngine(config, adapter);
const redactor = new PiiRedactor();
const queue = new ApprovalQueue(new MemoryStateStore());
const notifier = new ChatOpsNotifier(
{
enabled: true,
slackSigningSecret: crypto.randomBytes(16).toString("hex"),
},
queue,
);

// Scenario 1: Agent runs destructive DROP TABLE
const dropSql = "DROP TABLE customers;";
const dropVerdict = guard.evaluate(dropSql);

// Scenario 2: Agent runs unindexed unbounded scan & error path contains PII emails
const scanSql = "SELECT * FROM customers WHERE email = 'alice.ceo@acme-corp.com';";
const scanVerdict = await costGate.evaluate(scanSql);
const rawTrace =
"SQLITE_ERROR: Constraint failed for customer alice.ceo@acme-corp.com (backup bob.cfo@acme-corp.com)";
const piiRedactedText = redactor.redactErrorMessage(rawTrace);

// Scenario 3: Bulk delete routed to non-blocking Slack [Approve / Reject] card
const bulkSql = "DELETE FROM customers WHERE plan = 'trial';";
const req = queue.enqueue({
sql: bulkSql,
operation: "DELETE",
riskLevel: "BLOCKED",
riskScore: 92,
targetTables: ["customers"],
piiRedacted: true,
agentId: "cursor-agent-1",
});
const slackPayload = notifier.buildSlackBlocks(req);
const actionsBlock = slackPayload.blocks.find((b) => b.type === "actions");
const slackButtonLabels: string[] = Array.isArray(actionsBlock?.elements)
? actionsBlock.elements.map((el: { text?: { text?: string } }) => el.text?.text || "")
: [];

await adapter.disconnect();
const durationMs = Number((performance.now() - start).toFixed(2));

if (!options.silent) {
console.log("\n🛡️ DBShield — 45-Second Real Disaster Prevented Demo (SQLite :memory:)");
console.log("──────────────────────────────────────────────────────────────────────");
console.log("1️⃣ [Agent Tries Destructive DDL]");
console.log(` SQL: ${dropSql}`);
const violationMsg = dropVerdict.violations
.map((v) =>
typeof v === "string"
? v
: (v as { message?: string; code?: string }).message ||
(v as { message?: string; code?: string }).code ||
"Destructive DDL blocked",
)
.join("; ");
console.log(
` Verdict: ${!dropVerdict.allowed ? "🛑 BLOCKED" : "ALLOWED"} (${violationMsg})`,
);

console.log("\n2️⃣ [Agent Runs Unindexed Full-Table Scan + Leaks PII Email]");
console.log(` SQL: ${scanSql}`);
console.log(
` Cost: ${scanVerdict.blocked ? "🛑 BLOCKED" : "⚠️ WARNED"} (${scanVerdict.bottlenecks[0] || "unindexed scan"})`,
);
console.log(` PII: ${piiRedactedText}`);

console.log("\n3️⃣ [Bulk Mutation Rolled Back (0 Locks) -> Slack ChatOps Card]");
console.log(` SQL: ${bulkSql}`);
console.log(` Approval ID: ${req.id} (Single-use HMAC-SHA256 token, 10m TTL)`);
console.log(` Slack Buttons Dispatched: [${slackButtonLabels.join("] [")}]`);

console.log("\n4️⃣ [Auditor-Ready SOC 2 / HIPAA / PCI-DSS v4.0 / GDPR / EU AI Act PDF]");
console.log(" npx @ritualdev-lab/dbshield report --compliance soc2 --audit-pdf ./audit.pdf");
console.log(`\nCompleted in ${durationMs}ms`);
console.log("──────────────────────────────────────────────────────────────────────");
console.log("⚡ Protect Cursor or Claude Desktop in 1 command:");
console.log(" npx @ritualdev-lab/dbshield install-cursor");
console.log(" npx @ritualdev-lab/dbshield install-claude");
console.log("🏢 Team Rollout / AI Agent Security & SOC 2 Audit Setup ($299-$999/team):");
console.log(" https://ritualdev.in/dbshield/enterprise | security@ritualdev.in");
console.log("★ Star on GitHub: https://github.com/RitualDev-Lab/DBShield\n");
}

return {
dropBlocked: !dropVerdict.allowed,
fullScanBlocked: scanVerdict.blocked,
piiRedactedText,
slackButtonLabels,
approvalRequestId: req.id,
durationMs,
};
}
21 changes: 21 additions & 0 deletions tests/demo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { runDbShieldDemo } from "../src/demo.js";

describe("DBShield Live Disaster Prevention Demo", () => {
it("blocks DROP TABLE & unindexed scan, redacts PII emails, and generates Slack buttons", async () => {
const res = await runDbShieldDemo({ silent: true });
assert.equal(res.dropBlocked, true);
assert.equal(res.fullScanBlocked, true);
assert.equal(res.piiRedactedText.includes("alice.ceo@acme-corp.com"), false);
assert.equal(res.piiRedactedText.includes("bob.cfo@acme-corp.com"), false);
assert.ok(
res.slackButtonLabels.some((label) => label.includes("Approve")),
`Expected Slack Approve button, got: ${JSON.stringify(res.slackButtonLabels)}`,
);
assert.ok(
res.slackButtonLabels.some((label) => label.includes("Reject")),
`Expected Slack Reject button, got: ${JSON.stringify(res.slackButtonLabels)}`,
);
});
});