ALTER TABLE accounts DISABLE ROW LEVEL SECURITY; stops PostgreSQL from applying the table's policies: every role with SELECT on accounts now sees every row, not only its own. The policies are still defined, so turning RLS back on restores them. DISABLE TRIGGER works the same way for triggers (audit, validation), and DROP TRIGGER removes one for good.
How to recover the data
- Turn the protection back on:
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;(orENABLE TRIGGER). - Check that the policies are still there with
SELECT * FROM pg_policies WHERE tablename = 'accounts'; - Review what ran against the table while it was off (database logs,
pg_stat_statements, application logs) and treat any unexpected reads as a data exposure. - For a disabled trigger, find the rows written in that window and apply what the trigger would have done (audit rows, derived columns).
Why it happens
RLS and triggers get in the way of maintenance: a backfill that must see every tenant, a bulk load that a trigger slows down, a debugging session. Someone disables the protection for "a minute" and the step that turns it back on is skipped or fails. On platforms that expose tables through an API and use RLS as their access control (Supabase, for example), a table without RLS is readable through that API.
How to fix it
Leave RLS and triggers enabled and scope the operation instead: run maintenance with a dedicated role that has BYPASSRLS, used only by that job, or add a policy for it. If a trigger really must be off, disable and re-enable it inside the same transaction so it cannot stay off:
BEGIN;
ALTER TABLE accounts DISABLE TRIGGER accounts_audit;
-- the bulk operation
ALTER TABLE accounts ENABLE TRIGGER accounts_audit;
COMMIT;How to stop it from happening again
VERICTO-019 · ALTER TABLE DISABLE TRIGGER / RLS · Severity: High · AST node: AlterTableStmt > DisableTrigger
The statement the rule reports
-- migrations/0049_rls.sql
ALTER TABLE accounts DISABLE ROW LEVEL SECURITY;
Real CLI output
$ npx @vericto/vericto-cli@2.3.0 check --offline migrations/0049_rls.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.
! migrations/0049_rls.sql FLAGGED VERICTO-019 high
AlterTableStmt > DisableTrigger
fix: Keep triggers / RLS enabled; scope the operation instead
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))
In a migration file the CLI marks it FLAGGED and exits with 0: a schema change in a migration is usually intended, so it is raised for review instead of blocked. With --fail-on flag (or fail_on = "flag" in .vericto.toml) it exits with 1 and the job fails. Outside a migration (--sql, stdin or another file) it blocks, as the proxy and MCP check_sql do.
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-019" => find(stmts, |s| {
(s.kind == StatementKind::AlterTable
&& matches!(s.alter_table_kind, Some(AlterTableKind::DisableTrigger)))
|| (s.kind == StatementKind::Drop
&& matches!(s.drop_object, Some(DropObjectKind::Trigger)))
})
.map(|s| {
if s.kind == StatementKind::Drop {
let mut v = violation(
rule,
s,
Some("Keep the trigger; drop it only through a reviewed, versioned migration".to_string()),
);
v.ast_node_path = "DropStmt > ObjectType = TRIGGER".to_string();
v
} else {
let mut v = violation(
rule,
s,
Some("Keep triggers / RLS enabled; scope the operation instead".to_string()),
);
v.ast_node_path = "AlterTableStmt > DisableTrigger".to_string();
v
}
}),
Frequently asked questions
Related rules
- VERICTO-082: GRANT / REVOKE
- VERICTO-017: ALTER TABLE DROP CONSTRAINT (FK/PK/CHECK)
- VERICTO-081: DO anonymous code block