← Java / Spring · Contents

JAVA-003 / Intermediate

MyBatis ${} in value positions

A03:2021 Injection · CWE-89 SQL Injection

Why is this a problem?

${} substitutes text directly rather than binding a value.

How to fix it

xml
<select id="findByName" resultType="User">
  SELECT * FROM users WHERE name = #{name}
</select>

Further reading