SELECT pg_sleep(10); holds a database connection for ten seconds and does nothing else. Nothing is lost, but legitimate application code rarely sleeps inside SQL. When a sleep shows up in queries built from user input, it is usually someone testing for time-based blind SQL injection: if the response is ten seconds late, the input reached the query. Find where that query is built.
Why it happens
An attacker who cannot see query results can still learn whether input is injected by making the database wait: ' OR pg_sleep(10)-- on PostgreSQL, SLEEP(10) on MySQL, WAITFOR DELAY on SQL Server. Many such calls at once also tie up the connection pool. Occasionally a sleep is left in a test or debugging script.
How to fix it
Use parameterized queries everywhere user input reaches SQL, so input is never parsed as SQL. Limit how long a statement can run (PostgreSQL statement_timeout, MySQL max_execution_time for SELECT) and connect the application with a role that has only the privileges it needs.
ALTER ROLE app SET statement_timeout = '5s';How to stop it from happening again
VERICTO-070 · Use of SLEEP() or PG_SLEEP() · Severity: High · AST node: FunctionCall > pg_sleep()
The statement the rule reports
-- probe.sql
SELECT pg_sleep(10);
Real CLI output
$ npx @vericto/vericto-cli@2.3.0 check --offline probe.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.
✖ probe.sql BLOCKED VERICTO-070 high
FunctionCall > pg_sleep()
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))
✖ probe.sql BLOCKED VERICTO-070 high
FunctionCall > pg_sleep()
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-070] <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 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 }
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 a deterministic predicate over the AST, in src/rules/evaluator.rs of the open source engine (AGPL-3.0-only), at this page's commit:
"VERICTO-070" => find(stmts, |s| {
s.kind == StatementKind::FunctionCall
&& (s.function_name
.as_deref()
.is_some_and(is_sleep_function)
|| s.sqlite == Some(SqliteRisk::TimeProbe))
})
.map(|s| {
let fname = s.function_name.as_deref().unwrap_or("sleep");
let mut v = violation(rule, s, None);
v.ast_node_path = format!("FunctionCall > {fname}()");
v
}),
Frequently asked questions
Related rules
- VERICTO-090: SQL injection: OR tautology in WHERE (OR 1=1)
- VERICTO-050: SELECT without LIMIT
- VERICTO-080: COPY … TO/FROM PROGRAM (shell execution)