Security Model

Insightics runs inside your production database. A write that escaped would be data loss in a system we do not own and cannot restore. So read-only is not a setting or a convention. It is a stack of independent mechanisms, none of them load-bearing alone.

The constraint everything is built around

SQL Derived From A User Prompt Can Only Read. There Is No Exception.

Three in the guard, three in the database, one on the wire. Each would have to fail, independently, for a write to land.

  1. Guard01 / 07

    Parse and allowlist

    Postgres’s own parser, compiled to WebAssembly, reads the query. Exactly one statement, it must be a SELECT, and every node type, field and function has to be on an allowlist.

  2. Guard02 / 07

    Deparse round-trip

    What executes is re-emitted from the validated tree, never the model’s text. Obfuscation in the original cannot survive, because it was never in the tree.

  3. Guard03 / 07

    Row cap

    The LIMIT is clamped into the validated tree, then read back out of the emitted SQL to confirm it is really there.

  4. Database04 / 07

    ik_reader role

    Queries run as a role granted SELECT and nothing else. There is no write privilege to escalate to.

  5. Database05 / 07

    Sealed read-only transaction

    BEGIN READ ONLY, SET LOCAL only, confirmed by the server, and always rolled back, whatever happened inside.

  6. Database06 / 07

    Row-level security

    Tenant scoping is enforced by Postgres on every access path, including subqueries, from a verified token rather than from the prompt.

  7. Wire07 / 07

    Narrow responses

    Errors cross the wire as coarse statuses. Deny codes, prompts and token counts stay on the server.

  8. Proof, not trust

    ik doctor

    Checks the database-side guarantees against the live catalog and exits non-zero when the proof fails. Run it in CI.

The package that decides whether SQL is safe cannot execute SQL, cannot open a socket and cannot read the filesystem. It takes a string and returns a verdict. Something else runs the query.

sql-guard verdicts
import { createGuard } from "insightics-sdk/sql-guard";

const guard = await createGuard({ allowedSchemas: ["public"] });

guard("SELECT count(*) FROM users");
// { ok: true, sql: "SELECT count(*)\nFROM users", tables: [...], rowLimit: null }

guard("SELECT 1; DROP TABLE users");
// { ok: false, code: "E_MULTI_STATEMENT" }

guard("SELECT * INTO exfil FROM users");
// { ok: false, code: "E_FIELD_NOT_ALLOWED" }

guard("SELECT pg_read_file('/etc/passwd')");
// { ok: false, code: "E_FUNCTION_NOT_ALLOWED" }
  • It never throws

    An exception is a bypass waiting for somebody’s try/catch. Every failure comes back as a verdict.

  • A denial has no SQL

    ok: false carries no .sql field, so the compiler rejects code that skips the check.

  • It re-emits, never forwards

    The SQL it returns is printed from the validated tree, not passed through from your input.

  • Five dependencies, total

    Its whole transitive dependency tree is five packages, all parts of the Postgres parser. Auditable in a minute.

The trust boundary is a package boundary. The build fails on a breach, through the typecheck when a dependency is undeclared and through dependency-cruiser when it is reached another way.

  • react never imports core

    One such import in a Next.js client component would ship your connection string into the browser bundle.

  • llm never imports sql-guard

    The code talking to an untrusted model does not sit beside the code deciding what is trusted.

  • core never imports llm

    The engine declares the model provider shape structurally, so reaching a model costs it no dependency.

Insightics’ own metadata writes use a different role, touch only the insightics schema and never carry user-authored SQL. That guarantee is enforced in code today, and is not yet checked by ik doctor.

Found a hole?

Report It Privately

Use GitHub’s private security advisory form, not a public issue. A failing SQL string, or the question that produced one, is the most useful thing you can send. SECURITY.md covers scope and what counts as a vulnerability.

Most valuable contribution

Try To Break The Guard

New attack cases in the adversarial corpus are the contribution we value most. A case that currently passes the guard is a bug report we would very much like to receive.

Come Build It
With Us

Ask questions, show what you are building, and help decide what Insightics does next. The Discord is where the roadmap gets argued out.