SELECT * without WHERE: why it is risky and what to write instead

VERICTO-051 Medium In CI (offline CLI): FLAGGED

SELECT * FROM users LIMIT 500; returns 500 arbitrary rows with every column of users: password hashes, tokens, personal data, whatever the table holds now or gains later. The LIMIT bounds the size, not what is exposed. Nothing is lost, but list the columns you need and filter the rows you mean.

Why it happens

SELECT * is the shortest way to look at a table, so it ends up in exports, debug endpoints and generated queries. Its result changes whenever a column is added, so code that once returned harmless columns starts returning a new sensitive one without any change of its own.

How to fix it

Name the columns and add the condition that describes the rows you want:

SELECT id, email FROM users WHERE id = 42;

For roles used by agents or reporting tools, grant SELECT only on the columns or views they need, so a SELECT * cannot reach the rest.

How to stop it from happening again

VERICTO-051 · SELECT * without WHERE clause · Severity: Medium · AST node: SelectStmt > TargetEntry = STAR & WhereClause = NULL

The statement the rule reports

-- export.sql
SELECT * FROM users LIMIT 500;

Real CLI output

$ npx @vericto/vericto-cli@2.3.0 check --offline export.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.
! export.sql  FLAGGED  VERICTO-051 medium
    SelectStmt > TargetEntry = STAR & WhereClause = NULL
    fix: SELECT col1, col2 FROM ... WHERE <condition>
0 blocked · 0 allowed · 1 flagged · 0 monitored   (ruleset standard@engine-5.1.0 · mode: offline (engine 5.1.0, 42 standard rules, no workspace policy))

The CLI marks it FLAGGED and exits with 0: it is reported without stopping the job. With --fail-on flag (or fail_on = "flag" in .vericto.toml) it exits with 1 and the job fails.

The corrected version

-- export.sql
SELECT * FROM users WHERE id = 42 LIMIT 1;
$ npx @vericto/vericto-cli@2.3.0 check --offline export.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-051" => find(stmts, |s| {
    s.kind == StatementKind::Select
        && s.select_is_star
        && s.where_presence == WherePresence::Absent
})
.map(|s| {
    let mut v = violation(
        rule,
        s,
        Some("SELECT col1, col2 FROM ... WHERE <condition>".to_string()),
    );
    v.ast_node_path = "SelectStmt > TargetEntry = STAR & WhereClause = NULL".to_string();
    v
}),

Frequently asked questions