Quick answer: most Laravel security problems in production come from configuration and habits, not from the framework. Turn off debug mode, keep secrets out of the code, validate everything, protect file uploads, rate limit logins and APIs, send security headers, and keep PHP, Laravel and packages patched. The fifteen checks below cover the gaps we find most often.
Laravel gives you a lot for free: protection against SQL injection through the query builder, cross site request forgery tokens, encrypted cookies, hashed passwords. That is why people call it secure. It is also why teams relax, and relaxed teams ship the same fifteen mistakes again and again.
We review Laravel applications regularly, our own and clients'. The list below is the one we run through first. You can check most of it in a single afternoon with your developer.
Configuration and secrets
1. Debug mode is off in production
With debug on, an error page can show environment values, database details and code paths to anyone who triggers a failure. Set the debug flag to false and confirm it on the live server, not just in the repository.
2. Secrets live in the environment, not the code
Database passwords, mail credentials and API keys belong in environment variables or a secrets manager. If a key was ever committed to the repository, treat it as exposed and replace it, even if the repository is private.
3. The application key is set and never shared
The key protects encrypted data and sessions. If it leaks, rotate it and plan for users to sign in again.
4. Sensitive files cannot be downloaded
Your web server should point at the public folder only. Test by requesting the environment file and the lock file from the browser. Both must fail.
Input, output and data
5. Every request is validated on the server
Browser checks are a courtesy for users, not a defence. Validate type, length and allowed values for every field in a form request or validator.
6. Mass assignment is controlled
Use an allow list of fillable fields on each model. Never pass the whole request into a create or update call, or a user can set fields such as role or price that you never meant to expose.
7. Raw queries use bindings
The query builder protects you until someone writes a raw query by gluing strings together. Search the code for raw expressions and make sure every user value is bound as a parameter.
8. Output is escaped
The default template syntax escapes output. The risk appears when someone uses the unescaped form to print user content. Allow it only for content you have sanitised, and nothing else.
9. File uploads are treated as hostile
Check the real file type, not just the extension, set a size limit, generate your own file names and store uploads outside the public folder when you can. Never allow a user to upload something the server will execute.
Access and abuse
10. Authorization is checked on every action
Logging in is not permission. Use policies or gates so a customer cannot open another customer's invoice by changing a number in the address. This one flaw, often called an insecure direct object reference, causes a large share of real data leaks.
11. Login, password reset and APIs are rate limited
Limit attempts per user and per address. Without limits, attackers can try thousands of passwords or scrape your whole API.
12. Sessions and cookies are configured for the web as it is today
Set cookies to secure and http only, choose a sensible same site value, and expire idle sessions. Offer two factor authentication for staff and administrators.
Delivery and upkeep
13. Security headers are sent
A content security policy, frame protections, strict transport security and a referrer policy shut down whole classes of browser attacks. They are a few lines of configuration with a large payoff.
14. Dependencies are watched
Run a dependency audit on every build and review the results. Remove packages you no longer use, since each one is extra surface. Our guide on keeping Composer and npm dependencies safe explains how.
15. Logging and backups are real
Log sign ins, permission failures and admin actions, and send alerts for unusual patterns. Keep backups in a separate place and practise restoring them. If you cannot rebuild from a backup, you are one bad day from a very long week.
How to use this list
Print it, sit with your developer and mark each line green, amber or red. Fix the reds this week, plan the ambers, and put a calendar reminder to repeat the exercise every quarter. If an honest answer to several items is "I am not sure", a short external review is money well spent. Our engineers do this regularly as part of custom software development and ongoing support.
Frequently Asked Questions
Is Laravel secure enough for a business application?
Yes. Laravel includes strong defaults for many common attacks. Security in production depends on how the application is configured, how the code is written on top of the framework, and how well it is kept up to date.
What is the most common Laravel security mistake?
Leaving debug mode on and missing authorization checks are the two we see most. Both are easy to find and easy to fix once someone looks.
How often should a Laravel application be security reviewed?
A lightweight review every quarter and a deeper review once a year or before a major launch is a good rhythm for most businesses.
Do I need a penetration test?
If you handle payments, health data or other sensitive information, or if customers ask for evidence, yes. Pair it with the regular checks above so the test finds new problems instead of old ones.
Be the first to comment.