← PHP / Laravel · Contents

PHP-088 / Beginner

Missing array-input type validation

A03:2021 Injection · CWE-20 Improper Input Validation

Why is this a problem?

Arrays such as ids[]=1&ids[]=… reach functions expecting strings, causing exceptions or bypasses.

How to fix it

php
$data = $request->validate(['ids' => 'required|array|max:50', 'ids.*' => 'integer']);
User::whereIn('id', $data['ids'])->get();

Further reading