Every web developer, regardless of the framework or language used, must face ever-evolving cyber threats. Ignoring security is no longer an option: a single bug can compromise sensitive data, user trust, and a company's reputation. This pillar guide covers broadly and structurally the three fundamental pillars for protecting web applications: the updated vulnerability map according to OWASP Top 10, modern passwordless authentication based on WebAuthn and OAuth 2.0 standards, and specific prevention techniques for attacks such as SQL Injection, Cross-Site Scripting (XSS), and Cross-Site Request Forgery (CSRF) in the Laravel/PHP ecosystem. This is not a superficial list, but a permanent reference manual for developers.
OWASP Top 10 2025: The Most Dangerous Web Vulnerabilities
The Open Web Application Security Project (OWASP) periodically publishes a ranking of the most critical vulnerabilities. The 2025 version maintains the category structure, with updates based on real data and changes in the ecosystem. Below we analyze the most relevant items for a Laravel/PHP developer.
A01 Broken Access Control
Access control is the mechanism that prevents a user from performing actions beyond their authorizations. Typical examples include accessing another user's data by modifying an ID in the URL (Insecure Direct Object Reference) or privilege escalation. In Laravel, the use of policies and gates is mandatory to ensure every operation is authorized. It is not enough to check authentication; authorization must be verified at the model and route level.
// Example policy in Laravel
public function view(User $user, Post $post)
{
return $user->id === $post->user_id;
}A02 Cryptographic Failures
This category groups encryption-related errors: passwords not hashed, sensitive data transmitted in cleartext (HTTP), use of weak algorithms, or hardcoded keys. In PHP, the password_hash() function with bcrypt or Argon2 is the standard. Laravel implements it automatically, but you must avoid storing data like credit card numbers or tokens without robust encryption. For data at rest, use Laravel Encryption with AES-256.
A03 Injection
Injection includes SQL, OS Command, and LDAP. In Laravel, the Eloquent ORM protects against SQL Injection as long as you use the Query Builder or ORM itself, avoiding raw queries without parameterization. However, a developer can introduce vulnerabilities if they use DB::raw() without sanitization. The rules are: never concatenate user input into queries and always use prepared statements.
// Safe
$users = User::where('email', $input)->get();
// Unsafe
$users = DB::select("SELECT * FROM users WHERE email = '$input'");A04 Insecure Design
These are architectural flaws: lack of rate limiting, missing server-side validation, vulnerable business logic. In Laravel, it's easy to implement Throttle Middleware to limit requests, but secure design goes beyond: every flow must be analyzed with threat modeling.
A05 Security Misconfiguration
Default insecure settings, exposed directories, verbose errors in production. Laravel hides stack traces in production with APP_DEBUG=false. It is essential to disable directory listing in web servers, use environment variables for secrets, and follow server hardening best practices.
A06 Vulnerable and Outdated Components
Outdated dependencies (npm packages, Composer) are one of the primary attack vectors. Use composer audit to detect known vulnerabilities in PHP libraries. Laravel itself releases security patches; keeping the framework updated is mandatory.
A07 Identification and Authentication Failures
Weak passwords, missing account lockout after failed attempts, non-invalidated sessions. Laravel offers robust mechanisms with Laravel Breeze or Jetstream, but it's crucial to implement MFA (multi-factor authentication) and, as we will see in the next section, transition to passwordless authentication methods.
A08 Software and Data Integrity Failures
Unsigned updates, insecure CI/CD, deserialization of untrusted data. In PHP, deserialization via unserialize() is dangerous; use JSON with schema validation instead.
A09 Security Logging and Monitoring Failures
Without adequate logs, attacks go unnoticed. Laravel offers logging through multiple channels (stack, daily, syslog). Integrate with tools like Laravel Telescope or external services for security event monitoring.
A10 Server-Side Request Forgery (SSRF)
The application makes HTTP requests to internal servers based on user input. In Laravel, when using HTTP clients (Guzzle), validate URLs, restrict reachable IP addresses, and do not allow connections to private hosts.
Modern Authentication: Passkeys, WebAuthn, and OAuth 2.0
Password-based authentication is the weakest link in web security. The modern WebAuthn (Web Authentication) specification and the Passkey initiative allow completely eliminating passwords, replacing them with public/private key pairs using asymmetric cryptography. OAuth 2.0 remains the standard for delegating authentication to third parties (Google, GitHub).
WebAuthn and Passkeys
WebAuthn is a W3C standard that allows the browser to interact with an authenticator (biometric, USB token, TPM) to generate a key pair. The private key never leaves the device; the public key is registered on the server. The user authenticates simply by touching a sensor or using facial recognition. Passkeys extend this concept by synchronizing keys across devices via a cloud keychain (iCloud, Google Password Manager).
In Laravel, you can implement WebAuthn using packages like Laravel WebAuthn (based on webauthn-lib) or building a custom implementation. The flow requires two endpoints: one to generate a registration challenge (navigator.credentials.create) and one to verify authentication (navigator.credentials.get). The server must store the credential ID and the public key associated with the user.
// Pseudocode for WebAuthn registration
$challenge = random_bytes(32);
$user->webauthn_challenge = $challenge;
$user->save();
// Respond with challenge, rpId (domain), user ID, etc.
// After client-side creation, verify the response
$credential = $this->webauthn->processCreate($clientResponse, $challenge);
$user->credentials()->create([
'credential_id' => $credential->credentialId,
'public_key' => $credential->publicKey,
]);OAuth 2.0 with Laravel Socialite
OAuth 2.0 allows users to log in via external providers without sharing their password. Laravel Socialite simplifies integration with Google, GitHub, Facebook, etc. Security requires using the state parameter to prevent CSRF, validating the ID token (JWT), and verifying the nonce. It is strongly discouraged to use the Implicit Grant flow; prefer Authorization Code Grant with PKCE for mobile apps and SPAs.
Eliminating Passwords: Benefits and Challenges
Adopting Passkeys drastically reduces the risk of phishing, credential stuffing, and password theft. However, it requires the application to handle cross-device synchronization and provide a fallback (e.g., a secondary password or OTP) in case the user loses access to their authenticator. The transition should be gradual: offer Passkey registration in addition to a password, then make it mandatory later.
SQL Injection, XSS, and CSRF in Laravel: Complete Prevention
SQL Injection
Laravel, thanks to Eloquent ORM and the Query Builder, automatically parameterizes queries. Danger arises when using raw expressions (DB::raw()) or concatenating input. Golden rule: never execute unparameterized SQL queries. Always use bindings:
// Correct
DB::select('SELECT * FROM users WHERE id = ?', [$id]);
// Wrong
DB::select("SELECT * FROM users WHERE id = $id");Additionally, validate and filter input: for numeric values, use intval() or Laravel's numeric validation rule.
Cross-Site Scripting (XSS)
XSS allows injection of malicious scripts into pages viewed by other users. In Laravel, the Blade template engine automatically escapes output with double curly braces {{ $var }}. However, if using {!! $var !!} for raw HTML output, make sure the content has been sanitized. Packages like HTML Purifier or Laravel Purifier help clean HTML by allowing only safe tags and attributes. To prevent stored XSS, always validate input content and use Content Security Policy (CSP) headers.
// In Blade: automatic escaping
{{ $comment->body }}
// Raw HTML output: sanitize!
{!! Purifier::clean($comment->body) !!}Cross-Site Request Forgery (CSRF)
CSRF attacks exploit the user's authenticated session to perform unwanted actions. Laravel automatically protects every POST, PUT, DELETE request with a CSRF token. The VerifyCsrfToken middleware is included in the default route. It is important to include the token in forms with the @csrf directive, and for AJAX requests, send the X-CSRF-TOKEN or X-XSRF-TOKEN header. Never disable CSRF for critical routes; if necessary, use exceptions only for external webhooks verified via signature.
// In a Blade form
// For AJAX with Axios
axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content');Security Testing for Laravel
Security testing should be part of the development lifecycle. Tools such as Laravel Dusk for acceptance tests, PHPUnit for unit tests, and static analysis tools like PhpStan with custom rules can catch common vulnerabilities. Additionally, use OWASP ZAP or Burp Suite for penetration testing. Integrate security analysis into CI/CD with SonarQube or CodeQL.
Conclusion and Concrete Next Steps
Cybersecurity for web developers is not optional; it is a fundamental skill. This guide has covered OWASP Top 10 2025 vulnerabilities, modern authentication with Passkeys and WebAuthn, and specific prevention techniques for Laravel. As concrete next steps: update your stack to the latest Laravel version, implement policies and gates for access control, gradually replace passwords with Passkeys, conduct a security audit of your codebase, and integrate automated penetration testing. For further related topics, check out our Definitive Guide to Google Services for Developers (GA4, Search Console, GTM) and our article on the EU AI Act and Digital Privacy for compliance.
Authoritative external links: Official OWASP Top 10 and W3C WebAuthn Specification.
Sponsored Protocol