SQLite ATTACH DATABASE opened another file: why it is risky

VERICTO-098 High In CI (offline CLI): BLOCKED

ATTACH DATABASE '/tmp/other.db' AS other; opens /tmp/other.db on the current connection, and creates it if it does not exist. From then on, statements can read and write other.* tables alongside the main database. When SQL reaches SQLite from outside the application (an agent, a user-supplied query), that means access to files on the host. Detach it and find where the statement came from.

How to recover the data

  • Close the attachment: DETACH DATABASE other;
  • Delete any database file it created that should not exist, and check which tables were read or written through it.
  • If the attached path pointed at another application's database, check that database's integrity with PRAGMA integrity_check;

Why it happens

SQLite runs inside the application process with that process's file permissions, and ATTACH is ordinary SQL. Any path where text from outside becomes SQL (a tool that lets an agent run queries, a "run your own query" feature) therefore also lets that text open files.

How to fix it

Open the databases the application needs in its own connection setup, and stop SQL from attaching more. With the C API, sqlite3_limit(db, SQLITE_LIMIT_ATTACHED, 0) sets the number of attachable databases to zero, and an authorizer callback (sqlite3_set_authorizer) can deny SQLITE_ATTACH. Open the main database read-only when the caller only needs to read.

How to stop it from happening again

VERICTO-098 · ATTACH DATABASE (SQLite) · Severity: High · AST node: AttachStmt > '/tmp/other.db' AS other

The statement the rule reports

-- attach.sql
ATTACH DATABASE '/tmp/other.db' AS other;

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect sqlite attach.sql
note: offline mode: 42 standard rules at default severities, engine 5.1.0. Custom rules, overrides, sensitive columns, allowlists and the audit trail apply online only.
✖ attach.sql  BLOCKED  VERICTO-098 high
    AttachStmt > '/tmp/other.db' AS other
    fix: Open the databases the application needs in its connection setup, never from SQL it receives
1 blocked · 0 allowed · 0 flagged · 0 monitored   (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))

✖ Vericto blocked 1 statement  (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))
  ✖ attach.sql  BLOCKED  VERICTO-098 high
      AttachStmt > '/tmp/other.db' AS other
      fix: Open the databases the application needs in its connection setup, never from SQL it receives

This is Vericto enforcing a rule — the exit code is intentional, not a crash.
To allow a finding on purpose, add an inline comment on the statement:
    -- vericto:ignore[VERICTO-098] <reason>   (a reason is required)

The CLI blocks it and exits with code 1, so the CI job fails before the merge.

Try it free, no account

The CLI checks your .sql files on your machine with the 42 standard rules: no sign-up, no API key, and no SQL leaves your computer. It is open source (AGPL-3.0-only).

npx @vericto/vericto-cli@2.3.0 check --offline --dialect sqlite migrations/

On every pull request

The vericto/check-sql GitHub Action (Apache-2.0) runs the same offline check on the .sql files a PR changes and annotates the findings on the PR. Save it as .github/workflows/vericto.yml:

on: pull_request
jobs:
  vericto:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with: { fetch-depth: 0 }
      - uses: vericto/check-sql@v1
        with: { offline: true, upload-sarif: false, dialect: sqlite }

At runtime, for AI agents

The SQL an AI agent writes never goes through a PR. The Vericto TCP proxy checks each statement between the application or agent and the database, and the MCP check_sql tool lets the agent check SQL before it runs it. Both use the runtime profile, which also blocks schema changes.

The AST condition in the engine

The rule is evaluated by the dialect's classifier; its full definition is in the open source engine's README (AGPL-3.0-only), at this page's commit.

Frequently asked questions