COPY users FROM '/var/lib/postgresql/users.csv' WITH (FORMAT csv); makes the PostgreSQL server read a file from its own disk, which requires superuser or the pg_read_server_files role. Nothing is lost, but any role that can do this can read files the server process can reach. Stream the data from the client instead with COPY ... FROM STDIN (psql \copy). Very large INSERT ... VALUES batches raise a similar concern for size.
Why it happens
Server-side COPY is the form shown in many examples, and it works in development, where the application often connects as a superuser on the same machine as the file. Huge INSERT batches come from generated code that puts a whole import in one statement, making it slow to parse, hold locks for long and fail as a whole.
How to fix it
Load from the client, which only needs INSERT on the table:
\copy users FROM 'users.csv' WITH (FORMAT csv)From application code, use your driver's COPY FROM STDIN support. Split large INSERT imports into batches; the PostgreSQL protocol also caps a statement at 65,535 bind parameters.
How to stop it from happening again
VERICTO-061 · INSERT batch with more than 10k rows · Severity: Medium · AST node: CopyStmt > FROM file
The statement the rule reports
-- import.sql
COPY users FROM '/var/lib/postgresql/users.csv' WITH (FORMAT csv);
Real CLI output
$ npx @vericto/vericto-cli@2.3.0 check --offline import.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.
! import.sql FLAGGED VERICTO-061 medium
CopyStmt > FROM file
fix: Stream the rows from the client with COPY … FROM STDIN (psql \copy) instead of a server-side file
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
-- import.sql
COPY users FROM STDIN WITH (FORMAT csv);
$ npx @vericto/vericto-cli@2.3.0 check --offline import.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-061" => find(stmts, |s| {
(s.kind == StatementKind::Insert
&& s.insert_row_count.map(|n| n > 10_000).unwrap_or(false))
|| (s.kind == StatementKind::Copy && s.copy_from_file)
})
.map(|s| {
if s.kind == StatementKind::Copy {
let mut v = violation(
rule,
s,
Some("Stream the rows from the client with COPY … FROM STDIN (psql \\copy) instead of a server-side file".to_string()),
);
v.ast_node_path = "CopyStmt > FROM file".to_string();
v
} else {
let count = s.insert_row_count.unwrap_or(0);
let mut v = violation(
rule,
s,
Some("Split the batch into chunks of ≤1,000 rows with COPY or multiple INSERT statements".to_string()),
);
v.ast_node_path = format!("InsertStmt > ValuesList count = {count}");
v
}
}),
Frequently asked questions
Related rules
- VERICTO-080: COPY … TO/FROM PROGRAM (shell execution)
- VERICTO-060: INSERT without explicit columns
- VERICTO-040: INSERT INTO … SELECT without filter