Mitigation Strategy: Eloquent Model Attribute Control ($fillable
/ $guarded
)
-
Description:
- Identify Models: Examine all Eloquent models within the
app/Models
directory (or your custom model location). - Choose Strategy: Decide whether to use
$fillable
(whitelist of allowed attributes) or$guarded
(blacklist of disallowed attributes).$fillable
is generally preferred. - Define Attributes: Within each model class, define either the
$fillable
or$guarded
property as an array. For$fillable
, list every attribute that should be mass-assignable. For$guarded
, list attributes that should not be mass-assignable. Never leave both undefined. - Review Controller Logic: Ensure controllers interacting with these models do not use
request()->all()
directly withModel::create()
orModel::update()
. - Safe Data Handling: Use
request()->only(['field1', 'field2', ...])
or manually assign attributes after validation. - Form Requests (Optional but Framework-Specific): Utilize Laravel's Form Request classes for complex validation and data handling before it reaches the model.
- Identify Models: Examine all Eloquent models within the
-
Threats Mitigated:
- Mass Assignment: (Severity: High) - Attackers inject data into unexpected database columns.
- Data Tampering: (Severity: Medium) - Attackers modify existing data in unintended ways.
-
Impact:
- Mass Assignment: Risk reduced from High to Low.
- Data Tampering: Risk reduced from Medium to Low.
-
Currently Implemented:
app/Models/User.php
:$fillable
defined.app/Http/Controllers/UserController.php
: Usesrequest()->only()
.
-
Missing Implementation:
app/Models/Product.php
: Neither$fillable
nor$guarded
is defined.app/Http/Controllers/ProductController.php
: UsesProduct::create(request()->all())
.
Mitigation Strategy: CSRF Protection Enforcement (Using Laravel's Middleware and Directives)
-
Description:
- Verify Middleware: Confirm the
VerifyCsrfToken
middleware is enabled in theweb
middleware group withinapp/Http/Kernel.php
. - Blade Forms: Use the
@csrf
Blade directive inside all<form>
tags in your.blade.php
files. - AJAX Requests: Include the CSRF token (obtained from
<meta name="csrf-token" content="{{ csrf_token() }}">
) in theX-CSRF-TOKEN
header for AJAX requests. - API Routes (Sanctum/Passport): Use Laravel Sanctum or Passport for API authentication, which handles CSRF protection for API routes. Do not use the
web
middleware group for API security. - Exemptions (Rare & Framework-Specific): If disabling CSRF protection for specific routes (using
$except
inVerifyCsrfToken
), document the reason clearly.
- Verify Middleware: Confirm the
-
Threats Mitigated:
- Cross-Site Request Forgery (CSRF): (Severity: High)
-
Impact:
- CSRF: Risk reduced from High to Low.
-
Currently Implemented:
app/Http/Kernel.php
:VerifyCsrfToken
middleware enabled.- Blade forms include
@csrf
. - AJAX requests include
X-CSRF-TOKEN
header.
-
Missing Implementation:
- API routes currently use the
web
middleware group. Needs to switch to Laravel Sanctum.
- API routes currently use the
Mitigation Strategy: Secure Session Configuration (Using Laravel's config/session.php
)
-
Description:
- Session Driver: In
config/session.php
, choose a secure driver (database
,redis
, ormemcached
are recommended for production). - Lifetime: Set an appropriate session
lifetime
inconfig/session.php
. - Cookie Settings: Ensure
http_only
andsecure
are set totrue
inconfig/session.php
. - Encryption: Verify session encryption is enabled (default). Ensure a strong
APP_KEY
is set in.env
. - Regeneration (Framework Method): After login, call
request()->session()->regenerate()
. - Invalidation (Framework Method): On logout, call
request()->session()->invalidate()
.
- Session Driver: In
-
Threats Mitigated:
- Session Hijacking: (Severity: High)
- Session Fixation: (Severity: High)
- Session Data Exposure: (Severity: Medium)
-
Impact:
- Session Hijacking: Risk reduced from High to Low.
- Session Fixation: Risk reduced from High to Low.
- Session Data Exposure: Risk reduced from Medium to Low.
-
Currently Implemented:
config/session.php
: Secure settings configured.- Login/Logout controllers: Use
regenerate()
andinvalidate()
.
-
Missing Implementation:
- None.
Mitigation Strategy: Secure Route Model Binding (Using Laravel's Route Definitions and Scopes)
-
Description:
- Review Routes: Examine routes in
routes/web.php
androutes/api.php
using route model binding. - Soft Deletes: If models use soft deletes, be cautious. Use global scopes or explicit binding with closures to exclude them if needed.
- Explicit Binding (Custom Keys): Use explicit binding with custom keys:
Route::get('/users/{user:uuid}', ...)
- Scopes (Framework Feature): Use route model binding scopes to restrict queries (e.g.,
Route::model('user', User::class)->scope('active');
). - Validation: Validate the resolved model in your controller or Form Request.
- Review Routes: Examine routes in
-
Threats Mitigated:
- Unauthorized Access to Resources: (Severity: Medium)
- Exposure of Soft-Deleted Data: (Severity: Medium)
-
Impact:
- Unauthorized Access: Risk reduced from Medium to Low.
- Soft-Deleted Data Exposure: Risk reduced from Medium to Low.
-
Currently Implemented:
routes/web.php
: Uses explicit binding.- Controllers validate resolved models.
-
Missing Implementation:
app/Models/Post.php
: Uses soft deletes without proper handling in route binding.
Mitigation Strategy: Prevent Debugging Information Leaks (Using Laravel's Configuration and Tools)
-
Description:
APP_DEBUG
: SetAPP_DEBUG=false
in your.env
file for production.- Debugging Tools: Disable or restrict access to Laravel Telescope and Laravel Debugbar in production.
- Logging: Configure
config/logging.php
with appropriate log levels for production (e.g.,error
). - Remove Debugging Code: Remove
dd()
,dump()
, etc., from production code.
-
Threats Mitigated:
- Information Disclosure: (Severity: High)
-
Impact:
- Information Disclosure: Risk reduced from High to Low.
-
Currently Implemented:
.env
(production):APP_DEBUG=false
.- Telescope/Debugbar disabled in production.
config/logging.php
: Log level set toerror
.
-
Missing Implementation:
- None.
Mitigation Strategy: Validate Redirects and Forwards (Using Laravel's redirect()
and route()
Helpers)
-
Description:
- Avoid User Input: Do not directly use user input in
redirect()
orroute()
calls. - Named Routes (Framework Feature): Use named routes (e.g.,
return redirect()->route('home');
). - Whitelist: If using user input, validate it against a whitelist.
intended()
(Framework Method): Usereturn redirect()->intended('/');
after authentication.
- Avoid User Input: Do not directly use user input in
-
Threats Mitigated:
- Open Redirect: (Severity: Medium)
-
Impact:
- Open Redirect: Risk reduced from Medium to Low.
-
Currently Implemented:
- Named routes used extensively.
intended()
used after login.
-
Missing Implementation:
- One controller method uses
redirect($request->input('return_url'))
without validation.
- One controller method uses
Mitigation Strategy: Secure Configuration and Secrets (Leveraging Laravel's Configuration System)
-
Description:
.env
Exclusion:.env
file must not be in version control.- Environment Variables: Use environment variables on the server.
- Configuration Caching (Framework Command): Run
php artisan config:cache
in production. Clear withphp artisan config:clear
after changes. - File Permissions: Restrict access to
.env
and configuration files. - **Secrets Management (Consider external service, but configuration is within Laravel).
-
Threats Mitigated:
- Exposure of Sensitive Configuration: (Severity: High)
-
Impact:
- Exposure of Sensitive Configuration: Risk reduced from High to Low.
-
Currently Implemented:
.env
excluded from version control.- Environment variables used.
- Configuration caching enabled.
- File permissions set correctly.
-
Missing Implementation:
- Not currently using a dedicated secrets management service.