← PHP / Laravel · Contents

PHP-007 / Beginner

IDOR: missing resource ownership checks

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

Why is this a problem?

Changing only an ID grants access to other users' orders or documents.

How to fix it

php
public function show(Order $order) {
    $this->authorize('view', $order);  // Compare user_id in the policy
    return $order;
}

Further reading