Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
SQL injection in new JDBC 4.3 enquoteLiteral() and enquoteNCharLiteral()
Both methods fail to safely quote values, allowing input to break out of the literal:
enquoteLiteral emits ' as \' (via Matcher.appendReplacement, which collapses the doubled backslash). Under NO_BACKSLASH_ESCAPES the backslash isn't an escape, so the quote closes the string early.
Backslashes are left undoubled, so a trailing \ escapes the closing quote under the default sql_mode. enquoteNCharLiteral never escapes backslashes at all.
Repro:
Driver.enquoteLiteral("x' OR '1'='1"); // → 'x\' OR \'1\'=\'1' (injection under NO_BACKSLASH_ESCAPES) |
Driver.enquoteLiteral("a\\"); // → 'a\' (literal stays open under default mode) |
thanks jmestwa-coder for PR https://github.com/mariadb-corporation/mariadb-connector-j/pull/228/changes