OR 1=1 in a WHERE clause: the classic SQL injection pattern

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

SELECT id FROM users WHERE name = 'x' OR 1 = 1; returns every user: the OR 1 = 1 branch is true for every row, so the real condition no longer matters. Written into a query by hand it is a bug; appearing in a query built from user input, it is the textbook injection payload (x' OR '1'='1) that turns a login or lookup into "return everything". Find the code that builds that query.

How to recover the data

  • Find the endpoint or tool that built the query: the application logs around the time it ran usually show the input.
  • Work out what it returned or changed: with SELECT, which rows went back to the caller; with UPDATE or DELETE, which rows were affected, and restore them from a point-in-time copy if needed.
  • Rotate any secrets the query could have exposed (tokens, password hashes, API keys) and fix the query before re-enabling the endpoint.

Why it happens

The query was built by concatenating input into SQL text. Whatever the user types becomes part of the statement, so a quote followed by OR 1=1 rewrites the condition. Text-to-SQL and agent tools that paste values into SQL have the same exposure.

How to fix it

Pass values as parameters, never as SQL text; the driver sends them separately and the database never parses them as SQL:

SELECT id FROM users WHERE name = $1 LIMIT 1;

Parameters cover values only: table names, column names and sort directions must come from an allowlist. Connect the application with a role that has only the privileges it needs, so a query that does get through can do less.

How to stop it from happening again

VERICTO-090 · SQL injection: OR tautology in WHERE (OR 1=1) · Severity: Critical · AST node: SelectStmt > WhereClause > BoolExpr(OR) > always_true_branch

The statement the rule reports

-- login.sql
SELECT id FROM users WHERE name = 'x' OR 1 = 1;

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline login.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.
✖ login.sql  BLOCKED  VERICTO-090 critical
    SelectStmt > WhereClause > BoolExpr(OR) > always_true_branch
    fix: SELECT ... WHERE id = $1  -- use parameterized queries
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))
  ✖ login.sql  BLOCKED  VERICTO-090 critical
      SelectStmt > WhereClause > BoolExpr(OR) > always_true_branch
      fix: SELECT ... WHERE id = $1  -- use parameterized queries

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-090] <reason>   (a reason is required)

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

The corrected version

-- login.sql
SELECT id FROM users WHERE name = 'x' LIMIT 1;
$ npx @vericto/vericto-cli@2.3.0 check --offline login.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 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-090" => find(stmts, |s| {
    matches!(
        s.kind,
        StatementKind::Select | StatementKind::Delete | StatementKind::Update
    ) && s.has_or_tautology
})
.map(|s| {
    let stmt_name = match s.kind {
        StatementKind::Select => "SelectStmt",
        StatementKind::Delete => "DeleteStmt",
        StatementKind::Update => "UpdateStmt",

Frequently asked questions