Alternative link
HSQLDB allowed SQL statements to call any static Java method from the classpath, enabling remote code execution when untrusted input is processed. An attacker could execute arbitrary code on the server.
medium.com
Published on medium.com
Software Development
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
HSQLDB (HyperSQL DataBase) is a SQL relational database system written in Java, used for development, testing and deployment of database applications. It is maintained by the HSQL Development Group and, according to the write-up, ranks 139th in the Maven repository and 2nd among embedded SQL databases, with over 100 million downloads.
The finding concerns the parsing procedure for binary and text format data in java.sql.Statement and java.sql.PreparedStatement. By default, HSQLDB lets SQL statements call any static method from any Java class on the class path, for example call org.hsqldb.clazz.meth(). That capability is what the researchers found could be abused.
The issue was tracked as CVE-2022-41853 and affects all versions up to and including 2.7.0.
Setup
To improve its vulnerability detectors, the team continuously tests open-source projects with Jazzer, a fuzzer running inside OSS-Fuzz. HSQLDB was one of the projects under test. No accounts, roles or special configuration are described: the finding came out of a fuzzing run against the project, and the precondition for the vulnerability in a real application is that it uses java.sql.Statement or java.sql.PreparedStatement in HSQLDB with untrusted input.
Finding it
A test run produced a severe finding: a potential remote code execution in HSQLDB. Because SQL statements can, by default, call any static method from any Java class in the class path, a statement such as call org.hsqldb.clazz.meth() is accepted directly. If an application passes untrusted input into a statement, that input can reach this method-calling path.

The image is captioned "RCE in HyperSQL database" and sits with the announcement of the finding.
Exploitation
The write-up describes the mechanism rather than a full end-to-end attack chain. The essential step is the SQL-level call into a static Java method:
call org.hsqldb.clazz.meth()
This is the form HSQLDB accepts for invoking a static method of a class on the class path: call followed by the fully qualified class and method name. The condition for abuse is that the application feeds untrusted input into a java.sql.Statement or java.sql.PreparedStatement executed against HSQLDB, so that an attacker can shape the statement that reaches the parser.
Root cause
HSQLDB's default behaviour permits SQL statements to call any static method from any Java class in the class path. The parsing procedure for binary and text format data in java.sql.Statement and java.sql.PreparedStatement is where this is handled. Because the default allows the full class path, an attacker who controls part of a statement can reach methods that were never intended to be callable from SQL. The only class the report says should remain usable without configuration is java.lang.Math.
Impact
The vulnerability is rated Critical with a CVSS base score of 9.8. Applications using java.sql.Statement or java.sql.PreparedStatement in HSQLDB with untrusted input may be vulnerable to a remote code execution attack.
The reach of the library makes the risk broad. It is used by more than 3,113 Maven packages, including LibreOffice, JBoss, Log4j, Hibernate and Spring-Boot, the last of which the report notes has thousands of usages carrying the potential of transitive risk, as well as various enterprise software solutions.
Fix
The issue is fixed upstream and will be available in the next release. From version 2.7.1, the property hsqldb.method_class_names must be defined with a list of class names or wildcards if any Java static method is used as an HSQLDB routine target.
For current versions, the mitigation is to define the same property whenever HSQLDB processes queries containing user input and a static Java method is used as the target of an HSQLDB routine. Without a property definition, the use of Java static methods, except those in java.lang.Math, should not be allowed. Developers can set the system property in code:
System.setProperty("hsqldb.method_class_names", "abc");
or on the command line:
java -Dhsqldb.method_class_names="abc"
In both examples the value abc stands for the list of permitted class names. The maintainers are credited for responding to the issue and providing a fix and a workaround for current versions.
Variants to test
- Other embedded Java SQL engines with routine support. Look for documentation describing how SQL routines map to Java static methods, then try a
callstatement naming a class on the class path. A positive result is the engine executing the method rather than rejecting the statement. - Applications that build statements from user input. Where an application concatenates input into a
StatementorPreparedStatementagainst HSQLDB, supply acallexpression and observe whether it is parsed as a method invocation. A positive result is execution of the named static method. - Default configurations after upgrading. Check whether
hsqldb.method_class_namesis set at all. A positive result is an installation on 2.7.1 or later where the property is absent and a static method call outsidejava.lang.Mathis still accepted. - Transitive dependencies. For frameworks such as Spring-Boot, Hibernate or Log4j that pull HSQLDB in, test whether any code path passes untrusted input to HSQLDB statements. A positive result is a reachable statement path where attacker-controlled text reaches the parser.
What happened, in plain words
A team of security researchers spends its time looking for bugs in free, open-source software. To do this at scale, they use a tool that throws huge amounts of random and semi-random data at a program, hoping to make it crash or behave strangely. One of the programs they pointed this tool at was HSQLDB, a small database engine written in Java. The tool produced a serious result: a way that an attacker might be able to run their own code on a machine running HSQLDB. The problem was given the identifier CVE-2022-41853, and it affects every version of HSQLDB up to and including 2.7.0.
To follow the rest of this article you only need to know a few ideas, and each one is explained where it first appears. The important thing to take away is that a database is a program that stores and looks up data, and that HSQLDB has a feature which lets a database query call a piece of Java code. That feature is useful, but if a query can be influenced by someone outside the application, it becomes dangerous.
What HSQLDB is
HSQLDB stands for HyperSQL DataBase. It is a relational database system written in Java. A relational database stores information in tables, much like a spreadsheet with rows and columns, and answers questions written in a language called SQL (Structured Query Language). A typical SQL question looks like SELECT name FROM users WHERE id = 5, and the database replies with the matching rows.
HSQLDB is maintained by the HSQL Development Group. According to the write-up, it ranks 139th in the Maven repository and 2nd among embedded SQL databases, and it has been downloaded over 100 million times. Two of those terms need unpacking:
- Maven repository is a large public library of ready-made Java building blocks that programmers download and reuse instead of writing everything themselves. A high rank there means the component is very widely used.
- Embedded means the database is not a separate server you connect to over the network. Instead it is a library that is built into another program, so the program and the database run inside the same process. Think of it as the difference between a restaurant you visit and a kitchen built into your own house.
Because HSQLDB is embedded and small, it is popular for development, testing and deployment of database applications. That popularity is why a bug in it matters to a lot of people at once.
The feature that caused the problem
Java is a programming language, and a Java program is made of classes. A class is a named bundle of code, and inside it are methods, which are named actions the class can perform. A static method is a method that belongs to the class itself rather than to a particular object created from it, so you can call it by naming the class and the method together.
HSQLDB has a feature that lets an SQL statement call a Java static method. The write-up describes the general form as:
call org.hsqldb.clazz.meth()
Line by line, in plain words:
callis the SQL keyword that tells HSQLDB you want to invoke a routine, that is, run a piece of code that is registered with the database.org.hsqldb.clazzis the fully qualified name of a Java class. In Java, classes are grouped into packages, and the dots separate the package path from the class name, much like a postal address narrows down from country to street to house. Hereorg.hsqldbis the package andclazzis the class inside it.meth()is the name of the method being called, with empty brackets because this example takes no arguments.
The point is that HSQLDB, by default, accepts a call naming any static method from any Java class that is on the class path. The class path is the list of places the Java runtime looks for classes when the program runs, so in practice it means every piece of Java code the application has loaded or can load. Allowing SQL to reach all of that is a very wide door.
The finding concerns the parsing procedure for binary and text format data in java.sql.Statement and java.sql.PreparedStatement. Those two names are Java interfaces, that is, standard ways for a Java program to send an SQL statement to a database. Statement is used for a statement built as a string, and PreparedStatement is used for a statement that is prepared in advance with placeholders for values. The parsing procedure is the part of the code that reads the incoming statement and works out what it means before running it. That is where the method-calling behaviour is handled.
How the researchers found it
To improve its vulnerability detectors, the team continuously tests open-source projects with Jazzer, a fuzzer running inside OSS-Fuzz. Two more terms to explain:
- A fuzzer is an automated tester that feeds a program enormous numbers of inputs, many of them malformed or random, and watches for crashes or odd behaviour. The everyday comparison is shaking a machine in every direction to see which screw falls out.
- OSS-Fuzz is a service that runs fuzzers continuously against open-source projects and records the results.
HSQLDB was one of the projects under test. No accounts, roles or special configuration are described in the write-up: the finding came out of a fuzzing run against the project itself. The precondition for the vulnerability in a real application is that the application uses java.sql.Statement or java.sql.PreparedStatement in HSQLDB with untrusted input. Untrusted input means any data that comes from outside the application and could be shaped by an attacker, such as text typed into a web form, a value from a URL, or a field in a request.
A test run produced a severe finding: a potential remote code execution in HSQLDB. Remote code execution, usually shortened to RCE, means an attacker can make the target machine run code of the attacker's choosing. It is generally considered the most serious class of software bug, because once an attacker runs their own code, they can usually do anything the application itself could do.

The image is captioned "RCE in HyperSQL database" and sits with the announcement of the finding.
Because SQL statements can, by default, call any static method from any Java class in the class path, a statement such as call org.hsqldb.clazz.meth() is accepted directly. If an application passes untrusted input into a statement, that input can reach this method-calling path.
How it could be abused
The write-up describes the mechanism rather than a full end-to-end attack chain. The essential step is the SQL-level call into a static Java method, shown again here exactly as in the report:
call org.hsqldb.clazz.meth()
Line by line:
callasks HSQLDB to run a routine.org.hsqldb.clazznames the Java class that contains the routine.meth()names the method to run.
This is the form HSQLDB accepts for invoking a static method of a class on the class path: call followed by the fully qualified class and method name. The report gives this as the generic pattern, not as a working payload against a specific class. The condition for abuse is that the application feeds untrusted input into a java.sql.Statement or java.sql.PreparedStatement executed against HSQLDB, so that an attacker can shape the statement that reaches the parser.
An everyday comparison: imagine a form at a reception desk that says "write the name of the person you want to speak to". If the receptionist simply reads out whatever is written and fetches that person, then anyone who can write on the form can summon anyone in the building. The call feature is the receptionist, and the class path is the building.
Why it works: the root cause
HSQLDB's default behaviour permits SQL statements to call any static method from any Java class in the class path. The parsing procedure for binary and text format data in java.sql.Statement and java.sql.PreparedStatement is where this is handled. Because the default allows the full class path, an attacker who controls part of a statement can reach methods that were never intended to be callable from SQL.
The only class the report says should remain usable without configuration is java.lang.Math. java.lang.Math is Java's built-in collection of mathematical helpers, such as rounding and trigonometry. It is harmless to expose because it only does arithmetic, so the fix leaves it available while closing the door on everything else.
How serious it is
The vulnerability is rated Critical with a CVSS base score of 9.8. CVSS stands for Common Vulnerability Scoring System, a standard way of expressing how severe a security flaw is on a scale from 0 to 10, where higher is worse. A score of 9.8 sits near the top of that scale.
Applications using java.sql.Statement or java.sql.PreparedStatement in HSQLDB with untrusted input may be vulnerable to a remote code execution attack. In other words, the bug is in the database library, but whether it can actually be exploited depends on how the surrounding application is written.
The reach of the library makes the risk broad. It is used by more than 3,113 Maven packages, including LibreOffice, JBoss, Log4j, Hibernate and Spring-Boot, the last of which the report notes has thousands of usages carrying the potential of transitive risk, as well as various enterprise software solutions. Transitive risk means the danger arrives indirectly: an application may never mention HSQLDB in its own code, but a framework it depends on depends on HSQLDB, so the vulnerable library ends up inside the application anyway. It is like finding out that the flour in your bread came from a mill with a problem you had never heard of.
The fix and how to protect yourself
The issue is fixed upstream and will be available in the next release. "Upstream" means the original project that publishes the library, as opposed to the many applications that use it. From version 2.7.1, the property hsqldb.method_class_names must be defined with a list of class names or wildcards if any Java static method is used as an HSQLDB routine target. A property here is a named setting that the Java runtime or the library reads at startup to change its behaviour. A wildcard is a pattern that matches several names at once, such as a prefix followed by an asterisk.
For current versions, the mitigation is to define the same property whenever HSQLDB processes queries containing user input and a static Java method is used as the target of an HSQLDB routine. Without a property definition, the use of Java static methods, except those in java.lang.Math, should not be allowed. Developers can set the system property in code:
System.setProperty("hsqldb.method_class_names", "abc");
Line by line:
System.setPropertyis a standard Java call that sets a named setting for the running program."hsqldb.method_class_names"is the name of the setting HSQLDB reads. The name is a string, which is why it sits in double quotes."abc"is the value. In this example it stands for the list of permitted class names, so only classes named there may be called from SQL.
The same setting can be given on the command line when the program starts:
java -Dhsqldb.method_class_names="abc"
Line by line:
javastarts the Java runtime.-Dis the flag that tells Java to define a system property, and the name and value follow it joined by an equals sign.hsqldb.method_class_names="abc"is the property name and its value, withabcagain standing for the list of permitted class names.
In both examples the value abc stands for the list of permitted class names. The maintainers are credited for responding to the issue and providing a fix and a workaround for current versions.
Things worth testing in your own setup
Each one is a way of asking "does this particular setup still allow the dangerous behaviour?"
- Other embedded Java SQL engines with routine support. Look for documentation describing how SQL routines map to Java static methods, then try a
callstatement naming a class on the class path. A positive result is the engine executing the method rather than rejecting the statement. The reasoning is that the same design choice may have been made by other projects, so the same test is worth repeating elsewhere. - Applications that build statements from user input. Where an application concatenates input into a
StatementorPreparedStatementagainst HSQLDB, supply acallexpression and observe whether it is parsed as a method invocation. A positive result is execution of the named static method. Concatenation means gluing text together, so if user text is glued into a statement, the user can add SQL keywords of their own. - Default configurations after upgrading. Check whether
hsqldb.method_class_namesis set at all. A positive result is an installation on 2.7.1 or later where the property is absent and a static method call outsidejava.lang.Mathis still accepted. This checks that the upgrade actually changed the behaviour you rely on. - Transitive dependencies. For frameworks such as Spring-Boot, Hibernate or Log4j that pull HSQLDB in, test whether any code path passes untrusted input to HSQLDB statements. A positive result is a reachable statement path where attacker-controlled text reaches the parser. This is the indirect case: the application author may not even know HSQLDB is present.
Glossary
- Class: a named bundle of Java code containing methods; a building block of a Java program.
- Class path: the list of places the Java runtime looks for classes when a program runs.
- CVSS: Common Vulnerability Scoring System, a standard 0 to 10 severity score for security flaws.
- Embedded database: a database that runs inside the application process rather than as a separate server.
- Fuzzer: an automated tester that feeds a program large numbers of random or malformed inputs to find crashes and odd behaviour.
- HSQLDB: HyperSQL DataBase, a relational database system written in Java.
- Java: a widely used programming language and runtime.
- Jazzer: the fuzzer the researchers used, running inside OSS-Fuzz.
- Maven repository: a large public library of reusable Java components.
- Method: a named action inside a class.
- OSS-Fuzz: a service that runs fuzzers continuously against open-source projects.
- Parsing: reading incoming text and working out its structure and meaning before acting on it.
- PreparedStatement: a Java interface for sending an SQL statement that is prepared in advance with placeholders for values.
- Property: a named setting read at startup that changes a program's behaviour.
- Remote code execution (RCE): a flaw that lets an attacker make a machine run code of their choosing.
- Routine: a piece of code registered with a database that SQL can invoke.
- SQL: Structured Query Language, the language used to ask questions of a relational database.
- Statement: a Java interface for sending an SQL statement built as a string.
- Static method: a method that belongs to a class itself rather than to an object created from it.
- Transitive risk: danger that arrives indirectly through a dependency of a dependency.
- Untrusted input: data from outside the application that an attacker could shape.
- Upstream: the original project that publishes a library, as opposed to the applications using it.
- Wildcard: a pattern that matches several names at once.