Repository navigation
Description
Description
After CREATE INDEX i_xyz ON cmp_idx (x, y), MO materializes the index into a physical table. Catalog rows are hidden from SHOW TABLES / SHOW PUSH list, but** the physical secondary-index table remains fully addressable and writable by ordinary user SQL** once its name is known (name discoverable via mo_catalog.mo_indexes.index_table_name):
-- discover
SELECT index_table_name FROM mo_catalog.mo_indexes
WHERE table_id = (SELECT rel_id FROM mo_catalog.mo_tables WHERE relname = 'cmp_idx');
-- → `__mo_index_secondary_01a17cca-...`
-- ordinary user account, no special privileges:
SELECT COUNT(*) FROM `__mo_index_secondary_01a17cca-...`; -- 5000 rows readable ✓
SHOW CREATE TABLE `__mo_index_secondary_01a17cca-...`; -- schema readable:
-- CREATE TABLE `...` (
-- `__mo_index_idx_col` varchar(65535) COLLATE binary NOT NULL,
-- `__mo_index_pri_col` int NOT NULL,
-- PRIMARY KEY (`__mo_index_idx_col`) )
INSERT INTO `__mo_index_secondary_01a17cca-...` VALUES ('0xdeadbeef', 99999); -- accepted!
SELECT COUNT(*) FROM `__mo_index_secondary_...`; -- 5001A fabricated index row was successfully inserted into a secondary-index table from a plain user session. Analogous writes can DELETE real index entries (making rows unreachable via index while present in base) or UPDATE __mo_index_pri_col to point a key at an arbitrary primary key.
Verified corruption semantics (concrete observation)
- After the INSERT,
SELECT COUNT(*) FROM cmp_idx WHERE x = 424242;returns 0 — the fabricated entry occupies the index but points at a nonexistent primary key (99999), so index-driven lookups behave as if a row exists in the index with a broken primary link (point reads by that key error or silently miss depending on plan). - Base-table
SELECT COUNT(*) FROM cmp_idxreturns 5000 — index now holds 5001 entries vs. 5000 rows: index/base divergence is permanent (no trigger, no reconciliation; the extra entry survives until the table is dropped). SHOW COLUMNSon the hidden table lets the user who is not the table owner learn the full internal encoding scheme (__mo_index_idx_col,__mo_index_pri_col).
Impact
- Data integrity: any user with the base-table DML privilege (or even just any user, if permissions on hidden tables are not gated) can silently corrupt secondary indexes — insert/delete/update on the physical table bypasses all invariants and leaves the index permanently inconsistent with the base data (dangling pri-key links, missing entries). Query results then differ depending on the plan (index scan vs full scan).
- Security: hidden tables contain a copy of user data (for index-only scans); if any user can read them, data isolation between users may leak rows that the base table's row-level permissions would deny.
- SQL injection enablers: any tool that passes through attacker-influenced identifiers (SDK builders, REST layers) multiplies the exposure, since these tables are directly hammerable by name.
Reproduction of DELETE variant (skipped in session, but trivially implied)
DELETE FROM `__mo_index_secondary_...` WHERE __mo_index_pri_col = 50;
-- → base row with id=50 becomes unreachable via index by key lookups; still visible by full scanExpected behavior
- Reject direct DML on
__mo_index_secondary_*/__mo_index_unique_*tables for non-system users (as MySQL does for internal system objects). At minimum require a system-variable escape hatch (e.g.SET allow_internal_table_dml = 1for debugging). - Gate
SHOW CREATE TABLE/SHOW COLUMNS/ direct SELECTs on hidden index tables behind a similar privilege, and/or keep them out of the normal grant model entirely (parser-level rejection is safest). - Consider making the internal table name un-guessable except to sys (mock it with a session-scoped mapping), and ensure that the index-access path is always through the base table.
- Add an invariant checker (e.g.
mo_checksubcommand) to diff base-table rows vs index entries, enabling detection of exactly this divergence.
Activity
test(bvt): make index_cache_size_bounds compatible with hidden index …
fix: close stored SQL hidden-index access bypasses (matrixorigin#31436)
fix: restrict direct access to physical index relations (#32032)
XuPeng-SH commentedon Nov 6, 2026
转 QA 验证:#32032 已合入 main
证据与限制:
建议 QA:
按转测流程移除研发负责人,改派唯一 Ariznawlll;issue 保持 open。
MatrixAdventurer commentedon Nov 7, 2026
【修复核实】结论:已修复,可关闭。
PR #32032(11-06 20:43 合入 main,169 文件):
仍缺:只读条件下未起集群复现原 SQL;issue ③④(命名不可猜、mo_check 校验器)提案未随本 PR 实现;合入时刻 CI 记录为一轮被取消的 runs(无失败用例),最终 head 的全量绿色日志未逐项核查。
@Ariznawlll 请确认关闭。
本操作由LW授权的MOI智能体提交
slyunnn commentedon Nov 11, 2026
Regression and extended verification for #31436 (2026-11-11)
Verification Environment
45917e803f2915f6f0838b2b2fe9f591fc5b6018,fix(plan): fold contradictory same-column predicates to near-zero estimates (#32502).git_version()=45917e803fthrough Proxy6001, CN116001and CN216002. All three endpoints executed the issue checks.2 CN / 1 TN / 1 Log service / Proxy, macOS arm64, Go1.27.1.database/sql+go-sql-driver/mysql,interpolateParams=false, supplied native prepared-statement evidence forMIN/MAXparameter changes and physical-index role changes.What Was Covered
SELECT/INSERT/UPDATE/DELETEreal unique and secondary physical index tables through any endpoint.CREATE/COLUMNS, TRUNCATE/DROP/ALTER,CTAS, view creation and text PREPARE of physical relations are rejected. Current TABLES/COLUMNS/PARTITIONS metadata filters their entries.sys/moadmindiagnostic counts remain available. Ordinary indexed base-table queries and baseINSERT/UPDATE/DELETEstay correct, with5,000rows and expected complete ID sum after cleanup.moadminare rejected after switching to an ordinary role. The same statement and connection work again after restoringmoadmin.Findings
fix: restrict direct access to physical index relations, mergebfbb2645c03422a4c5d3a77a9e56942710944643is included in the frozen main. PR #32032MOTR / BVT Coverage
issue_31436_index_access.testand matching.resultinsuites/14_issue_regression; the physical-index case also invokes its Go protocol helper through the existing module.test/issue-31436-index-access, source commit0095889fbd937ee691471c2655ff9af59447d4ae, weekly cherry-pick6aa5c69948bc5cf490f6452fd85c26a5ff70fa74. Recording and2replays per endpoint passed, then branches were pushed and remote/upstream verified. Weekly MOTR PR #3219cases with-j 5 --repeat 2through each endpoint,54/54executions total. The new cases use separate databases, roles and connections, with no global-variable changes. This is runner concurrency.199test/subtest passes across7packages with selected tests. The independent forced-two-CN aggregate fixture also passed.Final Conclusion
Fixed for the original issue contract on the verified build and paths.
Large-data regression — Not required. Authorization is determined by caller identity and protected relation kind. The
5,000-row control checks preserved index/base behavior.