← PHP / Laravel · Contents

PHP-063 / Intermediate

User input in cache keys (cache-key collision or injection)

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

Why is this a problem?

Other users' cache entries can be overwritten or read.

How to fix it

php
Cache::remember("profile:".$request->user()->id, 3600, fn() => ...);  // Authenticated user ID

Further reading