SQLite load_extension() or readfile() called from SQL: what it means

VERICTO-100 Critical In CI (offline CLI): BLOCKED

SELECT load_extension('/tmp/ext.so'); asks SQLite to load a shared library into the application process and run its initialisation code. If extension loading is enabled for SQL, that is arbitrary native code running with the application's permissions. readfile(), writefile() and edit() (from the sqlite3 shell) read and write files, and fts3_tokenizer() can register a tokenizer by raw pointer. If one of these succeeded with SQL from outside, treat the host as compromised.

How to recover the data

  • Find where the statement came from (application logs, the tool or agent that sent it) and stop that path.
  • If the call succeeded, isolate the host, keep the library file it loaded for analysis, and rotate the credentials the process had access to.
  • If it failed because extension loading is disabled, nothing was loaded; still fix the path that let the SQL through.

Why it happens

Extension loading is turned on because the application needs one extension, and the switch that enables it can also enable the SQL function. Tools built on the sqlite3 shell expose its file functions. Either way, SQL that reaches the database from outside gains access to native code or the file system.

How to fix it

Load the extensions you need from application code, and keep the SQL function off. With the C API, sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, NULL) enables only the C-level sqlite3_load_extension(), not load_extension() in SQL. In Python, call conn.enable_load_extension(True), load, then conn.enable_load_extension(False). Do not run untrusted SQL through the sqlite3 shell.

How to stop it from happening again

VERICTO-100 · Extension loading or file functions (SQLite) · Severity: Critical · AST node: FunctionCall > load_extension() (native code or the file system)

The statement the rule reports

-- ext.sql
SELECT load_extension('/tmp/ext.so');

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline --dialect sqlite ext.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.
✖ ext.sql  BLOCKED  VERICTO-100 critical
    FunctionCall > load_extension() (native code or the file system)
    fix: Load extensions in the application's connection setup with extension loading disabled for SQL
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))
  ✖ ext.sql  BLOCKED  VERICTO-100 critical
      FunctionCall > load_extension() (native code or the file system)
      fix: Load extensions in the application's connection setup with extension loading disabled for SQL

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-100] <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