Repository navigation
Description
DRAFT 1 (SDK, 2026-10-27) — candidate issue, not yet filed
Title: [Bug]: Client._escape_string/_escape_identifier do not escape anything — they only wrap quotes
Relation to #31186
#31186 (consolidated tracker) covers builders that interpolate values without calling any escape helper. This report is the complementary root-cause find: the escape helpers that the "fixed" call sites do call (account.py, pubsub.py, snapshot.py, pitr.py, restore.py, async_client.py all invoke _escape_string/_escape_identifier after that fix wave) are themselves no-ops — so the defected-escape surface is larger than unescaped interpolation, and fixing builders alone leaves every "escaped" call site still broken.
Description
The Python SDK's central escaping helpers — used by every manager built after the #31186 SQL-injection report (account.py, pubsub.py, snapshot.py, pitr.py, restore.py...) — are no-ops that only wrap the value in quotes without doubling embedded quote characters:
# matrixone/client.py
def _escape_identifier(self, identifier: str) -> str:
return f"`{identifier}`"
def _escape_string(self, value: str) -> str:
return f"'{value}'"Verified behavior:
c._escape_identifier("a`b") # → `a`b` (backtick not doubled → breaks out of the identifier)
c._escape_string("o'rien") # → 'o'rien' (single quote not doubled → textbook injection)Any caller passing a value containing a quote character produces syntactically broken or attacker-controllable SQL. E.g. building an account-manager statement:
client.account.create_account("x", admin_name="a', 'pw' -- ", password="whatever")
# → CREATE ACCOUNT `x` ADMIN_NAME 'a', 'pw' -- ' IDENTIFIED BY 'whatever'The admin_name payload closes its string early and injects a second string literal — precisely what an escape function exists to prevent. Passwords are the classic vector (users paste arbitrary passwords with ' from password managers; usernames like "O'Brien" likewise).
Reproduction
from matrixone import Client
c = Client()
c.connect(host=..., port=..., user=..., password=..., database=...)
c.account.create_user("weird", password="p' OR '1'='1") # SQL runs with attacker-controlled fragmentsAlso reproducible purely at the SQL-builder level with Client.__new__(Client) + the two functions (no server needed).
Impact
- All "fixed" call sites inherit a fake guarantee: callers were switched to
_escape_string(e.g. account.py lines buildingIDENTIFIED BY {escape(password)}) and now look safe, but a single'in the password/admin_name/comment breaks out. This is worse than no escaping because reviewers see the escape call and stop looking. - The security-oriented docstrings ("Escapes a string value for SQL queries") are misleading.
- All account/user creation paths (3262-line cli_tools too — it likely shares these helpers) accept user-controlled passwords; account provisioning planes taking API-supplied names/passwords are exposed.
Expected behavior
_escape_stringmust double single quotes:value.replace("'", "''")(and ideally also backslashes semantics depending on sql_mode)._escape_identifiermust double backticks:identifier.replace("`", "") ``.- Add unit tests with
',`,\\, unicode, and the classicx', 'y' --payload asserting the rendered SQL is a single literal. - Consider using SQLAlchemy's
text().bindparams()once statement construction migrates there, which removes the need for manual escaping entirely.
Activity
Ariznawlll commentedon Oct 27, 2026
Verified against current main (sparse checkout of clients/python, 2026-10-27): this is already fixed by the new
_sql_literals.pymodule —sql_literal("o'rien")→'o''rien',sql_identifier("ab")→`a``b`, the no-op_escape_string/\_escape_identifier` helpers are gone, and callers (base_client insert paths, metadata, scoped_query) now route through it. Closing as fixed on main; the report remains valid for the 2026-10-16 snapshot it was filed against.