You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Mridul Pathak (Jira)" <ji...@apache.org> on 2026/09/27 07:58:00 UTC

[jira] [Closed] (OFBIZ-13620) DELETE statements built from EntityCondition inline field values as unescaped SQL literals instead of bound parameters

     [ https://issues.apache.org/jira/browse/OFBIZ-13620?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mridul Pathak closed OFBIZ-13620.
---------------------------------
    Fix Version/s: Upcoming Branch
                   24.09.08
       Resolution: Fixed

> DELETE statements built from EntityCondition inline field values as unescaped SQL literals instead of bound parameters
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: OFBIZ-13620
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-13620
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework/security
>    Affects Versions: Upcoming Branch, 24.09.07
>            Reporter: Mridul Pathak
>            Assignee: Mridul Pathak
>            Priority: Major
>             Fix For: Upcoming Branch, 24.09.08
>
>
> {{GenericDAO.deleteByCondition()}} builds the WHERE clause of DELETE statements by calling {{condition.makeWhereString(modelEntity, null, this.datasource, sqlP.getDelegator())}}, passing {{null}} as the entity condition params list. {{EntityConditionUtils.addValue()}} treats a null params list as a reason to also drop the {{ModelField}} it was given, even though one is available:
> {code:java}
> static void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) {
>     SqlJdbcUtil.addValue(buffer, params == null ? null : field, value, params);
> }
> {code}
> With a null field, {{SqlJdbcUtil.addValueSingle()}} inlines the value into the SQL text as a quoted literal instead of a {{?}} bind parameter, escaping only single quotes ({{value.replace("'", "''")}}), with no backslash handling. On MySQL/MariaDB, whose default {{sql_mode}} treats a backslash inside a string literal as an escape character, a value containing a leading {{\\}} before a quote causes the backslash to consume the closing quote OFBiz just appended, so the rest of the value is parsed as SQL rather than as data. The quote-doubling in place does not account for this.
> This path is reachable from every {{Delegator.removeByAnd(...)}} / {{Delegator.removeByCondition(...)}} call (via {{GenericHelperDAO.removeByCondition()}} → {{GenericDAO.deleteByCondition()}}), several of which pass request-derived values in, e.g. {{ProductEvents.removeProductFeatureAppl()}}, reachable via the authenticated, permission-gated {{quickAdminRemoveProductFeature}} request-map.
> h3. Steps to Reproduce
> On a local MySQL 8.0.31 instance (default {{sql_mode}}), building the same EntityCondition shape {{removeByAnd("ShoppingListItem", [shoppingListId: value])}} constructs, with {{value = "\\\\') OR 1=1 -- "}}, produces:
> {code:sql}
> DELETE FROM SHOPPING_LIST_ITEM WHERE (SHOPPING_LIST_ID = '\\'') OR 1=1 -- ')
> {code}
> Running this against a 3-row test table removed all rows (confirmed 4/4 on a repeat run); with {{NO_BACKSLASH_ESCAPES}} set, 0 rows were removed. H2 (the framework's own default datasource) was not affected by this payload shape, since it doesn't treat backslash as a literal escape character by default.
> h3. Suggested Fix
> {{deleteByCondition()}} should build and bind a real {{EntityConditionParam}} list through to {{SQLProcessor}}, the same way the existing SELECT/UPDATE paths in {{GenericDAO}} already do, instead of passing {{null}}. The literal-inlining branch in {{addValueSingle()}} should stay for genuine unmapped/raw-SQL values; the fix is to stop deriving bind-vs-inline from whether the caller passed a null params list when a real {{ModelField}} is actually available.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)