Skip to content

No-op DML statements report success for users without branch write permission #3833

Done

Description

@myml

Summary

DML statements that end up editing zero rows report success even when the user has no write permission on the current branch (branch control). The permission error is produced, but swallowed before it reaches the client.

This affects PostgreSQL/Doltgres users relying on dolt_branch_control to keep contributors off main: UPDATE t SET c = c (or DELETE ... WHERE <no match>) returns UPDATE 1 / DELETE 0 instead of the expected does not have the correct permissions on branch `main` error. No data is changed, but the statement reports success, which is misleading for review workflows and for clients/automation that treat a successful return as "the write was authorized and applied".

Repro (Doltgres 1.5.1 and current main)

Setup (superuser):

CREATE DATABASE audit;
-- in audit:
DELETE FROM dolt_branch_control;
INSERT INTO dolt_branch_control VALUES ('%','%','postgres','%','admin');
INSERT INTO dolt_branch_control VALUES ('audit','main','app_writer','%','write');
CREATE USER contributor PASSWORD 'c';
GRANT USAGE ON SCHEMA public TO contributor;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO contributor;
CREATE TABLE salary(id int primary key, name text, amount int);
INSERT INTO salary VALUES (1,'张三',12500);

As contributor (no branch-control rule for audit/main):

UPDATE salary SET amount = amount WHERE id = 1;   -- actual: UPDATE 1, expected: permission error
UPDATE salary SET amount = 12500 WHERE id = 1;    -- actual: UPDATE 1, expected: permission error
UPDATE salary SET amount = 777   WHERE id = 1;    -- actual: permission error (correct)
INSERT INTO salary VALUES (2,'李四',9000);         -- actual: permission error (correct)
DELETE FROM salary WHERE 1 = 0;                   -- actual: DELETE 0, expected: permission error

Data is unchanged after the successful no-op statements (SELECT still returns the original values, dolt_status is empty).

Root cause

The branch control check runs in WritableDoltTable.Updater / Deleter / Inserter (dolt sqle). When it fails, the error is wrapped in sqlutil.StaticErrorEditor and only returned from the per-row Update / Delete / Insert methods. go-mysql-server's updateIter skips Update for rows where old and new values are equal (sql/rowexec/update.go), and a DELETE with no matching rows never calls Delete. StaticErrorEditor.Close returned nil, so the captured error was dropped at statement end.

Fix

Upstream fix in dolt (the code is shared by Doltgres): dolthub/dolt#12462 — StaticErrorEditor.Close now returns the captured error, with regression tests in BranchControlBlockTests.

Once dolt#12462 is merged and the dolt dependency is bumped in Doltgres, this should be covered by a Doltgres-level regression test (e.g. in testing/go/auth_test.go, branch-control section): a contributor without a write rule on main must get a permission error for a no-op UPDATE, and an authorized role must still succeed.

Impact / workaround

Only affects statements that change no rows. Data integrity is not at risk, but a successful return must not be treated as authorization to write, and tests for branch permissions should use statements that actually change values.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions