← Java / Spring · Contents

JAVA-075 / Advanced

Injecting input into MyBatis <if> OGNL conditions

A03:2021 Injection · CWE-917 Expression Language Injection

Why is this a problem?

Test expressions are evaluated as OGNL, making it dangerous to mix input into them.

How to fix it

xml
<if test="name != null and name != ''"> AND name = #{name} </if>

Further reading