Laravel Security Checklist Before You Launch a Client Application
Before a Laravel application goes in front of a client's customers, someone should walk through it once with a list. Most checklists are generic: "validate input", "use HTTPS". This one is shorter on slogans and longer on evidence. Where I could test an item, I tested it and say what I saw. Where I could not, I label it a recommendation, so you know which statements rest on a run and which on experience and documentation.
What this article is, and is not
The checks were run in a fresh Laravel 13 application on PHP 8.3 and MySQL, with 5 automated tests (22 assertions) for the headers and throttling, plus manual requests for the rest. "Checked" means I observed it there. It does not mean your application is secure, and a checklist does not replace a proper security review or a penetration test. Items marked "Recommended" come from general practice and the Laravel documentation, and I did not test them here.
1. Configuration and secrets
| Item | Why | How to check | Status |
|---|
APP_DEBUG=false in production | Debug mode returns exception classes, file paths and more in error responses | Request an unknown or unauthorised URL with an Accept: application/json header and read the body | Checked: with debug on, an unauthorised request returned an 11,110-byte body naming the exception class and file paths. With debug off, the body was 21 bytes |
APP_ENV=production | Environment-specific behaviour, including some framework warnings | Read the value on the server | Recommended |
A unique APP_KEY per environment | It signs cookies and encrypts data. A shared or leaked key weakens both | Confirm it is set on the server, and not in the repository | Recommended |
The web server serves only public/ | Otherwise .env and source files are reachable | Request /.env from outside and expect 404 or 403 | Recommended |
| Secrets in the environment, not in code | Code gets shared, committed and pasted into chats | Search the repository for keys and tokens | Recommended |
| Dependency audit | Known vulnerabilities in packages | Run composer audit and, for the front end, npm audit | Checked: composer audit ran and reported no advisories on the day I ran it. Re-run it regularly, since advisories change |
2. Authentication and sessions
| Item | Why | How to check | Status |
|---|
| Passwords are hashed with a slow algorithm | Stolen hashes should be expensive to crack | Read config('hashing') | Checked: the default driver is bcrypt with 12 rounds |
| Session cookie flags | JavaScript must not read it, and it should travel only over HTTPS | Read config('session') | Checked: http_only is true and same_site is lax. secure is unset by default: set SESSION_SECURE_COOKIE=true once you serve HTTPS |
| Login and password-reset throttling | Stops password guessing | Send more attempts than allowed and expect a 429 | Checked for the mechanism: a route limited to 3 requests a minute returned 429 with a Retry-After header on the fourth. Confirm your login route actually has a limit |
| Two-factor authentication for admin accounts | An admin password alone is a single point of failure | Enable it in your authentication package | Recommended |
| No demo or seeded accounts, no default credentials | Seeders and starter kits create predictable accounts | List the users table before launch and remove what is not real | Recommended |
3. Authorization
Authentication tells you who someone is. Authorization decides what they may do, and missing authorization is the most common serious flaw in real applications.
- Use policies or gates for every resource, and check them in controllers or form requests.
- Scope queries to the owner.
Order::find($id) lets any logged-in user read any order by changing the number in the URL. $request->user()->orders()->findOrFail($id) does not.
- Guard against mass assignment. Keep an explicit list of fillable attributes. Avoid
$guarded = [].
A quick way to see where the doors are: list every state-changing route that has no auth middleware, and explain each one.
use Illuminate\Support\Facades\Route;
$open = collect(Route::getRoutes()->getRoutes())
->filter(fn ($r) => array_intersect($r->methods(), ['POST', 'PUT', 'PATCH', 'DELETE']))
->reject(fn ($r) => collect($r->gatherMiddleware())->contains(fn ($m) => is_string($m) && str_starts_with($m, 'auth')))
->map(fn ($r) => implode('|', array_diff($r->methods(), ['HEAD'])).' /'.$r->uri())
->values();
I ran this in the test application. It listed four routes: a signed webhook endpoint, an endpoint that checks a shared secret, a local-only test route, and PUT /storage/{path}. The last one belongs to Laravel itself, for signed temporary uploads on the local disk. Unsigned requests to it, a GET for a file, and a path-traversal attempt all returned 403. The point of the exercise is not that the list is empty. It is that every entry has a reason you can state.
4. Input, output and uploads
- Validate with form requests, and validate what you use, including data from webhooks and AI models. Recommended.
- Escape output. Blade's
{{ }} escapes. {!! !!} does not. In React, dangerouslySetInnerHTML does not either, so only give it HTML you wrote or have sanitised. Recommended.
- Use bindings for any raw SQL. Never concatenate input into a query. Recommended.
- Uploads: check size and type on the server, never trust the client's file name or MIME type, store with generated names, and keep private files off the public disk. Recommended.
- Serve private files through signed, expiring URLs. Checked that Laravel's own storage route refused every unsigned request I sent.
5. Headers, HTTPS and cookies
Laravel does not add security headers by default. I requested a plain response and it carried only Cache-Control, Date and Content-Type. A small middleware adds the baseline:
app/Http/Middleware/SecurityHeaders.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class SecurityHeaders
{
public function handle(Request $request, Closure $next): Response
{
$response = $next($request);
$response->headers->set('X-Content-Type-Options', 'nosniff');
$response->headers->set('X-Frame-Options', 'SAMEORIGIN');
$response->headers->set('Referrer-Policy', 'strict-origin-when-cross-origin');
$response->headers->set('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
// Only over HTTPS: a browser must never be told to "always use HTTPS" by a plain HTTP response.
if ($request->isSecure()) {
$response->headers->set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
}
return $response;
}
}
Register it for every request in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware): void {
$middleware->append(\App\Http\Middleware\SecurityHeaders::class);
})
Five tests (22 assertions) pass for it: the headers are on normal and error responses, and HSTS appears only on HTTPS requests. Two things to know:
- Behind a load balancer or proxy, configure trusted proxies so that
$request->isSecure() is true. Otherwise the HSTS line never fires. Recommended; depends on your setup.
- A Content-Security-Policy is worth having but has to be written for your pages, including any inline scripts your front end uses. I did not test one here, and a wrong policy breaks the site, so build it deliberately, preferably in report-only mode first.
6. Logging, backups and operations
- Do not log secrets or whole payloads that may contain personal data. Log identifiers and outcomes. Recommended.
- Give the application database user only the privileges it needs. Recommended.
- Back up the database and files, and test a restore. A backup you have never restored is a hope. Recommended.
- Restart queue workers after every deploy or
.env change, so they do not run old code or old settings. Recommended; this one bit me in a real test.
- Monitor errors and failed jobs, and decide who gets the alert. Recommended.
- Keep the framework and packages updated, and read release notes for security fixes. Recommended.
The launch checklist, condensed
- Debug off, environment set to production, unique app key
- Only
public/ served, .env not reachable
- No demo accounts or default credentials, two-factor on for admins
- Session cookie secure and HTTP-only
- Login throttled, and other public forms throttled
- Policies on every resource, queries scoped to the owner, no unexplained open state-changing routes
- Validation on everything that comes in, escaping on everything that goes out
- Security headers on, HSTS over HTTPS, trusted proxies configured
composer audit and npm audit clean or explained
- Backups running, restore tested, workers restarted on deploy, alerts wired up
Common mistakes
- Leaving debug on because the site "works".
- Authenticating but not authorising, so users can read each other's records.
- Trusting the signature or the payload from a third party without validating it.
- Shipping starter-kit demo accounts.
- Treating the checklist as the goal. It finds known problems. It does not prove there are none.
Frequently asked questions
Is this enough for a security audit?
No. It is a pre-launch review of common problems. An audit or a penetration test goes further and is worth it for anything handling money or sensitive personal data.
Do I need all the headers?
The four in the middleware are cheap and rarely cause problems. Add a Content-Security-Policy when you can test it properly, and HSTS only once your site is reliably served over HTTPS.
How often should I run composer audit?
On every deploy, and on a schedule, because new advisories appear for versions you already run.
Does this apply outside Laravel?
The ideas do. The commands and defaults here are Laravel's, and I tested them on Laravel 13 only.
Where this fits
If you are about to launch a Laravel application, or you have inherited one and want to know where it stands, see Laravel & PHP Development for reviews and hardening, or describe your application here. More guides on this topic are collected under Authentication & Security.