Laravel interview question · Most asked

What are the most common security mistakes in Laravel applications?

Summary

Mass assignment from raw input, missing authorization on endpoints, SQL injection through raw queries with interpolated values, XSS through {!! !!}, exposed debug mode or .env, and secrets committed to the repository.

Longer Answer

  • Authorization: route-model binding finds any record; every action needs a policy check.
  • Mass assignment: use validated() data and $fillable.
  • SQL injection: Eloquent and the builder bind values, but whereRaw("name = '$name'"), DB::statement with interpolation and user-controlled column names (orderBy($request->sort)) are injectable. Bind values and allow-list column names.
  • XSS: {{ }} escapes; {!! !!} does not. Only output trusted or sanitised HTML.
  • Configuration: APP_DEBUG=true in production leaks stack traces and environment; the web root must be public/ so .env is never served.
  • Uploads: validate types, store outside the web root or on private disks.
  • Keep Laravel and packages updated (composer audit).

Key Points

  • Authorize every action.
  • Bind values; allow-list sortable columns.
  • {!! !!} only for trusted HTML.
  • APP_DEBUG=false, web root public/, composer audit.

Deep dive: Code Clinic: review a Laravel orders controller

More most-asked Laravel questions

← All Laravel questions