[Bug]: UPDATE/DELETE bypass role rules: pruned columns readable in predicates and hidden rows matched
メンテナーはふだん 1 日以内に返信
@iamlinjunhong がすでに取り組んでいます。
2026年11月25日 から。
評価
この issue はまだ評価されていません。
説明
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)
- 主要言語
- Go
- スター
- 1.9k
- フォーク
- 312
- 平均マージ
- 22時間 59分
- マージ済み PR(30日)
- 736
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
matrixorigin/matrixone のほかの issue
-
kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
matrixorigin/matrixone#33363 ·
メンテナーはふだん 1 日以内に返信
-
kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
matrixorigin/matrixone#33362 ·
メンテナーはふだん 1 日以内に返信
-
SLEEP rejects NULL and negative durations that MySQL accepts対応中かも @XuPeng-SH が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
matrixorigin/matrixone#32653 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CI対応中かも @XuPeng-SH が今日担当しました。 オープンkind/bug needs-triage
matrixorigin/matrixone#33371 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CI対応中かも @XuPeng-SH が今日担当しました。 オープンkind/bug needs-triage
matrixorigin/matrixone#33370 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
matrixorigin/matrixone の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pg-sharding/spqr#3314 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
slavakurilyak/awesome-ai-agents#1051 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
google-gemini/gemini-api-cli#247 ·
メンテナーはふだん 1 日以内に返信