PHP-016 / Beginner
Constructing file paths from user input (path traversal)
Why is this a problem?
Input such as ../../.env enables arbitrary file reads.
How to fix it
php
$name = basename($request->name); // Remove path components
$path = storage_path('app/reports/'.$name);
abort_unless(str_starts_with(realpath($path) ?: '', realpath(storage_path('app/reports')).DIRECTORY_SEPARATOR), 404);