-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The auth gate inspected the path segment the attacker did not invoke\n\nOFBiz routes requests through `RequestHandler.doRequest`. The vulnerable build (commit `0b26b915`, in tree through 18.12.14) takes the request URI and pulls two distinct names out of it:\n\n```java\nString overrideViewUri = getOverrideViewUri(path);\n```\n\n`getOverrideViewUri` returns everything after the first path segment. For `/webtools/control/main/ProgramExport`, the first segment is `main` and the override view is `ProgramExport`.\n\nThe auth check then runs against the first segment:\n\n```java\nif (requestMap.securityAuth) {\n ...\n String checkLoginReturnString = (String) checkLoginEvent.invoke(...);\n if (!\"success\".equalsIgnoreCase(checkLoginReturnString)) {\n ...\n }\n}\n```\n\nIn `framework/webtools/webapp/webtools/WEB-INF/controller.xml`, the `main` request-map declares ``. Auth is satisfied trivially. The request-map for `ProgramExport` declares `auth=\"true\"`, but the handler never visits it. It visited `main`.\n\nThen the view name is computed and rendered:\n\n```java\nString viewName = (UtilValidate.isNotEmpty(overrideViewUri)\n && (eventReturn == null || \"success\".equals(eventReturn)))\n ? overrideViewUri : nextRequestResponse.value;\n```\n\n`overrideViewUri` is `ProgramExport`. The view-map for `ProgramExport` in the same `controller.xml`:\n\n```xml\n\n```\n\nThere is no `auth` attribute on view-maps in 18.12.14. The renderer reads the view-map, walks the screen widget, and executes the Groovy script the screen names.\n\nThe attacker named one URL segment to satisfy auth and a second URL segment to pick the renderer. The handler asked each gate about the segment that gate cared about, got the answer it wanted, and moved on.\n\n## The sandbox forbade `exec`. The Groovy lexer decoded `\\u0065\\u0078\\u0065\\u0063` back into `exec`.\n\n`ProgramExport.groovy` evaluates `parameters.groovyProgram` in a `GroovyShell`. Before the patch lineage that produced CVE-2024-38856, the sandbox between request body and `shell.evaluate` looked like this (commit `0b26b915`, November 13 2020):\n\n```groovy\n// TODO more can be added...\nif (groovyProgram.contains(\"new File\")\n || groovyProgram.contains(\".jsp\")\n || groovyProgram.contains(\"<%=\")) {\n request.setAttribute(\"_ERROR_MESSAGE_\", \"Not executed for security reason\")\n return\n}\n```\n\nBy the build that shipped CVE-2024-38856, the gate had been promoted to a call into `SecuredUpload.isValidText`:\n\n```groovy\nif (!org.apache.ofbiz.security.SecuredUpload.isValidText(groovyProgram, [\"import\"])) {\n request.setAttribute(\"_ERROR_MESSAGE_\", \"Not executed for security reason\")\n return\n}\n```\n\n`SecuredUpload.isValidText` is a case-insensitive substring scan against a 32-token deny-list. Among the tokens: `exec`, `import`, `runtime.getruntime().exec(`, `processbuilder`. The implementation is one line:\n\n```java\nprivate static boolean isValid(String content, String string, List allowed) {\n return !content.toLowerCase().contains(string) || allowed.contains(string);\n}\n```\n\nThe PoC body, before any HTTP parsing, is:\n\n```\ngroovyProgram=\\u0074\\u0068\\u0072\\u006f\\u0077\\u0020\\u006e\\u0065\\u0077\\u0020\\u0045\\u0078\\u0063\\u0065\\u0070\\u0074\\u0069\\u006f\\u006e\\u0028\\u0027\\u0069\\u0064\\u0027\\u002e\\u0065\\u0078\\u0065\\u0063\\u0075\\u0074\\u0065\\u0028\\u0029\\u002e\\u0074\\u0065\\u0078\\u0074\\u0029\\u003b\n```\n\nThat string is what `isValidText` sees. Lowercased and substring-scanned, it contains none of: `exec`, `import`, `processbuilder`, `runtime.getruntime`. The deny-list passes the string through to `shell.evaluate`.\n\n`GroovyShell.evaluate` hands the string to the Groovy lexer. The lexer resolves `\\uXXXX` escapes during pre-tokenization, before identifier tokens are formed. After pre-tokenization the source reads:\n\n```groovy\nthrow new Exception('id'.execute().text);\n```\n\nNow there are tokens. `Exception`, `execute`, `text`. None of them existed when `isValidText` looked. The string the deny-list scanned and the program the lexer compiled are different artifacts. The deny-list looked at the first one and the lexer compiled the second one.\n\n`'id'.execute()` is the Groovy idiom for spawning a shell, and `.text` reads stdout. The PoC throws the output back as an exception message, which OFBiz writes into `_ERROR_MESSAGE_` and renders into the response body. The nuclei matcher pattern `uid=\\d+\\(([^)]+)\\) gid=\\d+\\(([^)]+)\\)` reads the result.\n\nSource grep is not a sandbox. The deny-list inspects bytes, the interpreter compiles a program, and the bytes and the program are not the same artifact.\n\n## The `// TODO more can be added...` shipped in November 2020\n\nCommit `0b26b915` introduced the `new File` / `.jsp` / `<%=` substring check. It was patching OFBIZ-12055, a Groovy-injection finding from an earlier disclosure. The first line of the if-statement is the comment:\n\n```\n// TODO more can be added...\n```\n\nThis is a TODO that shipped. The developer wrote a substring check, named it inadequate in the same commit, and pushed it. OFBIZ-12305 (2021) re-opened the same screen for a different bypass and re-tightened the substring list. OFBIZ-13128 (the CVE-2024-38856 ticket, July 2024) added the permission check inside the script:\n\n```groovy\nif (!security.hasPermission('ENTITY_MAINT', userLogin)) {\n return\n}\n```\n\nOFBIZ-13130 (August 2024) added auth gating to view-maps in `RequestHandler` so the override-view trick stops bypassing request-map auth:\n\n```java\nif (viewMap.isSecurityAuth() && UtilValidate.isEmpty(userLogin)) {\n ...checkLoginEvent...\n if (!\"success\".equalsIgnoreCase(checkLoginReturnString)) {\n throw new RequestHandlerException(\n \"An active login is required for view with name [\" + view + \"]\");\n }\n}\n```\n\nFour JIRA tickets, four patches, four years, one screen. `ProgramExport.groovy` is the design debt driver: the patches address symptoms, the screen holds the primitive. The substring sandbox in `SecuredUpload.isValidText` is still the sandbox. The TODO that shipped on its first ancestor was written three years and nine months before CISA added CVE-2024-38856 to the Known Exploited Vulnerabilities catalog.\n\n## The patch closes this CVE. The substring sandbox is still the sandbox.\n\n`security.hasPermission('ENTITY_MAINT', userLogin)` is the right check for who should run a Groovy script against the production delegator. The OFBIZ-13130 patch closes the override-view auth bypass for `ProgramExport` and for every other view-map whose request-map was supposed to be the auth gate.\n\nWhat no patch in the CVE-2024-38856 cluster touches is the premise that string-matching tokens against attacker-controlled source is the way to keep a Groovy interpreter from running attacker-controlled programs. `SecuredUpload.isValidText` still ships, still scans the request body for the substring `exec`, and still hands the surviving string to a lexer that decodes `\\u0065\\u0078\\u0065\\u0063` back into `exec` before any token is constructed. The next disclosure against `ProgramExport.groovy` will run the same line of the deny-list and lose for the same reason.\n\n---\n\nPoC: [projectdiscovery/nuclei-templates CVE-2024-38856.yaml](https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2024/CVE-2024-38856.yaml)","closing_line":"Both gates inspected an artifact the next stage did not act on, and both were documented as inadequate by the developers who wrote them three years and nine months before CVE-2024-38856 landed in KEV.","hook_md":"Apache OFBiz's `ProgramExport` screen runs an attacker-supplied Groovy program. The script lives behind an auth-required URL and a substring deny-list. CVE-2024-38856 is the unauthenticated chain that goes through both gates without satisfying either. The patch is a three-line `if (!security.hasPermission(...)) return` at the top of the script; it addresses one of the gates and leaves the other one exactly as the developer who wrote it described it in November 2020.","post_id":499,"slug":"apache-ofbiz-cve-2024-38856-auth-saw-main-renderer-ran-programexport","title":"CVE-2024-38856: Apache OFBiz's Auth Gate Saw `main`. The Renderer Ran `ProgramExport`.","type":"initial","unreadable_sentence":"The string the deny-list scanned and the program the lexer compiled are different artifacts."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCan4L4gAKCRDeZjl4jgkQ JtKMAPoDo3yFMp8bvCbtHHuLyhFa7BzrfOSW+QaQrEeDodulLAD+M+k9Xhv+Q/Cx lTzizVe0tZHNosgKg1pQAfUJ8NtqLAs= =zokc -----END PGP SIGNATURE-----