Skip to content

fix: validate the arguments of JSON functions in ExpressionValidator - #2952

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:json-function-validation
Nov 23, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:json-function-validation

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

ExpressionValidator.visit(JsonFunction) and visit(JsonAggregateFunction) were empty (// no idea what this is good for), so nothing inside JSON_OBJECT, JSON_ARRAY, JSON_VALUE / JSON_QUERY, JSON_ARRAYAGG or JSON_OBJECTAGG was validated: not the key and value expressions, the aggregate argument, its FILTER, OVER (PARTITION BY .. ORDER BY ..) or inner ORDER BY, nor the PASSING and ON EMPTY / ON ERROR expressions. With Feature.function removed, SELECT JSON_ARRAY(upper(a)) FROM t validated with no errors while SELECT upper(a) FROM t is rejected, and with FeaturesAllowed.SELECT the subquery in SELECT JSON_ARRAY((SELECT a FROM t FOR UPDATE)) passed while the same subquery in the select list reports selectForUpdate. A caller that restricts user SQL with Validation could be bypassed by wrapping the disallowed part in a JSON constructor. I found it by listing the ExpressionValidator visits that return without looking at their children; ExpressionVisitorAdapter already walks these sub-expressions, so StatementFeatureVisitor and TablesNamesFinder were not affected. Both methods now validate the same sub-expressions the adapter walks. The new testValidateFunctionInJsonFunction (7 cases) and testValidateSubSelectInJsonFunction fail before (8 failures) and pass after; the util.validation tests, spotless, Checkstyle and PMD on main pass. The rest of ./gradlew test is unchanged on this Windows machine (the only local failures are 33 Mockito inline-mock-maker init errors and 2 temp-dir access errors, unrelated to this change).

@manticore-projects
manticore-projects merged commit e1519a6 into JSQLParser:master Nov 23, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants