← PHP / Laravel · Contents

PHP-005 / Beginner

Mass assignment: passing $request->all() directly to create or update

A01:2021 Broken Access Control · CWE-915 Mass Assignment

Why is this a problem?

An attacker can submit additional fields not present in the form, such as is_admin or role, to change privileges.

How to fix it

php
// Model: protected $fillable = ['name', 'email', 'password'];
User::create($request->validated());  // Only fields allowed by FormRequest

Further reading