Guides · SaaS

Laravel production security checklist: .env, debug mode, permissions and more.

A practical security checklist before launching a Laravel app: APP_DEBUG, .env exposure, document root, HTTPS, rate limits and uploads.

Key takeaways

  • APP_DEBUG must be false in production, and the web root must be public/.
  • Never commit .env, and never reuse the same keys across environments.
  • Most Laravel incidents come from configuration and forgotten checks, not from the framework itself.
  • Treat this list as a minimum, not a guarantee. Security is ongoing work.

1. Debug off, environment production

In .env:

APP_ENV=production
APP_DEBUG=false

With debug on, an error page can reveal environment variables, database details and stack traces to anyone.

2. Web root is public

The site must serve from public/. If the project root is exposed, .env and source files may be downloadable. Test after deployment: requesting /.env on your domain must not return the file.

3. Secrets stay out of Git

Add .env to .gitignore and keep .env.example with placeholders. If a secret was ever committed, rotate it. Deleting the file later does not remove it from history.

4. HTTPS everywhere

Use a valid certificate, redirect HTTP to HTTPS, and set APP_URL to the https address. Consider HSTS once you are sure HTTPS works for every subdomain.

5. Authentication hygiene

  • Hash passwords with Laravel's default hashing, never your own scheme.
  • Rate limit login, password reset and OTP endpoints.
  • Use Gate or policies for authorisation, and check ownership on every record access.
  • Verify email or phone where it matters.

6. Mass assignment

Define $fillable on models, or $guarded carefully. Avoid Model::create($request->all()). Validate with Form Requests and pass only validated data.

7. SQL injection and queries

Eloquent and the query builder use parameter binding. Danger appears when you concatenate user input into DB::raw() or whereRaw(). Pass bindings as the second argument.

8. File uploads

  • Validate type and size.
  • Store uploads outside public/ or on a disk that does not execute code.
  • Generate your own file names. Never trust the original.
  • Serve private documents through controller checks or signed URLs.

9. XSS and output

Blade's {{ }} escapes output. {!! !!} does not. Use the second only for content you have sanitised.

10. CSRF and cookies

Keep the CSRF middleware on web routes. Set secure, HTTP-only and same-site cookie options appropriate for your app.

11. Webhooks and callbacks

Verify signatures before trusting payloads. See how to verify Razorpay webhook signatures.

12. Dependencies and updates

Run composer audit and update packages regularly. Remove unused ones. Keep PHP supported and patched.

13. Logging and backups

Do not log secrets or full card or document data. Keep automated, tested backups stored off the server.

14. Permissions

Only storage and bootstrap/cache need to be writable. Do not use chmod 777.

Quick test list

  1. /.env, /storage/logs/laravel.log and /vendor/ return 403 or 404.
  2. A forced error shows a generic page, not details.
  3. A second user cannot open the first user's record by changing an ID.
  4. Brute-force requests to login get blocked.

Frequently asked questions

Is Laravel secure by default?

It provides good defaults, such as parameter binding, CSRF protection and output escaping. Misconfiguration and custom code remain the usual weak points.

Do I need a penetration test?

For sensitive or regulated data, a professional review is wise. This checklist covers common basics only.

How often should I update?

Check for security releases regularly and apply them promptly after testing.

See the SaaS products I build with Laravel.

See the products