← Java / Spring · Contents

JAVA-076 / Intermediate

Unbounded MyBatis <foreach> input arrays

A04:2021 · CWE-770 · CWE-89 (binding is safe)

Why is this a problem?

An IN clause with tens of thousands of values overloads the database.

How to fix it

java
if (ids.size() > 500) throw new IllegalArgumentException();   // Limit the count in the service

Further reading