Security, OWASP & Hardening Interview Questions (PHP & Laravel)
10 Security, OWASP & Hardening questions from the PHP & Laravel track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
How does CSRF protection work in Laravel, what causes a 419 Page Expired error, and how do you fix it?
Laravel generates a unique CSRF token per session and checks it on every POST/PUT/DELETE request; status 419 means the session expired or the form did not include the token.
Read the full explanation - Junior
What is Mass Assignment, and how do $fillable and $guarded differ in Eloquent?
It occurs when a developer passes $request->all() directly to create(), allowing users to change sensitive fields such as is_admin; $fillable prevents this by restricting updates to an allowlist.
Read the full explanation - Junior
How does Laravel hash passwords with the Hash Facade?
By default, it uses bcrypt (or Argon2), adds a Salt, and creates secure, slow hashes with Hash::make(); verify them with Hash::check().
Read the full explanation - Mid-level
How do Gates and Policies differ in Laravel authorization?
Gates are defined for general actions unrelated to a specific model (such as accessing an admin dashboard), while Policies organize permissions around a model (such as PostPolicy).
Read the full explanation - Mid-level
How do Eloquent and Query Builder protect Laravel applications from SQL Injection?
Standard methods such as where and find automatically use PDO Prepared Statements, treating user input as values rather than executable code.
Read the full explanation - Junior
How does Blade protect against XSS, and what is the difference between {{ $data }} and {!! $data !!}?
{{ $data }} automatically passes text through htmlspecialchars() to prevent malicious scripts from running, while {!! $data !!} outputs raw text without protection.
Read the full explanation - Mid-level
What are the strict security rules for uploading and storing files in Laravel?
Verify the actual MIME type, block executable extensions (.php, .sh), generate random filenames, and store files outside the public directory or in S3.
Read the full explanation - Mid-level
What is the role of APP_KEY in Laravel, and what are the risks of changing or exposing it in production?
It is the primary encryption key (AES-256) for cookies, sessions, and encrypted fields; exposing it allows data to be decrypted or forged, while changing it prevents old data from being decrypted.
Read the full explanation - Mid-level
What are Signed URLs in Laravel, and when are they used to protect sensitive operations?
They contain a digital signature (HMAC Hash) that prevents parameter tampering and can have an expiration time; use them for email verification and account recovery.
Read the full explanation - Senior
How do you implement a Content Security Policy with a Nonce in Laravel applications?
Generate a unique random Nonce for each HTTP request, include it in the CSP header and in <script nonce="..."> tags to block injected scripts.
Read the full explanation