Skip to content

[Bug]: ordinary view bypasses row rewrite rule and exposes hidden rows #29093

Closed

Description

@slyunnn

Description

An ordinary view can bypass a base-table row rewrite rule. With the required rewrite setting enabled, the affected user sees only authorized rows when querying the base table directly, but sees an unauthorized row when querying a normal view that expands the same table.

Environment

  • MatrixOne: main@480b91764a94cf9ab49d3f2b43a60cb63ce677c6
  • Deployment: macOS arm64, single-node local isolated MatrixOne service
  • Required session setting: enable_remap_hint = 1

Steps to reproduce

CREATE DATABASE rcac_view;
CREATE TABLE rcac_view.sales(id INT PRIMARY KEY, tenant INT, amount INT);
INSERT INTO rcac_view.sales VALUES (1,1,10), (2,1,20), (3,2,30);

CREATE VIEW rcac_view.v_sales AS
  SELECT id, tenant, amount FROM rcac_view.sales;

CREATE ROLE rcac_view_r;
ALTER ROLE rcac_view_r ADD RULE
  "select * from rcac_view.sales where tenant = 1"
  ON TABLE rcac_view.sales;

CREATE USER rcac_view_u IDENTIFIED BY '<test-password>' DEFAULT ROLE rcac_view_r;
GRANT CONNECT ON ACCOUNT * TO rcac_view_r;
GRANT SELECT ON TABLE rcac_view.sales TO rcac_view_r;
GRANT SELECT ON VIEW rcac_view.v_sales TO rcac_view_r;

Log in as rcac_view_u and execute:

SET enable_remap_hint = 1;
SELECT id FROM rcac_view.sales ORDER BY id;
SELECT id FROM rcac_view.v_sales ORDER BY id;

Actual behavior

direct base-table query:  1, 2
ordinary-view query:      1, 2, 3

The direct query proves the row rule is active for this session. The view query exposes row id=3, whose tenant=2 does not satisfy the rule.

Expected behavior

Both queries must return only 1, 2. The view execution path must preserve the base-table row rule (or reject access when its security model requires that); it must never expose rows hidden by the rule.

Stability / impact

  • Reproduced directly on current main in an isolated service.
  • A user with ordinary view access can read rows hidden by the base table's row access-control rule.
  • This is a data-access-control bypass, not an EXPLAIN-only observability issue.

Evidence and initial scope

Regression coverage

After remediation, add an end-to-end regression that creates a controlled base table and ordinary view, then verifies that direct and view queries produce the same authorized row set. Cover nested views and supported definer/invoker semantics separately if applicable.

Activity

  1. added
    kind/bug
    on Sep 18, 2026
  2. added theissue type on Sep 18, 2026
  3. added this to the MO-202609 milestone on Sep 18, 2026
  4. added
    ai-easy
    on Oct 9, 2026
  5. slyunnn commented on Oct 10, 2026

    @slyunnn
    Author

    Regression and extended verification for #29093 (2026-10-10)

    Verification Environment

    • Fetched main and built 0ccc989731f9c2b40d31554a44ca505c656c0e62 — feat(sql): add durable cluster-scoped UUID_SHORT() (#29805) — with Go 1.27.1 on Linux/ARM64. The newly started runtime reports this commit.
    • Binary SHA-256: f2134a94b5a79c6a71def4475dfc913cb3300904d13bcf0fecf56b0d3c270c23.
    • Fresh isolated topology: 2 CN / 1 TN / 1 Log service / Proxy, local-disk storage.
    • All endpoints were reachable and executed the regression: Proxy 127.0.0.1:6661 → container 6009, CN1 127.0.0.1:16661 → 16001, CN2 127.0.0.1:16662 → 16002. Alternate host ports avoid existing services; the pre-existing 6001/16001/16002 deployment was not tested.
    • Clients: MySQL CLI and MOTR/PyMySQL over TCP using text protocol COM_QUERY. Access-control assertions ran as a dedicated restricted user, not as the setup administrator.

    What Was Covered

    • OK — Original reproduction: in the same authenticated session with enable_remap_hint=1, both the direct table and ordinary View return only IDs 1,2; unauthorized ID 3 is absent, on all endpoints.
    • OK — Star projections and nested aliased Views preserve the same authorized row set.
    • OK — Aggregate View returns only tenant 1 with sum 30; View/table join returns count 2 and sum 30.
    • OK — Explicit predicates selecting unauthorized ID 3 or tenant 2 return count 0.
    • OK — With enable_remap_hint=0, direct, ordinary and nested View queries still enforce mandatory role rules on this main revision.
    • OK — Accepted SQL SECURITY DEFINER and SQL SECURITY INVOKER View declaration forms both preserve the restricted row set in this fixture. This does not assert full MySQL definer/invoker context equivalence.
    • OK — A View without a corresponding SELECT grant is rejected with error 20101; the same connection remains usable afterward.
    • OK — MOTR recorded successfully and passed two normal replays through each endpoint: 6 replays, 45 statements per replay, no failures or skips.
    • OK — Parallel MOTR run with the existing isolated issue_25186_insert_select_remap_hint case passed: 2/2 cases, 66/66 statements, -j 2.
    • OK — Test user, role and database cleanup verified with zero remaining MOTR fixture objects; ad hoc reproduction objects were also removed.
    • Not covered — Binary prepared-statement protocol, distinct definer identities, cross-tenant/subscription behavior, forced multi-CN execution plans, and the complete access-control BVT suite. No claims are made for these broader surfaces.

    Findings

    The reported ordinary-View row-rule bypass is no longer reproducible on the tested main.

    Related merged fix: #29695 — fix(plan): preserve row rewrite rules through views, commit a23874569c5669febbe641f8b1c230afad3426e0, contained in the tested main. It propagates the outer row-rewrite option into the independent View binding context and preserves the qualifier required by stored View projections.

    MOTR / BVT Coverage

    • Existing product zz_accesscontrol/role_rule.sql contains ordinary-View coverage. Added MOTR coverage for nested/star/aggregate Views, forbidden-row predicates, joins, accepted security declaration forms, permission rejection and connection health.
    • Files: suites/14_issue_regression/t/issue_29093_view_row_rule.test and the matching .result file. The recorded baseline was reviewed against explicit authorized-row expectations before replay.
    • Independent branch: test/issue-29093-view-row-rule.
    • Source commit: 3f75461cc9ee2f42ceab569b39f8cf66dd40a2f0, test: add MOTR regression for #29093.
    • The case uses isolated object names and session-local settings and is eligible for runner parallelism. Replays of this same case across endpoints were serial because they share fixture names; the initial read-only endpoint checks and the separate-case -j 2 run were parallel. This is not a claim of engine-parallel execution coverage.
    • No MatrixOne production source changes.

    Final Conclusion

    Fixed for the reported bypass and the tested View expansions on 0ccc989731f9c2b40d31554a44ca505c656c0e62, verified through Proxy and both CNs.

    Large-data regression is not needed: the defect is policy propagation during View binding. Three controlled rows distinguish authorized from unauthorized visibility; additional volume would not exercise a different boundary for this defect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

4.3-devai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions