The OracleCodec encodes one character. The rest pass through.
org.owasp.esapi.codecs.OracleCodec is fifty lines of Java in the codebase that shipped through 2.6.x. Its encodeCharacter method, the function the encoder loops over every character of the input through, reads in full:
public String encodeCharacter( char[] immune, Character c ) {
if ( c.charValue() == '\'' )
return "\'\'";
return ""+c;
}
One character is transformed: ' becomes ''. Every other character, including \, is returned verbatim. The class Javadoc names the destination: "Implementation of the Codec interface for Oracle DB strings." Oracle's string literal grammar uses '' to express a literal single quote inside a string; the codec encodes for that grammar. For any input that does not contain a backslash, the codec produces an output that Oracle's parser reads as the intended string literal, with ' characters that originated in the input represented as the two-character sequence Oracle treats as a literal '.
That contract holds when the destination is the Oracle string-literal parser the codec was written for. It is OracleCodec. The codec's documentation, since the class's inception in 2007, said so.
The destination is whatever the application's JDBC URL points at.
ESAPI.encoder().encodeForSQL(Codec codec, String input) is a method on the Encoder interface. The codec argument is supplied by the caller. The interface signature accepts any Codec implementation. The caller's selection of new OracleCodec() is the caller's typed assertion that the destination interpreter is Oracle's SQL string-literal parser. The runtime has no way to verify that assertion. Nothing in encodeForSQL connects the codec choice to the DataSource the assembled query is going to be sent to.
The public PoC for CVE-2025-5878 (dickfu/ESAPI-SQLinjection-CVE-2025-5878-Exploit) demonstrates the disconnect with a target whose URL path is literally /vulnapi/sqli/jdbc/safe3. The "safe" suffix is the lab's claim that the endpoint is the protected branch. The protection is ESAPI.encoder().encodeForSQL(new OracleCodec(), userInput). The backend is MySQL.
The injection is the backslash the codec leaves alone.
The PoC's payload is a single time-based blind probe, with the SQL injection adapted to MySQL syntax (information_schema, SLEEP(), IF()). The first probe:
1\' AND IF(length(database())>5,0,SLEEP(5))-- -
That is one literal backslash, one literal single quote, then the rest of the SQL.
The Java application reads the id request parameter, hands it to encodeForSQL(new OracleCodec(), id), and concatenates the result into a SQL string. The codec walks the input character by character:
1 passes through
\ passes through (the OracleCodec branch for backslash does not exist)
' is transformed to ''
- everything else passes through
The output is:
1\'' AND IF(length(database())>5,0,SLEEP(5))-- -
The application's query builder wraps that in literal single quotes:
SELECT * FROM users WHERE id='1\'' AND IF(length(database())>5,0,SLEEP(5))-- -'
The MySQL parser reads '1\'' as: open string with ', literal 1, backslash-quote escape sequence yielding a literal ' inside the string, terminating '. The string the parser binds is 1'. What follows the closing quote is interpreted as SQL: AND IF(length(database())>5,0,SLEEP(5)), then the MySQL -- comment that runs to end of line, consuming the trailing stray ' the application appended. The IF(...) triggers SLEEP(5) when the boolean is true. The PoC measures the response delay and recovers the database name one character at a time.
The codec did exactly what it advertised. It encoded a single quote the way Oracle's string-literal parser would consume the encoded form. The application's parser is MySQL, where the codec's pass-through of \ is the boundary the encoded '' provides the second quote of.
The codec's documentation, post-disclosure, admits the destination question is unanswerable.
The 2.7.0.0 release ships a substantially expanded class-level Javadoc on OracleCodec. The new prose, attached to a class whose code is unchanged:
CAUTION: This class has some known issues. During the investigation of CVE-2025-5878, it was discovered that since this class' inception in 2007, that Oracle databases also use \ (backslash) as a default escape char. That was fundamental in the vulnerability, since the escape character itself was not being escaped. We had originally planned to address this, but while researching the issue, we discovered that not only was there a new default escape character for Oracle SQL*Plus, but that developers could actually override the default to a character of their choosing.
The maintainer's first observation in the post-investigation Javadoc is that the codec was never adequate even for Oracle. Oracle's SQL*Plus client treats \ as an escape character by default. The codec, named for Oracle, did not escape its own database's escape character for eighteen years.
The maintainer's second observation is the one that makes the codec architecturally unfixable: Oracle's SET ESCAPE command lets a session override the escape character at runtime, to any character the developer chooses. A SQL injection that succeeds in setting ESCAPE to a character the codec does not transform reopens whatever the codec just closed. The Javadoc's conclusion:
We realized that there is no way we can defend against this, so it seemed pointless to even bother to try to quote default escape character passed in as input when OracleCodec is used with the Encoder.encodeForSQL interface. Therefore, you really should not use this, but if dead set in still using this leg canon, it;s on you. You have been warned.
The patch does not add backslash escaping. The patch adds a paragraph in the Javadoc explaining why backslash escaping would not have been sufficient even for the database the codec is named after.
The 2.7.0.0 "fix" is to deprecate the method and gate it behind an opt-in property.
The diff to DefaultEncoder.java adds a private helper, ensureDangerousMethodExplicitlyEnabled, and inserts a call to it at the top of encodeForSQL:
public String encodeForSQL(Codec codec, String input) {
// This will throw if this method is not explicitly enabled in ESAPI.properties.
ensureDangerousMethodExplicitlyEnabled(
DefaultEncoder.class.getName() + ".encodeForSQL",
"[default]",
"see CVE-2025-5878 and ESAPI Security Bulletin #13 for details" );
if( input == null ) {
return null;
}
...
}
The helper's body checks ESAPI.isMethodExplicityEnabled against the property ESAPI.dangerouslyAllowUnsafeMethods.methodNames, throws NotConfiguredByDefaultException when the method's fully qualified name is not in the list, and when it is, logs a SECURITY_FAILURE event with the contents of a second property, ESAPI.dangerouslyAllowUnsafeMethods.justification. The audit log line the maintainer wrote:
SIEM ALERT: Method 'org.owasp.esapi.reference.DefaultEncoder.encodeForSQL'
has been invoked despite having credible security concerns; for additional
details, see see CVE-2025-5878 and ESAPI Security Bulletin #13 for details.
Provided justification: [whatever the operator typed]
The merge commit that ships this (PR #888) records the working name the maintainer settled on for the property. Quoting the commit message: "Changed to use a more politically correct property name. But I still like ESAPI.enableLegCannonModeAndGetMyAssFired.justification better." The published property is the politically corrected version. The internal name is the operative description.
OracleCodec, MySQLCodec, and DB2Codec receive @Deprecated annotations with a removal target of one year after 2.7.0.0. The encodeForSQL method on the Encoder interface receives the same annotation. Existing applications upgrading to 2.7.0.0 do not get a safer codec. They get a NotConfiguredByDefaultException at runtime from every call site, until the deployer either rewrites the call site or sets the property whose name reads, when you remove the politeness, as a confession.
The pattern: the shell was not the sink.
The codec parameter on encodeForSQL is the developer's typed assertion of which interpreter the output will be parsed by. The assertion is local to the call site. The actual destination is the JDBC URL, the active SQL mode, and, on Oracle, whatever the session's current SET ESCAPE value is. None of those facts are visible at the call site. None of them are accessible to the codec. The codec name encodes the threat model the developer was thinking about; the destination encodes the one they were not.
The catalog has named this shape across runtimes. Cacti's cacti_escapeshellarg wraps for the POSIX shell in front of rrdtool's batch parser reached over proc_open with no shell ever running. exiftool-vendored applies htmlEncode to the value half of a stdin loop and not to the key half, where ExifTool reads bare newlines as argument boundaries. Next.js reuses a JSON-string escape regex against a CSP-nonce HTML-attribute gate. Open WebUI reuses an HTML scrubber against the browser's URI-scheme parser. Everest Forms Pro runs sanitize_text_field, written for HTML, on values about to be eval'd as PHP arithmetic.
ESAPI's contribution to the catalog is the only one in the set where the destination dialect is selected by an argument that the caller is structurally required to fill in. encodeForSQL cannot be called without naming a codec. The Encoder interface's documentation describes the codecs as "appropriate codecs include the MySQLCodec and OracleCodec," leaving the choice between them, and the consequence of choosing wrong, to the caller. The other CVEs in the pattern silently mismatch one function to one sink. CVE-2025-5878 explicitly mismatches a named codec to an unnamed JDBC URL.
encodeForSQL is an unpatchable primitive.
encodeForSQL is the API surface that lets a developer outsource SQL injection prevention to a function whose name promises to handle it. The codec parameter is the affordance that makes the API surface look more discriminating than it is, because picking the codec feels like specifying the destination. The destination is the database the application is connected to. The codec is not.
The bug class is the design. There is no patch that preserves the API and closes the gap. The OracleCodec.encodeCharacter method has fifteen meaningful tokens. Adding \ to the transformation set closes the demonstrated PoC and does not close the SET ESCAPE extension the Javadoc cites. Closing SET ESCAPE would require the codec to inspect every prior statement issued on the same session, which a stateless codec method cannot do. The OWASP cheat sheet that the Encoder Javadoc itself links to has been classifying this approach as "Defense Option 4: STRONGLY DISCOURAGED" for years. An unpatchable primitive does not get a code fix; it gets removed, or it gets gated behind a property whose name confesses what it is.
The 2.7.0.0 response is the maintainer reading their own documentation. They deprecate the method and add an opt-in gate whose internal name is the warning. A year from 2.7.0.0, the method goes away. The codec stays in the source tree, encoding ' to '', applied by whoever sets the opt-in property to whatever database they were already pointed at.
PoC: dickfu/ESAPI-SQLinjection-CVE-2025-5878-Exploit
The maintainer wrote down the answer to the question every consumer asked when they reached for encodeForSQL. The function does not know which database you are talking to, and you do not get to outsource that question to a method signature.