Automated Threat Modeling

Overview of CVE-2026-133442: SQL Injection in Hibernate ORM JSON HQL Functions on MySQL and MariaDB

A summary of CVE-2026-133442, a high-severity SQL injection in Hibernate ORM's incubating json_value HQL rendering on MySQL and MariaDB, with patch details from PR #14019 and practical detection guidance based on the upstream regression tests.

CVE Analysis

10 min read

Gaurav Sarraf
Gaurav Sarraf

2026-12-02

Overview of CVE-2026-133442: SQL Injection in Hibernate ORM JSON HQL Functions on MySQL and MariaDB

Introduction

A single crafted string passed into a JSON path parameter is enough to break out of a SQL literal in Java applications that use Hibernate ORM's incubating JSON functions against MySQL or MariaDB. The Hibernate project lists authorization bypass and data exfiltration as consequences, and IBM's bulletin adds unauthorized viewing, adding, modifying or deleting of database data. The exposure is limited, though, to a specific combination of version, configuration, database and query shape.

Hibernate ORM is a Java object-relational mapping project. The Quarkus documentation describes it as the de facto standard implementation of Jakarta Persistence. Its main sponsors are IBM and Red Hat, which fund development and ship support for it through their Java runtimes, and IBM is also the CVE assigning organization for this record. Because so many Java persistence layers sit on top of Hibernate, a flaw in how it renders SQL is relevant well beyond any single application.

The CVE record scores the issue CVSS 3.1 8.8, while the Hibernate advisory scores it 8.6. Both rate it high. We cover the scoring discrepancy below, since it affects how you should reason about authentication requirements.

Technical information

Where the bug lives

The affected package is org.hibernate.orm:hibernate-core, and the weakness is CWE-89. The Hibernate advisory pins it to the MySQL and MariaDB renderer for HQL json_* functions.

Hibernate does not send JSON path arguments to MySQL as JDBC bind parameters. It writes them directly into the SQL string as a quoted literal. When a query used json_value(..., passing :pathParam as paramName), the value bound to :pathParam was spliced into the path through a private helper in JsonPathHelper that knew exactly one escaping rule. PR #14019 removed this helper:

private static void appendLiteral(SqlAppender sqlAppender, int startIndex, String part) { for ( int j = startIndex; j < part.length(); j++ ) { final char c = part.charAt( j ); if ( c == '\'') { sqlAppender.appendSql( '\'' ); } sqlAppender.appendSql( c ); }

Root cause

The helper doubles single quotes (' becomes ''), which is the ANSI SQL rule. MySQL and MariaDB additionally treat the backslash as an escape character inside string literals by default. Because the helper left backslashes untouched, an attacker-supplied backslash could cancel the quote doubling, close the literal early, and let the rest of the input execute as SQL.

The upstream test helper written for the fix spells this out. On databases with backslash escapes, a literal like '\''--' leaves -- outside the string. The backslash consumes the first of the doubled quotes as an escaped character, the second quote terminates the literal, and everything after it is parsed as SQL.

A second, related problem existed in inlinedJsonPathIncludingPassingClause(). It applied SQL escaping while building what is really a plain JSON path string, so values could be escaped wrongly or twice once the caller wrapped the result in quotes.

The fix makes clear that the root cause was broader than one bad function. Several code paths escaped strings by hand with ANSI rules, even on databases whose literal rules are different.

Conditions for exploitation

Per the project advisory, all of the following must hold:

  1. The application runs an affected 8.0 build (no special setting required), or an affected 7.x build with hibernate.query.hql.json_functions_enabled set to true.
  2. The application connects to MySQL or MariaDB.
  3. It executes an HQL json_value call whose JSON path expression references a parameter supplied through a passing clause, and that query parameter contains an untrusted string. The upstream regression tests also exercise a bound JSON path argument (json_value(e.json, :path)), so treat that form as suspect too.

The project classifies this as a first-order injection, meaning the malicious value is used in the same request that supplies it.

Attack flow

Based on the advisory and the fix, exploitation looks like this:

  1. The attacker finds an application entry point whose input flows into a json_value path or passing parameter on a vulnerable build backed by MySQL or MariaDB.
  2. The attacker supplies a value containing a backslash followed by a single quote, followed by SQL of their choosing.
  3. Hibernate inlines the value into the JSON path literal, doubling the quote but leaving the backslash in place.
  4. MySQL or MariaDB parses the backslash as escaping the first quote. The second quote closes the literal, and the trailing input is interpreted as SQL.
  5. Depending on the surrounding query and database privileges, the attacker can bypass authorization filters or exfiltrate data. IBM also describes modifying or deleting data.

The sources do not describe a specific endpoint, payload or exploit sequence that applies to every deployment, and no public exploit is tracked.

Severity and the authentication question

The published scoring is inconsistent:

  • The CVE record (as reproduced by OpenCVE): 8.8, CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H, which specifies low privileges.
  • The Hibernate advisory: 8.6, CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:L, which specifies no privileges and lower integrity and availability impact.
  • IBM's bulletin displays 8.6 next to the PR:L, high-impact vector that the CVE record scores 8.8, and its prose calls the attacker unauthenticated.

Our conclusion is that whether authentication is required depends entirely on which of your application's entry points feed the vulnerable parameter. Assess that per application rather than inferring it from any one score.

Patch information

Fixed versions

The maintainers fixed this in three org.hibernate.orm:hibernate-core release lines:

  • >=7.0.0.Beta2, <7.2.26.Final: upgrade to 7.2.26.Final
  • >=7.3.0.CR1, <7.4.17.Final: upgrade to 7.4.17.Final
  • >=8.0.0.Alpha1, <8.0.0.CR2: upgrade to 8.0.0.CR2

The GitHub advisory and IBM's bulletin list the same versions and both point to Jira ticket HHH-21164. IBM recommends moving to the latest version.

The fix: PR #14019

The change is PR #14019, "HHH-21164 Fix wrong rendering of arguments for json_value on some databases", by beikov, merged on November 18, 2026 and labelled 7.2. An upstream report also links commit ff26150 to HHH-21164, but its contents could not be reviewed, so this walkthrough is based on the merged PR diff.

Step 1: a new dialect hook. The PR adds appendLiteralContent() to Dialect, which writes the escaped body of a string literal without the enclosing quotes, using the same rules as appendLiteral():

/// Append the escaped content of a SQL string literal, without the enclosing quotes. /// /// The caller is responsible for rendering the enclosing quotes. /// Implementations must apply the same escaping rules as [#appendLiteral(SqlAppender, String)]. public void appendLiteralContent(SqlAppender appender, String literal) {

JSON path helpers need this hook because they assemble one literal from several pieces ('$, a path fragment, a passed value, more path, ') and must escape each piece correctly without adding their own quotes.

Step 2: MySQL dialects supply their own escaping. MySQLDialect.appendLiteral() is split. Its existing per-character loop, which already handled both ' and \, moves into an appendLiteralContent() override, and appendLiteral() simply wraps it in quotes:

public void appendLiteral(SqlAppender appender, String literal) { appender.appendSql( '\'' ); appendLiteralContent( appender, literal ); appender.appendSql( '\'' ); } @Override public void appendLiteralContent(SqlAppender appender, String literal) {

The community MySQLLegacyDialect gets the same treatment, and now stops doubling backslashes when the server runs in NO_BACKSLASH_ESCAPES mode, where a doubled backslash would corrupt the value:

case '\\': if ( !noBackslashEscapesEnabled ) { // See https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_backslash_escapes appender.appendSql( '\\' ); }

SingleStoreDialect is refactored the same way, and SpannerDialect, which also uses backslash escaping, gains new appendLiteral and appendLiteralContent overrides.

Step 3: the vulnerable path uses the dialect. In JsonPathHelper, the quote-only helper is gone. Every place that inlines a path fragment or a passing value goes through appendLiteralContent() on the SqlAppender:

public static void appendJsonPassingLiteralValue(SqlAppender sqlAppender, Object literalValue) { sqlAppender.appendLiteralContent( String.valueOf( literalValue ) );

inlinedJsonPathIncludingPassingClause() now substitutes raw values and leaves escaping to the caller:

// The result is a plain JSON path, not SQL, so no SQL escaping must happen here. // Callers are responsible for rendering the result as SQL string literal.

Step 4: the same fix everywhere else. Calls to the dialect-agnostic appendSingleQuoteEscapedString(...) are replaced with appendLiteral(...) across many JSON renderers: MySQLJsonTableFunction (nested and column paths), JsonTableFunction, DB2JsonTableFunction, HANAJsonTableFunction, the Oracle, PostgreSQL and CockroachDB array, remove and insert functions, and all SingleStoreJson*Function classes. Some helpers outside the JSON functions are covered too: OrdinalFunction, StringFunction, and the SQLServerAggregateSupport for xml path(...) rendering. JsonValueFunction, JsonQueryFunction and JsonExistsFunction now call sqlAppender.appendLiteral(...) directly, and FormatFunction uses a new StringBuilderDialectSqlAppender so buffered text also gets dialect escaping.

Why this works. After the patch, the only way to put a string literal into generated SQL is Dialect.appendLiteral() or appendLiteralContent(), so on MySQL and MariaDB backslashes are always escaped together with quotes. Hibernate ORM 6.x and earlier are unaffected, so there is nothing to backport there.

If you cannot upgrade immediately

The project lists two alternatives, neither of which replaces upgrading:

  1. Avoid passing untrusted values to HQL JSON function path parameters. Use hardcoded or sanitized values, applying SQL escaping as the project advises. The advisory warns that incorrect escaping can leave the application vulnerable.
  2. On Hibernate ORM 7.x only, set hibernate.query.hql.json_functions_enabled to false or leave it unset (the default is false). Queries using these functions will then error out. This workaround is specified for 7.x, not for 8.x.

Detection methods

No ready-made signatures exist. CVETodo found no published Sigma, Suricata, YARA or Nuclei rules as of December 2, 2026, no public exploit, and no CISA KEV listing. IBM's bulletin covers fixes and workarounds, not compromise indicators. At the time of review, the NVD page for this ID also returned "CVE ID Not Found". Detection therefore breaks into three parts.

1. Exposure triage

All four conditions must be true, so this works as a checklist:

  • Library version. org.hibernate.orm:hibernate-core within >=7.0.0.Beta2,<7.2.26.Final, >=7.3.0.CR1,<7.4.17.Final, or >=8.0.0.Alpha1,<8.0.0.CR2. Software composition analysis or a dependency tree inventory can flag these via the GHSA ID.
  • Feature flag. On 7.x, hibernate.query.hql.json_functions_enabled must be explicitly true. On 8.0.0.Alpha1 and later, no setting is needed. Search persistence.xml, Spring application.properties or .yml, and programmatic settings for this property.
  • Database. MySQL or MariaDB only.
  • Query shape. HQL calling json_value(...) with a bind parameter, especially the passing :param as name form, plus the bound path form json_value(e.json, :path) covered by upstream tests. Search source for json_value( near passing or a named parameter, then trace each hit back to see whether user input reaches it. Applications using only stable, nonincubating features are unaffected, which closes many findings quickly.

2. Behavioural testing with canary values

The strongest public method comes from the regression tests added with HHH-21164. JsonValueTest sends canary strings through the vulnerable parameters, and JsonTestHelper.assertNoInjection records every SQL statement Hibernate executes (using @SessionFactory(useCollectingStatementObserver = true)) and fails if the marker appears outside a quoted SQL token:

@Test public void testPathInjection(SessionFactoryScope scope) { assertNoInjection( scope, em -> { em.createQuery( "select json_value(e.json, :path) from EntityWithJson e", Tuple.class ) .setParameter( "path", "$'--" ) .getResultList(); } ); }

The marker is defined as:

private static final String INJECTION_MARKER = "--";

The test set covers:

  • a plain quote break out through the path: $'--
  • a plain quote break out through the passing value: '--
  • backslash variants of both: $\\'-- and \\'--
  • path and passing parameters set together, plus variants adding an error on empty clause

The helper's tokenizer asks the dialect whether backslash escapes apply, which also accounts for NO_BACKSLASH_ESCAPES. A naive scanner that only counts single quotes would miss the backslash cases. A statement is flagged only when the marker lands outside a single-quoted literal or a double-quoted token.

To apply this, replicate the approach in your integration tests or DAST harness:

  1. Target a test copy of each suspect endpoint on MySQL or MariaDB.
  2. Send the same canaries through any input that reaches json_value parameters.
  3. Capture the SQL, via a statement observer or the database statement log.
  4. Check whether the marker escapes quoting.

On 7.2.26.Final, 7.4.17.Final or 8.0.0.CR2, the same inputs should stay inside the literals.

3. Runtime monitoring

No vendor has published a log pattern for this CVE. CVETodo's guidance is general (enable database and application logging and watch for unusual query patterns). Based on how the bug works, watch the MySQL and MariaDB backends of exposed applications for:

  • JSON_VALUE or JSON path statements where a quote or a -- comment sequence appears in the path or passing argument
  • unexpected SQL grammar errors (JDBCException or SQLGrammarException) raised from JSON queries

Treat hits as leads, not confirmed indicators, and correlate them with unusually large result sets or unusual data access from the same client.

Affected systems and versions

Affected package: org.hibernate.orm:hibernate-core

  • 7.0.0.Beta2 through 7.2.25.Final (fixed in 7.2.26.Final), only when hibernate.query.hql.json_functions_enabled is set to true
  • 7.3.0.CR1 through 7.4.16.Final (fixed in 7.4.17.Final), only when hibernate.query.hql.json_functions_enabled is set to true
  • 8.0.0.Alpha1 through 8.0.0.CR1 (fixed in 8.0.0.CR2), with no special configuration required

Additional required conditions: a MySQL or MariaDB backend, and an HQL json_value call whose JSON path references a passing clause parameter containing untrusted input.

Not affected by this CVE: Hibernate ORM 6.x and earlier, applications using other database and HQL call combinations, and applications relying exclusively on stable, nonincubating features. This is a statement about this CVE only, not a guarantee that those applications are free of other issues.

Vendor security history

In September 2026, Hibernate published an earlier, related advisory for SQL injection in the json_* HQL methods via unsanitized bind parameters (GHSA-834x-qc2r-wc59). The current advisory distinguishes CVE-2026-133442 as specific to the MySQL and MariaDB renderer. A second JSON function escaping issue within a few months is consistent with the fix's own conclusion that several code paths escaped literals by hand with ANSI rules. PR #14019 centralizes that logic in the dialect.

The project's published security policy requests private vulnerability reports, describes coordinated disclosure, and states that security fixes are supported for the latest stable release and selected older releases. IBM, a main sponsor, also provides standalone support for Hibernate releases at end of life. These facts show a documented disclosure and remediation process, though they do not by themselves establish an overall security rating.

References

Detect & fix
what others miss

Works with
  • GitHub
  • GitLab
  • Bitbucket
  • Azure DevOps Services
  • Gerrit
  • CVS
  • Jira
  • Linear
  • Slack
  • Security Compass
Explore integrations
Security magnifying glass visualization