# Security Policy AskDB is pre-1.0 software that generates SQL from schema context using a language model you supply. The library (`@askdb/core`, `@askdb/client`), the CLI, and the HTTP API return generated SQL and never execute it. The exception is Studio's optional Playground **Execute** action, a local development tool that is off by default (`studio.execute.enabled`) and, when enabled, runs SQL against the database you configure for it (see [Studio execute](#studio-execute) below). Applications that run generated SQL own the approval workflows, database roles, tenant enforcement, network controls, and audit logging around it. ## Security model ### What AskDB guarantees For SQL returned by `ask()` with a built-in dialect id or a `DialectSpec`, when that dialect matches how your server reads strings (see the paragraph after this list; a custom `AskDialect` must call `validateSelectSql` itself to get the first five): - The statement starts with `SELECT` or `WITH` (after any opening parentheses). - It contains no `;` separating a second statement, no comments (`--`, `/* */`, and `#` on MySQL/MariaDB), and no string, quoted identifier, or block comment that never closes, and, on Postgres, CockroachDB, or a dialect id that is no built-in engine, no `E'…'` string continued on a later line, no `b'…'` byte string with a backslash or a continuation, and no `$N` parameter written against a word, such as `$1INTO`. SQL Server doesn't need `;` between statements, so there it also contains no second `SELECT`, no parenthesized query right after a complete value, and no label (a `:` written directly against a name or value), and its code outside strings and quoted names is plain: printable ASCII or Unicode letters and digits, with no bare `$`, no `\`, no number written against a word, and no `?` written against a name or number. A second statement that starts with `FETCH`, or with `END`, `GET` or `MOVE CONVERSATION`, isn't detected. - None of a fixed list of write/DDL keywords appears as an unquoted keyword: `INSERT`, `UPDATE`, `DELETE`, `DROP`, `TRUNCATE`, `ALTER`, `CREATE`, `GRANT`, `REVOKE`, `VACUUM`, `ANALYZE`, `COPY`, `CALL`, `MERGE`, `INTO`, plus `OUTFILE`/`DUMPFILE` for MySQL and MariaDB, `ATTACH`/`DETACH`/`PRAGMA`/`REINDEX` for SQLite, and `EXEC`/`EXECUTE`/`OPENROWSET`/`OPENQUERY`/`WAITFOR`/`SET`, control-flow verbs such as `DECLARE`/`BEGIN`/`IF`/`WHILE`, and other T-SQL statement verbs for SQL Server. - It contains no locking read, anywhere in the statement: `FOR UPDATE`, `FOR NO KEY UPDATE`, `FOR SHARE`, `FOR KEY SHARE` or `LOCK IN SHARE MODE`, and on SQL Server none of the table hints `UPDLOCK`, `XLOCK`, `HOLDLOCK`, `PAGLOCK`, `TABLOCK`, `TABLOCKX`, `ROWLOCK`, `SERIALIZABLE` or `REPEATABLEREAD` as an unquoted word, or quoted alone in parentheses right after a name, at any depth and with trailing spaces (`FROM t ([UPDLOCK])`, `t (("UPDLOCK "))`), which SQL Server also reads as the hint (`NOLOCK` and `READUNCOMMITTED` pass). Because SQL Server compares hint names loosely, every unquoted name on SQL Server must be printable ASCII, and so must a quoted name alone in parentheses right after a name; quote any other name (`[Größe]`), and qualify it when it's alone in parentheses (`COUNT(t.[Größe])`). - It calls none of the dialect's blocked side-effecting functions (for example `pg_sleep`, `set_config`, `dblink`, and `pg_read_file` on Postgres and CockroachDB, `SLEEP`, `LOAD_FILE`, `NEXTVAL` and `SETVAL` on MySQL and MariaDB, `load_extension` on SQLite), and no `NEXT VALUE FOR`, which advances a sequence on MariaDB and SQL Server. On Postgres and CockroachDB it also contains no Unicode-escaped identifier (`U&"…"`), whose escapes could spell one of them. - When the schema artifact has a tenant policy, `ask()` refuses to run without a valid `tenantScope`, and, with any scope but `global`, the tenant check refuses any statement that doesn't start with `SELECT` or `WITH` (`NOT_SELECT_OR_WITH`), under every dialect, a custom `AskDialect` included. It also refuses, under every dialect, a function whose reads it can't see, wherever the SQL names it, a column named like one included (`UNCHECKABLE_FUNCTION`): one that runs a query or reads a table named in a string (`query_to_xml`, `table_to_xml`, `crosstab`), runs SQL over another connection (`dblink`, `OPENQUERY`), or sets a value row-level security may read (`set_config`). That rule reads statements with the shared lexer, like the read-only check, and on SQL Server it ends a statement at a verb such as `EXEC` as well as at a `;`. A `subtree` scope is expanded through the host's `resolveTenantDescendants` callback or `ask()` throws. A tenant placeholder AskDB can't bind throws instead of being returned raw. Tenant IDs are passed as driver parameters by default (`tenantSqlMode: "sql-params"`); a custom `AskDialect` must set `tenantSqlMode` itself, or `ask()` throws `TENANT_SQL_MODE_REQUIRED`. Where AskDB inlines tenant IDs (`sql-only` mode, in `ask()` or a rebind), an ID that isn't printable ASCII or that contains a backslash throws `UNESCAPABLE_TENANT_ID`, so an inlined tenant ID reads the same whatever the server's string settings and connection charset. Unless the scope is `global`, the tenant check has run on the model's SQL before the tenant IDs were bound. It requires each tenant-scoped table named in the SQL, and each root table the scope covers, to have a tenant predicate: its tenant column, written as the schema spells it, compared with the tenant placeholder (`= :tenant_…_ids`, `IN (…)` or `= ANY(…)`), ANDed into a `WHERE` or inner-join `ON` clause, or into `HAVING` on a column the query groups by (not inside a string literal or comment). A column that's only selected, a literal tenant ID, or a predicate beside an `OR` or under `NOT` doesn't count. With `enforcement: strict` a failed check throws; with `warn` the findings are returned in `tenantGuardrail.warnings`. - When the schema marks tables or columns `sensitive`, the sensitive-reference check has run (unless `sensitiveGuardrailMode: "off"`). It defaults to `warn` (findings returned in `sensitiveGuardrail`); `sensitiveGuardrailMode: "strict"` makes it throw. The read-only and sensitive-column checks split the SQL into tokens the way the target engine reads it under its default string settings, then look for keywords, function calls, and identifiers. The tenant check used a simpler scanner of its own that skipped string literals and comments but didn't match the engine's reading in every case ([#342](https://github.com/Ygilany/AskDB/issues/342)); since [#815](https://github.com/Ygilany/AskDB/issues/815) it reads SQL through the same lexer, under readings that one module sets for each check and dialect. Before `@askdb/core` 1.0.0-beta.50, four of those differences could let a tenant-scoped query pass without a tenant predicate that filters ([GHSA-8pwj-6hfv-5pm4](https://github.com/Ygilany/AskDB/security/advisories/GHSA-8pwj-6hfv-5pm4)): a `$` inside a name, a table named after a keyword, an unset `backslashEscapes` on a MySQL-family `DialectSpec`, and where a `--` comment ends. Since beta.50 it reads those the way each engine does. Beta.50 still read a dollar-quoted string whose tag holds non-ASCII letters (`$é$ … $é$`) as code, where the engine reads a string; since beta.51 it reads that the way the engine does too ([GHSA-rmjw-pffc-5hjr](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rmjw-pffc-5hjr)). Before beta.52, three more differences could let a tenant-scoped query pass without an effective tenant predicate: a number or `$N` parameter written right against a keyword ([GHSA-rhwf-7742-8hwj](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rhwf-7742-8hwj)), a name, placeholder, column or join matched differently from the engine ([GHSA-rpcp-322q-q738](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rpcp-322q-q738)), and where a SQL Server name or number ends ([GHSA-cjwq-phcm-mwg7](https://github.com/Ygilany/AskDB/security/advisories/GHSA-cjwq-phcm-mwg7)). Beta.52 fixes each as its advisory describes. Before beta.53, the tenant check could also read some table names, column names, `HAVING` clauses and conditions differently from the engine ([GHSA-9w7p-c3w8-4839](https://github.com/Ygilany/AskDB/security/advisories/GHSA-9w7p-c3w8-4839)), and tied a predicate to reads it doesn't filter ([GHSA-mmrm-rfxf-ccc8](https://github.com/Ygilany/AskDB/security/advisories/GHSA-mmrm-rfxf-ccc8)), so a tenant-scoped query could pass without an effective tenant predicate. Beta.53 fixes both as their advisories describe. Before beta.54, the tenant check could also read a name's letters differently from the engine, so a tenant-scoped query could pass without an effective tenant predicate ([GHSA-rx3m-m5jr-pwch](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rx3m-m5jr-pwch)). Beta.54 fixes it as its advisory describes. Before beta.55, the tenant check could also read a name differently from the engine ([GHSA-p2v7-pv8j-c264](https://github.com/Ygilany/AskDB/security/advisories/GHSA-p2v7-pv8j-c264)), and counted a join without checking which columns it equated ([GHSA-j363-683j-2pvw](https://github.com/Ygilany/AskDB/security/advisories/GHSA-j363-683j-2pvw)), so a tenant-scoped query could pass without an effective tenant predicate. Beta.55 fixes both as their advisories describe; the join fix is partial, and its advisory names the shape that still passes. None of these checks is a SQL parser. They are defense in depth that catches common model mistakes, and **not a security boundary** against adversarial input. If your server reads strings differently, the list above holds only once the dialect matches the server: a MySQL or MariaDB server with `NO_BACKSLASH_ESCAPES` in its `sql_mode` needs a `DialectSpec` with `backslashEscapes: false`, such as `{ ...MYSQL_DIALECT, backslashEscapes: false }`, and Postgres with `standard_conforming_strings = off` needs `backslashEscapes: true`. MySQL's `ANSI_QUOTES` mode isn't supported. The CLI, the HTTP API, and Studio take only a built-in dialect id, so they always assume the default settings ([#340](https://github.com/Ygilany/AskDB/issues/340)). A mismatched dialect also affects the business values `bindPreparedQuery` inlines into its `sql`: they're escaped to match the dialect, so a value containing a backslash can escape its literal. Values passed as driver parameters (`unboundSql` with `params`) aren't affected, so run that pair for values your users type. Tenant IDs don't depend on the dialect matching: they're driver parameters by default, and an inlined one must be printable ASCII without a backslash ([#371](https://github.com/Ygilany/AskDB/issues/371), [ADR 0024](docs/adrs/0024-tenant-ids-leave-the-sql-text.md)). With a mismatched dialect, SQL that passes the checks can run a statement or function call they never saw, for example `SELECT 'x\' UNION SELECT load_file('/etc/passwd') -- '` on a `NO_BACKSLASH_ESCAPES` server with the built-in `mysql` dialect. See [Match your server's string settings](https://askdb.tools/guides/match-server-string-settings/). ### What AskDB does not guarantee - **No parsing or semantic analysis.** AskDB doesn't verify that SQL is syntactically valid, that referenced tables or columns exist, or that a `SELECT` is free of side effects. The function denylist covers known built-in functions only; a call to one of your own functions that writes passes. The locking-read check looks for words, not locks: the connection's isolation level still decides what a plain `SELECT` locks (SQL Server `REPEATABLE READ` and `SERIALIZABLE`, and MySQL and MariaDB `SERIALIZABLE`, lock what a plain `SELECT` reads until the transaction ends). - **No system-schema restrictions.** Queries against `pg_catalog`, `information_schema`, `sys`, and similar schemas are not rejected. - **No proof of tenant scoping.** The tenant check is a heuristic over SQL tokens, not a parser. It refuses a fixed list of functions that hide what they read: those built into Postgres or SQL Server, and those from the `tablefunc`, `dblink` and `xml2` extensions that ship with Postgres. A function from any other extension, such as pgRouting's `pgr_*` functions or SQLite's loadable `eval()`, passes, and so does a function of your own that reads tenant tables. It doesn't model the strings that Postgres or CockroachDB read with backslash escapes, so whenever the SQL may be read as Postgres it refuses them instead: an `E'…'` literal that continues across a newline into another literal ([#703](https://github.com/Ygilany/AskDB/issues/703)), and a `b'…'` byte string with a backslash or a continuation ([#730](https://github.com/Ygilany/AskDB/issues/730)). Since 1.0.0-beta.53 each read of a scoped table needs its own predicate in its own `SELECT` ([#399](https://github.com/Ygilany/AskDB/issues/399)), and a join on any other pair of columns than the policy declares doesn't count ([#400](https://github.com/Ygilany/AskDB/issues/400)). A root reached through the hierarchy isn't checked as a root, and joined scoped tables aren't checked for a shared scope (see the limits in [`docs/contracts/tenant-policy.md`](docs/contracts/tenant-policy.md#guardrail-validation)). AskDB does not rewrite queries to add tenant filters. AskDB trusts the IDs your `tenantScope` and `resolveTenantDescendants` callback supply. - **No complete sensitive-column detection.** Sensitive columns named in the SQL, sensitive tables in `FROM`/`JOIN`, and sensitive columns reached through `SELECT *`, `t.*`, or a whole-row reference are reported. A table written in some `FROM` forms is missed, so a wildcard over it goes unreported: a parenthesized `FROM` item (#306), a comma-joined table after a `JOIN`'s `ON`/`USING` (#307), MySQL `STRAIGHT_JOIN` used as a join (#308), and Postgres `TABLE t` inside a derived table (#309). - **No protection from untrusted schema files.** A schema directory or bundle (`schema.json`, `tables/*.md`, `concepts.md`, `tenant-policy.md`, or an inline `schemaJson`) is input AskDB parses and puts into the model prompt, so whoever can write it can change what AskDB loads and what the model sees. Before `@askdb/core` 1.0.0-beta.48, a crafted front-matter block in a schema markdown file could also run code in the process that loaded it ([GHSA-qqx9-qpw2-wcqg](https://github.com/Ygilany/AskDB/security/advisories/GHSA-qqx9-qpw2-wcqg)); since beta.48, schema front-matter must be YAML. Load schema files only from sources you trust. - **No protection from prompt injection.** The question text and schema enrichment (descriptions, concepts, tenant-policy prose) are part of the model prompt. Anyone who can write to them can influence the generated SQL. ### What integrators should do Load schema directories and bundles only from sources you trust, and keep `httpApi.allowSchemaOverride` off unless every caller that can reach `POST /ask` is trusted: an override is a schema artifact the server parses. Upgrade every AskDB package you install to a release that depends on `@askdb/core` 1.0.0-beta.55 or later, which carries the fixes for [GHSA-qqx9-qpw2-wcqg](https://github.com/Ygilany/AskDB/security/advisories/GHSA-qqx9-qpw2-wcqg) (beta.48), [GHSA-wjgj-mf9h-6g68](https://github.com/Ygilany/AskDB/security/advisories/GHSA-wjgj-mf9h-6g68) (beta.49), [GHSA-8pwj-6hfv-5pm4](https://github.com/Ygilany/AskDB/security/advisories/GHSA-8pwj-6hfv-5pm4) (beta.50), [GHSA-rmjw-pffc-5hjr](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rmjw-pffc-5hjr) (beta.51), [GHSA-rhwf-7742-8hwj](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rhwf-7742-8hwj), [GHSA-rpcp-322q-q738](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rpcp-322q-q738) and [GHSA-cjwq-phcm-mwg7](https://github.com/Ygilany/AskDB/security/advisories/GHSA-cjwq-phcm-mwg7) (beta.52), [GHSA-9w7p-c3w8-4839](https://github.com/Ygilany/AskDB/security/advisories/GHSA-9w7p-c3w8-4839) and [GHSA-mmrm-rfxf-ccc8](https://github.com/Ygilany/AskDB/security/advisories/GHSA-mmrm-rfxf-ccc8) (beta.53), [GHSA-rx3m-m5jr-pwch](https://github.com/Ygilany/AskDB/security/advisories/GHSA-rx3m-m5jr-pwch) (beta.54), and [GHSA-p2v7-pv8j-c264](https://github.com/Ygilany/AskDB/security/advisories/GHSA-p2v7-pv8j-c264) and [GHSA-j363-683j-2pvw](https://github.com/Ygilany/AskDB/security/advisories/GHSA-j363-683j-2pvw) (beta.55): `askdb` and `@askdb/http-api` 1.0.0-beta.55, `@askdb/studio` 0.2.0-beta.48, `@askdb/introspect` 0.3.0-beta.29, `@askdb/enrich` 0.2.0-beta.26, `@askdb/rag` 0.2.0-beta.35, `@askdb/postgres` 0.2.0-beta.31, `@askdb/prisma` 0.2.0-beta.29, `@askdb/mysql` and `@askdb/sqlite` 0.1.0-beta.30, and `@askdb/sqlserver` 0.1.0-beta.31, and `@askdb/core` itself if your app lists it (`@askdb/client` uses your app's `@askdb/core`). These packages pin their `@askdb/core` exactly (`@askdb/prisma` through `@askdb/introspect`), so upgrading `@askdb/core` alone can leave an older copy under them: check with `npm ls @askdb/core` or `pnpm why @askdb/core` that only 1.0.0-beta.55 or later remains. Treat generated SQL as untrusted. Execute it with a least-privilege, read-only database role; enforce tenant isolation in the database (for example, Postgres row-level security); set statement timeouts and row limits; and log every question and generated statement. See [Run generated SQL safely](https://askdb.tools/concepts/safety-boundaries/#run-generated-sql-safely). ### Studio execute Studio is a local development tool and binds to `127.0.0.1` by default. Its Playground **Execute** action is off by default (`studio.execute.enabled`). When enabled, Studio validates each query with `validateSelectSql` for the execute engine's dialect. It runs the query in a read-only transaction (SQLite: a read-only file handle; SQL Server: an always-rolled-back transaction) with a row cap and, except on SQLite, a statement timeout. Studio's API also requires a per-launch session token and checks the `Host` and `Origin` headers, so other websites open in your browser can't drive it. These guards are defense in depth, not a sandbox. Point `studio.execute` at a read-only, least-privilege database role on a non-production database, and don't expose Studio on a shared network. See the [Studio security model](https://askdb.tools/reference/studio/#security-model). ## Reporting a Vulnerability Please report suspected security issues privately by opening a GitHub security advisory through [private vulnerability reporting](https://github.com/Ygilany/AskDB/security/advisories/new). Send anything that might be a security issue this way, a check miss included. Within 7 days the maintainers either open an advisory or move the report to a public issue labelled `security-hardening` and tell you. The report stays private until then. Include: - Affected package or app. - Version, commit, or branch. - Reproduction steps. - Expected and actual impact. - Any relevant schema or request shape, with secrets and customer data removed. Do not include API keys, database credentials, production connection strings, or private schema details in reports. ## Scope Security-sensitive areas include SQL validation, schema handling, prompt construction, sensitive-field omission, tenant-scope validation and binding, local HTTP surfaces (the HTTP API and Studio, including Studio execute), package publishing, dependency supply chain, and any path that could expose secrets or user data. **A vulnerability is a break in something AskDB owns.** A report gets a GitHub security advisory only when AskDB itself breaks something it owns, in a host that follows [What integrators should do](#what-integrators-should-do). That covers code execution (such as [GHSA-qqx9-qpw2-wcqg](https://github.com/Ygilany/AskDB/security/advisories/GHSA-qqx9-qpw2-wcqg), through schema front-matter), tenant-scope validation and tenant IDs that AskDB binds or inlines wrongly (such as [GHSA-wjgj-mf9h-6g68](https://github.com/Ygilany/AskDB/security/advisories/GHSA-wjgj-mf9h-6g68), in `sql-only` mode), leaked secrets, access control on AskDB's own local servers (the HTTP API, and Studio including Studio execute: its session token and its `Host` and `Origin` checks), and package publishing and the dependency supply chain. This rule applies to reports received from 2026-11-11 on; the advisories published before then stay as published. **A check that misses something is a public hardening bug.** SQL that gets past the read-only check, the tenant check or the sensitive check is a bug we want to hear about: for example, a write keyword hidden from the keyword check, a second statement that isn't detected, a tenant-scoped table that passes without a tenant predicate that filters, or a check that reads a string, a name or a comment differently from the engine. The checks are defense in depth, not a security boundary, so a miss is tracked as a public issue labelled `security-hardening` and fixed in a normal release. This holds even when the miss would let a tenant-scoped query read another tenant's rows: database-level tenant enforcement is the boundary that stops it. Not a vulnerability: a report whose harm comes only from generated SQL being executed without the controls in [What integrators should do](#what-integrators-should-do), such as with a privileged role or without database-level tenant enforcement, with nothing AskDB owns broken. A check miss behind such a report is still a hardening bug. Model output quality (incorrect but harmless SQL) is out of scope. ## Supported Versions Until AskDB reaches 1.0, security fixes target the latest public release and `main`.