Update dependencies
Composer: Laravel 13.43, Octane 2.25, Fortify 1.43 and Pest 5.3.7, with the packages they bring (70 in all). This fixes the advisories in Laravel and the Symfony components. npm: Vite 8.3.8 with Rolldown 1.2.19, Playwright 1.65.1 and chokidar 6. The asset build, CI and the dev container use Node.js 26. The dev image also has git for Composer. Both audits are clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Security Best Practices
|
||||
# Security best practices
|
||||
|
||||
## Control Mass Assignment
|
||||
## Control mass assignment
|
||||
|
||||
Define `$fillable` when a model is populated from request-derived arrays, or deliberately guard attributes by another consistent model convention. Laravel models guard all attributes by default; `$guarded = []` opts out of that protection.
|
||||
Define `$fillable` when a model is populated from request-derived arrays, or deliberately guard attributes by another consistent model convention. Laravel models guard all attributes by default. `$guarded = []` opts out of that protection.
|
||||
|
||||
```php
|
||||
class User extends Model
|
||||
@@ -15,9 +15,9 @@ class User extends Model
|
||||
}
|
||||
```
|
||||
|
||||
Do not pass untrusted request data to a model with `$guarded = []`. Mass-assignment protection controls which attributes `create()`, `fill()`, and `update()` may set; it does not validate values or authorize the operation.
|
||||
Do not pass untrusted request data to a model with `$guarded = []`. Mass-assignment protection controls which attributes `create()`, `fill()`, and `update()` may set. It does not validate values or authorize the operation.
|
||||
|
||||
## Authorize Protected Actions
|
||||
## Authorize protected actions
|
||||
|
||||
Use policies, gates, or form request authorization for actions that depend on the current user's permissions. Authentication alone does not establish permission, and validation is not authorization.
|
||||
|
||||
@@ -43,9 +43,9 @@ public function authorize(): bool
|
||||
|
||||
Public actions intentionally available to everyone do not need a redundant authorization check.
|
||||
|
||||
## Bind Query Parameters
|
||||
## Bind query parameters
|
||||
|
||||
Use Eloquent, the query builder, or explicit bindings instead of interpolating untrusted values into Structured Query Language (SQL). Bindings protect values, not identifiers such as column names or sort directions; map user-selected identifiers to an allow-list.
|
||||
Use Eloquent, the query builder, or explicit bindings instead of interpolating untrusted values into Structured Query Language (SQL). Bindings protect values, not identifiers such as column names or sort directions. Map user-selected identifiers to an allow-list.
|
||||
|
||||
Incorrect:
|
||||
|
||||
@@ -60,9 +60,9 @@ User::where('name', $request->name)->get();
|
||||
User::whereRaw('LOWER(name) = ?', [$request->string('name')->lower()->toString()])->get();
|
||||
```
|
||||
|
||||
## Escape Output in Its Context
|
||||
## Escape output in its context
|
||||
|
||||
Blade's `{{ }}` syntax HTML-escapes output. Use `{!! !!}` only for content that has been sanitized for the exact HTML context in which it is rendered. Escaping rules differ for HTML, URLs, JavaScript, and Cascading Style Sheets.
|
||||
Blade's `{{ }}` syntax HTML-escapes output. Use `{!! !!}` only for content sanitized for the exact HTML context where it renders. Escaping rules differ for HTML, URLs, JavaScript, and Cascading Style Sheets.
|
||||
|
||||
Incorrect for untrusted content:
|
||||
|
||||
@@ -76,7 +76,7 @@ Correct:
|
||||
{{ $user->bio }}
|
||||
```
|
||||
|
||||
## Apply Cross-Site Request Forgery Protection
|
||||
## Apply cross-site request forgery protection
|
||||
|
||||
Include `@csrf` in state-changing Blade forms handled by Laravel's `web` middleware. Routes intentionally excluded from cross-site request forgery (CSRF) verification, such as validated third-party webhooks, need their own authenticity check.
|
||||
|
||||
@@ -87,11 +87,11 @@ Include `@csrf` in state-changing Blade forms handled by Laravel's `web` middlew
|
||||
</form>
|
||||
```
|
||||
|
||||
Inertia applications commonly use Axios, which returns the encrypted `XSRF-TOKEN` cookie in the `X-XSRF-TOKEN` header. Confirm equivalent configuration when using another HTTP client. Do not disable CSRF protection merely to fix a token mismatch.
|
||||
Inertia applications commonly use Axios, which returns the encrypted `XSRF-TOKEN` cookie in the `X-XSRF-TOKEN` header. When you use another HTTP client, confirm equivalent configuration. Do not disable CSRF protection only to fix a token mismatch.
|
||||
|
||||
## Rate Limit Sensitive Endpoints
|
||||
## Rate limit sensitive endpoints
|
||||
|
||||
Apply suitable rate limits to login attempts, password recovery, verification messages, and expensive or abuse-prone application programming interface (API) routes. Choose the limiter key deliberately; an Internet Protocol (IP) address alone can unfairly group users behind a shared network, while an account identifier alone can enable targeted denial of service.
|
||||
Apply suitable rate limits to login attempts, password recovery, verification messages, and expensive or abuse-prone application programming interface (API) routes. Choose the limiter key deliberately. An Internet Protocol (IP) address alone can unfairly group users behind a shared network. An account identifier alone can enable targeted denial of service.
|
||||
|
||||
```php
|
||||
RateLimiter::for('login', function (Request $request) {
|
||||
@@ -103,11 +103,11 @@ RateLimiter::for('login', function (Request $request) {
|
||||
Route::post('/login', LoginController::class)->middleware('throttle:login');
|
||||
```
|
||||
|
||||
Rate limiting reduces abuse; it does not replace authentication, authorization, or upstream denial-of-service protection.
|
||||
Rate limiting reduces abuse. It does not replace authentication, authorization, or upstream denial-of-service protection.
|
||||
|
||||
## Validate and Store Uploads Safely
|
||||
## Validate and store uploads safely
|
||||
|
||||
Validate expected content type, dimensions where relevant, and size. Laravel's `mimes` rule reads the file contents and guesses a Multipurpose Internet Mail Extensions (MIME) type corresponding to the listed extensions; it does not validate the user-assigned filename extension. The `extensions` rule checks that extension and should not be used by itself.
|
||||
Validate the expected content type, the size, and the dimensions where relevant. Laravel's `mimes` rule reads the file contents and guesses a Multipurpose Internet Mail Extensions (MIME) type corresponding to the listed extensions. It does not validate the user-assigned filename extension. The `extensions` rule checks that extension. Do not use it by itself.
|
||||
|
||||
```php
|
||||
public function rules(): array
|
||||
@@ -124,11 +124,11 @@ Use Laravel's storage methods to generate a filename, and store untrusted files
|
||||
$path = $request->file('avatar')->store('avatars');
|
||||
```
|
||||
|
||||
## Keep Secrets Out of Application Code
|
||||
## Keep secrets out of application code
|
||||
|
||||
Do not commit populated environment files or hard-code credentials. Read environment variables in configuration files, then use `config()` in application code so configuration caching works correctly. See the configuration rules for encrypted environment files and external secret stores.
|
||||
Do not commit populated environment files or hard-code credentials. Read environment variables in configuration files, then use `config()` in application code so configuration caching works. See the configuration rules for encrypted environment files and external secret stores.
|
||||
|
||||
## Audit Dependencies
|
||||
## Audit dependencies
|
||||
|
||||
Run `composer audit` regularly and in continuous integration. Review findings for exploitability and update or mitigate affected packages promptly.
|
||||
|
||||
@@ -136,9 +136,9 @@ Run `composer audit` regularly and in continuous integration. Review findings fo
|
||||
composer audit
|
||||
```
|
||||
|
||||
## Encrypt Sensitive Attributes When Appropriate
|
||||
## Encrypt sensitive attributes when appropriate
|
||||
|
||||
Use an `encrypted` cast for sensitive values that must be recoverable, and use `$hidden` to omit them from array and JavaScript Object Notation (JSON) serialization. Hidden attributes remain accessible in PHP, and encryption does not replace access control. Encrypted values cannot be meaningfully queried and should use a `TEXT` or larger column because ciphertext length is variable.
|
||||
Use an `encrypted` cast for sensitive values that must be recoverable, and use `$hidden` to omit them from array and JavaScript Object Notation (JSON) serialization. Hidden attributes remain accessible in PHP, and encryption does not replace access control. You cannot meaningfully query encrypted values. Store them in a `TEXT` or larger column because ciphertext length varies.
|
||||
|
||||
```php
|
||||
class Integration extends Model
|
||||
|
||||
Reference in New Issue
Block a user