We have an existing application running Seam 1.2. Today I tried upgrading to Seam 2.0.1.GA. In the process I discovered that the fix for
JBSEAM-2099 breaks the application because the application uses lots of query objects with an order clause that sorts on the result of an function, namely UPPER(): order="UPPER(p.lastname)".
This used to work under 1.2. So this is a regression that probably does affect a lot of real world applications. I have suggested the original fix and have to say it is not done probably. Even my latest version is not the proper way to fix this as it will not allow functions with multiple arguments, nor concatenations of properties, nor computing the order by-value... To fix this properly it definitly takes an EJBQL-Expert greater than me :-) I'm not even sure if there is an SQL-Injection threat here.
I don't mind implementing an insufficient fix for my special problem myself by extending the Query object and binding that to a custom namespace but I would appreciate if
a.) the regression would be properly documented, and
b.) the error message would tell the user what happened and what is necessary to fix it.
JBSEAM-2099so I have cloned it.The fix for
JBSEAM-2099does not work as expected because the regular expression is too restrictive.When I suggested the regex for input filtering I did not think of funtion based order clauses which are quite common in the real world, e.g.
<framework:entity-query name="qry_allPersons"
ejbql="SELECT p FROM Person p" entity-manager="#{entityManager}" order="UPPER(p.lastname)">
</framework:entity-query>
The query will raise an invalid argument exception "invalid order clause" because the order clause does not match the regular expression
"^[\\w\\.,\\s]*$" defined in ORDER_CLAUSE_PATTERN). (http://fisheye.jboss.com/browse/Seam/trunk/src/main/org/jboss/seam/framework/Query.java?r=7173).
I suggest changing this to
^(\\w+\\([\\w\\.\\s]+\\)\\s*,\\s*|[\\w\\.]+\\s*,\\s*)*(\\w+\\([\\w\\.\\s]+\\)|[\\w\\.]+)
which will alo match something like:
UPPER(p.lastname), p.age, LOWER(p.country).