← PHP / Laravel · Contents

PHP-051 / Intermediate

Missing scope in route model binding

A01:2021 Broken Access Control · CWE-639 Authorization Bypass via User-Controlled Key

Why is this a problem?

Child resources are retrieved independently of the parent, allowing access to another user's data.

How to fix it

php
Route::get('/posts/{post}/comments/{comment}', ...)->scopeBindings();

Further reading