← PHP / Laravel · Contents

PHP-034 / Beginner

Using $request->all() without input validation

A03:2021 Injection · CWE-20 Improper Input Validation

Why is this a problem?

Values whose type, length and format are unchecked reach the DB or external APIs.

How to fix it

php
$data = $request->validate([
    'name'  => 'required|string|max:100',
    'price' => 'required|integer|min:0',
]);
Product::create($data);

Further reading