why you should never use the client supplied filename and extension
You should also validate file mime types
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
After a couple of post on image validation, I experimented with trying to run a script if a php file made it's way through. I sent this email to Taylor:
I have been experimenting with images and sneaking a php file through. In my test I just see if I can run phpinfo();
In an older custom framework when I open image in new tab I get:
Forbidden
You don't have permission to access this resource.
However in laravel 10 it opened and had the phpinfo displayed.
I suggest adding:
# Restrict php files direct access
RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ]
RewriteRule \.php$ - [F]
This prevents it. Perhaps add more to it, but beyond my knowledge at this time.
I haven't tested Nginx yet, if someone knows how to do the same for Nginx please post.
Note when I added that code above to the bottom of the stock htacces file Laravel ships with it prevented the execution.
Just FYI.
Please or to participate in this conversation.