PRAGMA writable_schema or foreign_keys = OFF: SQLite safety switched off

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

PRAGMA writable_schema = ON; lets ordinary statements edit SQLite's own schema table, and a wrong edit there can leave the file unreadable. Other pragmas turn off different protections: foreign_keys = OFF stops enforcing foreign keys, journal_mode = OFF and synchronous = OFF remove crash safety, ignore_check_constraints = ON skips CHECKs. Nothing may be broken yet: turn the setting back and check the database.

How to recover the data

  • Turn the setting back on the same connection, for example PRAGMA writable_schema = OFF; or PRAGMA foreign_keys = ON;
  • Check the file with PRAGMA integrity_check; and, if foreign keys were off, list violations with PRAGMA foreign_key_check;
  • If the database is damaged, restore it from a backup; the sqlite3 command-line shell's .recover command can salvage what is readable into a new file.

Why it happens

Some of these pragmas have legitimate uses: foreign_keys = OFF is a documented step of rebuilding a table in a SQLite migration, and synchronous = OFF speeds up bulk loads. They become a problem when the step that restores them is missing, or when SQL from outside the application can set them.

How to fix it

Set safety pragmas once in the application's connection setup, not in SQL it receives. In a migration that needs one off, restore it in the same script and verify before committing:

PRAGMA foreign_keys = OFF;
BEGIN;
-- rebuild the table
PRAGMA foreign_key_check;
COMMIT;
PRAGMA foreign_keys = ON;

With the C API, SQLITE_DBCONFIG_DEFENSIVE blocks the schema-editing features that can corrupt a database.

How to stop it from happening again

VERICTO-099 · Safety PRAGMA (SQLite) · Severity: High · AST node: PragmaStmt > PRAGMA writable_schema = on (the schema table becomes writable)

The statement the rule reports

-- pragma.sql
PRAGMA writable_schema = ON;

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect sqlite pragma.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.
✖ pragma.sql  BLOCKED  VERICTO-099 high
    PragmaStmt > PRAGMA writable_schema = on (the schema table becomes writable)
    fix: Leave safety pragmas to the connection setup; in a migration, restore them in the same script
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))
  ✖ pragma.sql  BLOCKED  VERICTO-099 high
      PragmaStmt > PRAGMA writable_schema = on (the schema table becomes writable)
      fix: Leave safety pragmas to the connection setup; in a migration, restore them in the same script

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-099] <reason>   (a reason is required)
note: VERICTO-099 is schema DDL. It is reported as FLAGGED only in a migration file (under a migrations/, migration/ or migrate/ directory, a Flyway V1__name.sql or a golang-migrate 1_name.up.sql file, or a path in .vericto.toml's migration_paths); --sql, stdin and other files are checked like SQL run against the database.

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

The corrected version

-- pragma.sql
PRAGMA table_info(users);
$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect sqlite pragma.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.
0 blocked · 1 allowed · 0 flagged · 0 monitored   (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))

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