Laravel security

Laravel security is mostly a set of small habits applied consistently: validate what comes in, escape what goes out, keep secrets out of Git and logs, and keep dependencies current. This page collects every PHP Hub lesson and weekly brief that touches Laravel, grouped by the part of the app you are trying to protect.

The lessons are practical and short. Each one explains the risk, shows the safe pattern in Laravel or plain PHP, and links to official documentation so you can check the details yourself. The weekly briefs track advisories for PHP projects and are fact-checked against the advisory records. New Laravel posts show up here automatically.

Not sure where to begin? Start with auth and sessions, then input handling, then secrets. Pair it with the free PHP Security Checker for a quick outside look at a site you own.

Auth & sessions

Lesson · 12 Nov 2026

Rate Limiting Login in Laravel: throttle, RateLimiter and Fortify

Define named Laravel rate limiters with RateLimiter::for() and Limit::perMinute()->by(), attach them with the throttle middleware (HTTP 429 when exceeded), and keep Fortify's default login throttle: 5 attempts per 60 seconds, keyed by username and IP.

Lesson · 11 Nov 2026

Open Redirects in PHP and Laravel: Validating ?next= and Return URLs

Laravel's redirect()->to() returns full URLs like https://evil.example or //evil.example unchanged, so redirect($request->input('next')) is an open redirect. Accept only single-slash local paths (or an explicit host allowlist), reject backslashes and control characters, and fall back to a safe default.

Input, validation & mass assignment

Lesson · 23 Nov 2026

Laravel exists and unique Rules: Two Advisories and How to Validate Safely

Laravel published two moderate advisories for laravel/framework on 18 Nov 2026: Rule::exists()/Rule::unique() fluent where() values can be read as predicates, and exists can be bypassed by integer or boolean JSON input on MySQL/MariaDB. Upgrade to 12.73.0 or 13.43.0, add string rules before exists/unique, and keep independent ownership checks.

Lesson · 13 Nov 2026

SSRF in PHP HTTP Clients: Don't Fetch User-Supplied URLs

SSRF happens when your server fetches a URL an attacker chose. Don't pass request input to file_get_contents(), cURL or Laravel's Http::get(). Allow-list the hosts you intend to call, require HTTPS, reject URLs with credentials, and disable redirects.

XSS & CSRF

Secrets, encryption & signed URLs

Lesson · 21 Nov 2026

Keeping Secrets Out of Git: .env, APP_KEY and APP_DEBUG

Laravel's documentation says the .env file should not be committed to source control. Keep APP_KEY and database credentials in the environment, set APP_DEBUG to false in production, and after config:cache only call env() from config files. If you need a file in git, use php artisan env:encrypt and store the decryption key in a password manager.

Lesson · 17 Nov 2026

Signed URLs in Laravel: signedRoute, Expiry and the signed Middleware

Laravel signed URLs append an HMAC to the query string so the path and query cannot be altered unnoticed. Prefer URL::temporarySignedRoute() with an expiry, protect the route with the signed middleware, and read parameters with $request->query() because the request body is not signed.

Lesson · 16 Nov 2026

Encryption in Laravel and PHP: Crypt, APP_KEY and sodium

Laravel's Crypt::encryptString() uses OpenSSL AES-256-CBC and signs every value with a MAC. Generate APP_KEY with php artisan key:generate, never commit it, and use APP_PREVIOUS_KEYS when you rotate. In plain PHP, use the sodium extension's documented secretbox API rather than a home-grown cipher.

Files & uploads

Lesson · 14 Nov 2026

Path Traversal in PHP and Laravel: Safe File Paths

Never concatenate request input onto a filesystem path. Reject null bytes, backslashes and absolute paths, resolve the result with realpath(), and allow the file only when it stays inside a known base directory. realpath() returns false when the path does not exist, so new files need a parent-directory check.

Logging & data leaks

Lesson · 22 Nov 2026

Logging Without Leaking Secrets or PII in PHP and Laravel

Do not log $request->all(), Authorization headers, cookies or passwords. Use Laravel's Log facade with a request id from Log::withContext() or shareContext(), and run context arrays through a redaction helper before writing them. Logs are often copied to Slack, files and log vendors — a secret in a log is a secret out of your app.

Lesson · 20 Nov 2026

PHP Deserialization Risks: Why unserialize Is Unsafe for User Input

The PHP manual warns: do not pass untrusted input to unserialize(), regardless of allowed_classes. Unserialization can instantiate objects and run code during autoloading. Prefer json_encode() / json_decode() for data you accept from users, and treat allowed_classes as a hardening step for trusted payloads only.

Dependencies & advisories

Brief · 23 Nov 2026

PHP security this week (16–23 Nov 2026)

Five PHP advisories worth a look: Jane OpenAPI codegen RCE, Silverstripe framework RCE, Paymenter (Laravel/Livewire) unauthenticated method call, Contao admin self-grant, and a SimpleSAMLphp SAML2 signature bypass. None is on CISA KEV.

Brief · 16 Nov 2026

PHP security this week (9–16 Nov 2026)

Quiet week in PHP: Laravel concurrency output injection (low), two medium code16/sharp flaws, and a FileGator upload/batch-download pair. None is on CISA KEV.

Lesson · 15 Nov 2026

Auditing PHP Dependencies with composer audit

Run composer audit (and composer audit --locked in CI) against the Packagist advisory API. The command exits 0 when it finds no issues and 1 when packages match a policy, including security advisories, abandoned packages or malware flags. composer update already runs an audit unless you pass --no-audit.

Questions

Where should I start?

Begin with the lessons on sessions and login, then XSS and CSRF. They cover the routes most Laravel apps expose first.

Are the lessons only about Laravel?

Many also show the plain PHP version of the pattern, so you can see what the framework helper is doing.

How do I keep up with new advisories?

Read the weekly security briefs listed under dependencies and advisories, and run composer audit as the lesson shows.