← PHP / Laravel · Contents

PHP-065 / Beginner

Not using strict mode in in_array()

A01:2021 Broken Access Control · CWE-697 Incorrect Comparison

Why is this a problem?

in_array(0, ['admin']) returns true in PHP 7, bypassing authorization checks.

How to fix it

php
if (in_array($request->input('role'), ['admin', 'editor'], true)) { ... }

Further reading