-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The OracleCodec encodes one character. The rest pass through.\n\n`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:\n\n```java\npublic String encodeCharacter( char[] immune, Character c ) {\n if ( c.charValue() == '\\'' )\n return \"\\'\\'\";\n return \"\"+c;\n}\n```\n\nOne 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 `'`.\n\nThat 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.\n\n## The destination is whatever the application's JDBC URL points at.\n\n`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.\n\nThe 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.\n\n## The injection is the backslash the codec leaves alone.\n\nThe 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:\n\n```\n1\\' AND IF(length(database())>5,0,SLEEP(5))-- -\n```\n\nThat is one literal backslash, one literal single quote, then the rest of the SQL.\n\nThe 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:\n\n- `1` passes through\n- `\\` passes through (the OracleCodec branch for backslash does not exist)\n- `'` is transformed to `''`\n- everything else passes through\n\nThe output is:\n\n```\n1\\'' AND IF(length(database())>5,0,SLEEP(5))-- -\n```\n\nThe application's query builder wraps that in literal single quotes:\n\n```sql\nSELECT * FROM users WHERE id='1\\'' AND IF(length(database())>5,0,SLEEP(5))-- -'\n```\n\nThe 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.\n\nThe 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.\n\n## The codec's documentation, post-disclosure, admits the destination question is unanswerable.\n\nThe 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:\n\n> **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.\n\nThe 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.\n\nThe 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:\n\n> 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.\n\nThe 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.\n\n## The 2.7.0.0 \"fix\" is to deprecate the method and gate it behind an opt-in property.\n\nThe diff to `DefaultEncoder.java` adds a private helper, `ensureDangerousMethodExplicitlyEnabled`, and inserts a call to it at the top of `encodeForSQL`:\n\n```java\npublic String encodeForSQL(Codec codec, String input) {\n // This will throw if this method is not explicitly enabled in ESAPI.properties.\n ensureDangerousMethodExplicitlyEnabled(\n DefaultEncoder.class.getName() + \".encodeForSQL\",\n \"[default]\",\n \"see CVE-2025-5878 and ESAPI Security Bulletin #13 for details\" );\n\n if( input == null ) {\n return null;\n }\n ...\n}\n```\n\nThe 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:\n\n```\nSIEM ALERT: Method 'org.owasp.esapi.reference.DefaultEncoder.encodeForSQL'\nhas been invoked despite having credible security concerns; for additional\ndetails, see see CVE-2025-5878 and ESAPI Security Bulletin #13 for details.\nProvided justification: [whatever the operator typed]\n```\n\nThe 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.\n\n`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.\n\n## The pattern: the shell was not the sink.\n\nThe 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.\n\nThe catalog has named this shape across runtimes. [Cacti's `cacti_escapeshellarg`](/posts/cacti-escapeshellarg-no-shell) wraps for the POSIX shell in front of rrdtool's batch parser reached over `proc_open` with no shell ever running. [`exiftool-vendored`](/posts/exiftool-vendored-cve-2026-43893-keys-were-raw) 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](/posts/nextjs-cve-2026-44581-escape-regex-was-for-json) reuses a JSON-string escape regex against a CSP-nonce HTML-attribute gate. [Open WebUI](/posts/open-webui-cve-2026-44721-input-had-no-angle-brackets) reuses an HTML scrubber against the browser's URI-scheme parser. [Everest Forms Pro](/posts/everest-forms-cve-2026-3300-sanitized-for-html-fed-to-eval) runs `sanitize_text_field`, written for HTML, on values about to be `eval`'d as PHP arithmetic.\n\nESAPI'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.\n\n## `encodeForSQL` is an unpatchable primitive.\n\n`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.\n\nThe 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.\n\nThe 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.\n\nPoC: [dickfu/ESAPI-SQLinjection-CVE-2025-5878-Exploit](https://github.com/dickfu/ESAPI-SQLinjection-CVE-2025-5878-Exploit)","closing_line":"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.","hook_md":"ESAPI is the Open Web Application Security Project's Enterprise Security API. `ESAPI.encoder().encodeForSQL(Codec codec, String input)` is the method a developer reaches for after they have read the OWASP SQL Injection Prevention Cheat Sheet, decided they cannot use a `PreparedStatement` for some reason, and want a function whose name promises to escape SQL input. CVE-2025-5878 is the demonstration that the codec argument names a specific SQL dialect's parser, that the input the application concatenates the encoder's output into is parsed by whatever database that application actually connects to, and that those two parsers do not have to be the same.\n\nESAPI 2.7.0.0 ships in response. The codec's `encodeCharacter` is byte-for-byte the same. What changed is that the method now throws `NotConfiguredByDefaultException` unless the deployer sets a property the maintainer almost named `ESAPI.enableLegCannonModeAndGetMyAssFired.justification`.","post_id":583,"slug":"esapi-cve-2025-5878-oraclecodec-encoded-for-the-wrong-dialect","title":"CVE-2025-5878: ESAPI's OracleCodec Encoded For Oracle. The Application Was Talking To MySQL.","type":"initial","unreadable_sentence":"The patch did not add backslash escaping. The patch added a property the deployer has to set to confirm that they are using a leg cannon."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCawza5wAKCRDeZjl4jgkQ JlB+AQDgAs6cPqxuayF0i+dhZNl9i4z2TMJ9AhHgay+UezFV7AD9GyJYNPTGUPIH 8QAOg4/8JogjDbLiiQZXeK1bNoqaow4= =IInT -----END PGP SIGNATURE-----