Skip to content

[Bug]: another same-account session can read, modify, or drop a temporary table via its physical name #30495

Closed as not planned

Description

@iamlinjunhong

Environment

  • MatrixOne: main @ commit b111224 (workspace build), single-process mo-service from etc/launch with ports offset by 20000; MySQL-protocol clients: mysql CLI and pymysql. macOS 15.7, arm64.
  • Implementation under test: session temporary tables are persisted physical tables named __mo_tmp_<session-uuid>_<db>_<generation>_<alias> (pkg/sql/compile/temporary_ddl.go, pkg/defines/temp_table.go) and are reached through a per-session alias map.

Actual Behavior

A concurrent connection of the same account can fully access a session's temporary table once it knows the generated physical name:

  1. The physical name is enumerable through the catalog: select relname from mo_catalog.mo_tables where reldatabase='loomrepro' and relname like '\_\_mo\_tmp\_%' returns it for the sys-tenant dump user and for account admins (other live sessions' tables included). A peer user without catalog privileges can still use a name it obtained by other means.
  2. SELECT * FROM loomrepro.__mo_tmp_..._secret from session B returns the rows of session A's temporary table secret.
  3. INSERT/UPDATE on the physical name from session B succeed; session A then reads B's tampered rows through its alias.
  4. DROP TABLE loomrepro.__mo_tmp_..._secret from session B succeeds; session A then gets ERROR 1146: SQL parser error: table "secret" does not exist -- its own temp table was destroyed by another session.

Verified for: the sys-tenant dump user; two non-admin peer users of a regular account (only object privileges: create/drop table on the database, select/insert/update on db.*); and a create temporary table ... clone src destination (same results for the clone path).

Expected Behavior

MySQL 8.0 semantics (https://dev.mysql.com/doc/refman/8.0/en/create-temporary-table.html): a temporary table is visible only to the session that created it; no other session can select, insert, update or drop it, and no separately referenceable physical name exists. Verified on local MySQL 8.0.46 with the same two-session scenario:

  • session 2 select * from loomcmp.secret -> ERROR 1146 (42S02): Table 'loomcmp.secret' doesn't exist
  • session 2 information_schema.tables where table_schema='loomcmp': empty
  • session 2 show tables from loomcmp: empty

MatrixOne itself already enforces this at the alias layer (test/distributed/cases/table/temporary_table/temp_session_isolation.sql asserts session 2 cannot select session 1's alias) and hides temp physicals from information_schema (closed issue #25405, PR #26298). Expected: name resolution of any __mo_tmp_... relation must behave like a non-existent table for a session that is not the owner, so cross-session read, write, and drop all fail and the owner's table and data remain untouched.

Steps to Reproduce

Two concurrent sessions of the same account (shown with the sys-tenant dump user; identical with two non-admin users of one account):

-- Session A
CREATE DATABASE loomrepro; USE loomrepro;
CREATE TEMPORARY TABLE secret(id INT PRIMARY KEY, data VARCHAR(50));
INSERT INTO secret VALUES (1, 's3cret');
SELECT * FROM secret;           -- (1, 's3cret')

-- Session B (concurrent connection of the same account)
USE loomrepro;
SELECT relname FROM mo_catalog.mo_tables
 WHERE reldatabase='loomrepro' AND relname LIKE '\_\_mo\_tmp\_%';
-- e.g. __mo_tmp_01a14af09e077af09162a622c5bc0b1d_loomrepro_798f94e4-3576-4140-b683-d521e192f5a0_secret

SELECT * FROM `<physical>`;                          -- returns (1, 's3cret')          <-- cross-session read
INSERT INTO `<physical>` VALUES (2, 'peer-tamper');  -- succeeds                        <-- cross-session write
UPDATE `<physical>` SET data='hacked' WHERE id=1;     -- succeeds                        <-- cross-session write

-- Session A
SELECT * FROM secret;
-- (2, 'peer-tamper')
-- (1, 'hacked')                                       <-- owner observes attacker's writes

-- Session B
DROP TABLE `<physical>`;                              -- succeeds

-- Session A
SELECT * FROM secret;
-- ERROR 1146 (42S02): SQL parser error: table "secret" does not exist

DROP DATABASE loomrepro;

Additional information

  • pkg/defines/temp_table.go:32 mints the physical name; the session alias is a frontend-level map only (pkg/frontend/session.go GetTempTable / pkg/frontend/temporary_ddl.go:31 owns the alias-to-physical relation per session).
  • pkg/vm/engine/disttae/session_temp_table_catalog.go:30 (isSessionTemporaryCatalogItem) and pkg/vm/engine/disttae/txn_database.go:693-710 (getTableItem): on a name-cache miss the engine admits committed temporary schema for the same tenant (AccountId == accountID); neither compares the session UUID embedded in the name with the requesting session. No layer in pkg/sql/plan or pkg/frontend rejects a user statement that names a __mo_tmp_... relation either (defines.IsTempTableName is only used for renaming/typing, not for access control).
  • Because the physical name is intentionally listed in mo_catalog.mo_tables (only information_schema hides it, per [Bug]: information_schema.tables exposes internal temporary table objects #25405/fix(sysview): hide temporary tables from information schema #26298), account admins and sys-tenant users can enumerate every live session's temp table; ordinary peers that obtain a name get full DML/DROP access.
  • The DROP case is the most damaging: the owner's alias keeps pointing at the destroyed relation, so its next statement fails with 1146 mid-session.
  • Recommended fix direction: enforce session ownership at name resolution -- when a requested relation name has defines.IsTempTableName, admit it only if the session UUID component of the name equals the requesting session's UUID (internal executor paths for create/cleanup already carry ownership and can be exempted); also keep the physical names unlisted to non-owner sessions to match the spirit of the [Bug]: information_schema.tables exposes internal temporary table objects #25405 fix. This preserves the physical-table implementation and restores MySQL's session privacy.
Full reproduction, exactly as Loom ran it
-- Two concurrent sessions of the same account (e.g. two connections of user 'dump').
-- Session A:
CREATE DATABASE loomrepro; USE loomrepro;
CREATE TEMPORARY TABLE secret(id INT PRIMARY KEY, data VARCHAR(50));
INSERT INTO secret VALUES (1, 's3cret');
SELECT * FROM secret;                                   -- (1, 's3cret')
-- Session B (concurrent):
USE loomrepro;
SELECT relname FROM mo_catalog.mo_tables WHERE reldatabase='loomrepro' AND relname LIKE '\_\_mo\_tmp\_%';
--  -> __mo_tmp_01a14af09e077af09162a622c5bc0b1d_loomrepro_798f94e4-3576-4140-b683-d521e192f5a0_secret
SELECT * FROM `<that name>`;                            -- (1, 's3cret'): cross-session data leak
INSERT INTO `<that name>` VALUES (2, 'peer-tamper');      -- succeeds
UPDATE `<that name>` SET data='hacked' WHERE id=1;        -- succeeds
DROP TABLE `<that name>`;                               -- succeeds: destroys the owner's table
-- Session A again:
SELECT * FROM secret;
-- ERROR 1146 (42S02): SQL parser error: table "secret" does not exist
DROP DATABASE loomrepro;

Found by Loom bug hunt (module: custom-5ec72c0c38; tests: unit, white-box, end-to-end)

Activity

  1. added
    kind/bug
    on Oct 17, 2026
  2. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #30584. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions