← Java / Spring · Contents

JAVA-078 / Intermediate

Confusing MyBatis #{} and ${} when constructing IN clauses

A03:2021 Injection · CWE-89

Why is this a problem?

IN (${ids}) substitutes the comma-separated list directly.

How to fix it

xml
WHERE id IN <foreach item="id" collection="list" open="(" separator="," close=")">#{id}</foreach>

Further reading