Skip to content

Latest commit

 

History

History
169 lines (126 loc) · 9.47 KB

File metadata and controls

169 lines (126 loc) · 9.47 KB

Mitigation Strategies Analysis for laravel/framework

  • Description:

    1. Identify Models: Examine all Eloquent models within the app/Models directory (or your custom model location).
    2. Choose Strategy: Decide whether to use $fillable (whitelist of allowed attributes) or $guarded (blacklist of disallowed attributes). $fillable is generally preferred.
    3. 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.
    4. Review Controller Logic: Ensure controllers interacting with these models do not use request()->all() directly with Model::create() or Model::update().
    5. Safe Data Handling: Use request()->only(['field1', 'field2', ...]) or manually assign attributes after validation.
    6. Form Requests (Optional but Framework-Specific): Utilize Laravel's Form Request classes for complex validation and data handling before it reaches the model.
  • 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: Uses request()->only().
  • Missing Implementation:

    • app/Models/Product.php: Neither $fillable nor $guarded is defined.
    • app/Http/Controllers/ProductController.php: Uses Product::create(request()->all()).
  • Description:

    1. Verify Middleware: Confirm the VerifyCsrfToken middleware is enabled in the web middleware group within app/Http/Kernel.php.
    2. Blade Forms: Use the @csrf Blade directive inside all <form> tags in your .blade.php files.
    3. AJAX Requests: Include the CSRF token (obtained from <meta name="csrf-token" content="{{ csrf_token() }}">) in the X-CSRF-TOKEN header for AJAX requests.
    4. 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.
    5. Exemptions (Rare & Framework-Specific): If disabling CSRF protection for specific routes (using $except in VerifyCsrfToken), document the reason clearly.
  • 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.
  • Description:

    1. Session Driver: In config/session.php, choose a secure driver (database, redis, or memcached are recommended for production).
    2. Lifetime: Set an appropriate session lifetime in config/session.php.
    3. Cookie Settings: Ensure http_only and secure are set to true in config/session.php.
    4. Encryption: Verify session encryption is enabled (default). Ensure a strong APP_KEY is set in .env.
    5. Regeneration (Framework Method): After login, call request()->session()->regenerate().
    6. Invalidation (Framework Method): On logout, call request()->session()->invalidate().
  • 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() and invalidate().
  • Missing Implementation:

    • None.
  • Description:

    1. Review Routes: Examine routes in routes/web.php and routes/api.php using route model binding.
    2. Soft Deletes: If models use soft deletes, be cautious. Use global scopes or explicit binding with closures to exclude them if needed.
    3. Explicit Binding (Custom Keys): Use explicit binding with custom keys: Route::get('/users/{user:uuid}', ...)
    4. Scopes (Framework Feature): Use route model binding scopes to restrict queries (e.g., Route::model('user', User::class)->scope('active');).
    5. Validation: Validate the resolved model in your controller or Form Request.
  • 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.
  • Description:

    1. APP_DEBUG: Set APP_DEBUG=false in your .env file for production.
    2. Debugging Tools: Disable or restrict access to Laravel Telescope and Laravel Debugbar in production.
    3. Logging: Configure config/logging.php with appropriate log levels for production (e.g., error).
    4. 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 to error.
  • Missing Implementation:

    • None.
  • Description:

    1. Avoid User Input: Do not directly use user input in redirect() or route() calls.
    2. Named Routes (Framework Feature): Use named routes (e.g., return redirect()->route('home');).
    3. Whitelist: If using user input, validate it against a whitelist.
    4. intended() (Framework Method): Use return redirect()->intended('/'); after authentication.
  • 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.
  • Description:

    1. .env Exclusion: .env file must not be in version control.
    2. Environment Variables: Use environment variables on the server.
    3. Configuration Caching (Framework Command): Run php artisan config:cache in production. Clear with php artisan config:clear after changes.
    4. File Permissions: Restrict access to .env and configuration files.
    5. **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.