affaan-m/ECC/docs/ja-JP/skills/laravel-security/SKILL.md
laravel-security
Use it for data analysis and engineering tasks; the detail page covers purpose, installation, and practical steps.
- Source repository stars
- 234,327
- Declared platforms
- 0
- Static risk flags
- 1
- Last source update
- 2026-07-27
- Source checked
- 2026-07-28
Decision brief
What it does—and where it fits
Laravel アプリケーションを一般的な脆弱性から守るための包括的なセキュリティガイダンス。
Not for
- Tasks that require unconfirmed production actions or broad system permissions.
- Environments where the pinned source and install steps cannot be inspected.
Compatibility matrix
Platform support, with evidence labels
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
Inspect first. Install second.
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/affaan-m/ECC --skill "docs/ja-JP/skills/laravel-security"Inspect the Agent Skill "laravel-security" from https://github.com/affaan-m/ECC/blob/4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38/docs/ja-JP/skills/laravel-security/SKILL.md at commit 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
What the source asks the agent to do
- 01
アクティベートする時機
認証または認可を追加する場合
認証または認可を追加する場合ユーザー入力とファイルアップロードを処理する場合新しい API エンドポイントを構築する場合 - 02
仕組み
ミドルウェアは基本的な保護を提供(CSRF は VerifyCsrfToken 経由、セキュリティヘッダーは SecurityHeaders 経由)
ミドルウェアは基本的な保護を提供(CSRF は VerifyCsrfToken 経由、セキュリティヘッダーは SecurityHeaders 経由)ガードとポリシーがアクセス制御を実施(auth:sanctum、$this-authorize、ポリシーミドルウェア)フォームリクエストが入力を検証し形成(UploadInvoiceRequest)サービスに到達する前に - 03
コアセキュリティ設定
APPDEBUG=false を本番環境で設定
APPDEBUG=false を本番環境で設定APPKEY をセットして、漏洩時にはローテーション必須SESSIONSECURECOOKIE=true と SESSIONSAMESITE=lax(または機密アプリケーションは strict)を設定 - 04
セッションとクッキーの強化
SESSIONHTTPONLY=true を設定して JavaScript アクセスを防止
SESSIONHTTPONLY=true を設定して JavaScript アクセスを防止高リスクフローに対して SESSIONSAMESITE=strict を使用ログイン時と権限変更時にセッションを再生成
Permission review
Static risk signals and limitations
Network access
The documentation includes network, browsing, or remote request actions.
'allowed_origins' => ['https://app.example.com'],Evidence record
Why each signal appears
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 77/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 234,327 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Provenance and original SKILL.md
- Repository
- affaan-m/ECC
- Skill path
- docs/ja-JP/skills/laravel-security/SKILL.md
- Commit
- 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38
- License
- MIT
- Collected
- 2026-07-28
- Default branch
- main
View the original SKILL.md
Laravel セキュリティベストプラクティス
Laravel アプリケーションを一般的な脆弱性から守るための包括的なセキュリティガイダンス。
アクティベートする時機
- 認証または認可を追加する場合
- ユーザー入力とファイルアップロードを処理する場合
- 新しい API エンドポイントを構築する場合
- シークレットと環境設定を管理する場合
- 本番環境デプロイメントを強化する場合
仕組み
- ミドルウェアは基本的な保護を提供(CSRF は
VerifyCsrfToken経由、セキュリティヘッダーはSecurityHeaders経由) - ガードとポリシーがアクセス制御を実施(
auth:sanctum、$this->authorize、ポリシーミドルウェア) - フォームリクエストが入力を検証し形成(
UploadInvoiceRequest)サービスに到達する前に - レート制限が不正使用保護を追加(
RateLimiter::for('login'))認証制御と並行して - データの安全性は暗号化されたキャスト、一括割当ガード、署名付きルート(
URL::temporarySignedRoute+signedミドルウェア)から来ます
コアセキュリティ設定
APP_DEBUG=falseを本番環境で設定APP_KEYをセットして、漏洩時にはローテーション必須SESSION_SECURE_COOKIE=trueとSESSION_SAME_SITE=lax(または機密アプリケーションはstrict)を設定- 正しい HTTPS 検出のため、信頼できるプロキシを設定
セッションとクッキーの強化
SESSION_HTTP_ONLY=trueを設定して JavaScript アクセスを防止- 高リスクフローに対して
SESSION_SAME_SITE=strictを使用 - ログイン時と権限変更時にセッションを再生成
認証とトークン
- Laravel Sanctum または Passport を API 認証に使用
- 機密データの場合、有効期限の短いトークンとリフレッシュフローを優先
- ログアウトと侵害されたアカウントでトークンを無効化
ルート保護例:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->get('/me', function (Request $request) {
return $request->user();
});
パスワードセキュリティ
Hash::make()でパスワードをハッシュし、平文で保存しない- パスワードリセットフロー用に Laravel のパスワードブローカーを使用
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
$validated = $request->validate([
'password' => ['required', 'string', Password::min(12)->letters()->mixedCase()->numbers()->symbols()],
]);
$user->update(['password' => Hash::make($validated['password'])]);
認可:ポリシーとゲート
- モデルレベルの認可にはポリシーを使用
- コントローラーとサービスで認可を実施
$this->authorize('update', $project);
ルートレベルの実施にはポリシーミドルウェアを使用:
use Illuminate\Support\Facades\Route;
Route::put('/projects/{project}', [ProjectController::class, 'update'])
->middleware(['auth:sanctum', 'can:update,project']);
バリデーションとデータサニタイゼーション
- フォームリクエストで常にユーザー入力をバリデーション
- 厳密なバリデーションルールと型チェックを使用
- リクエストペイロードを派生フィールドに信頼しない
一括割当保護
$fillableまたは$guardedを使用して、Model::unguard()は回避- DTO またはかば詰明示的な属性マッピングを優先
SQL インジェクション防止
- Eloquent またはクエリビルダーのパラメータバインディングを使用
- 厳密に必要でない限り生 SQL を回避
DB::select('select * from users where email = ?', [$email]);
XSS 防止
- Blade は標準で出力をエスケープ(
{{ }}) {!! !!}は信頼できる、サニタイズされた HTML にのみ使用- リッチテキストを専用ライブラリでサニタイズ
CSRF 保護
VerifyCsrfTokenミドルウェアを有効に保つ- フォームに
@csrfを含めて、SPA リクエストで XSRF トークンを送信
SPA 認証(Sanctum)の場合、ステートフルなリクエストが設定されていることを確認:
// config/sanctum.php
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost')),
ファイルアップロード安全性
- ファイルサイズ、MIME タイプ、拡張子をバリデーション
- 可能な場合、公開パスの外にアップロードを保存
- 必要に応じてファイルをマルウェアスキャン
final class UploadInvoiceRequest extends FormRequest
{
public function authorize(): bool
{
return (bool) $this->user()?->can('upload-invoice');
}
public function rules(): array
{
return [
'invoice' => ['required', 'file', 'mimes:pdf', 'max:5120'],
];
}
}
$path = $request->file('invoice')->store(
'invoices',
config('filesystems.private_disk', 'local') // set this to a non-public disk
);
レート制限
- 認証とライトエンドポイントに
throttleミドルウェアを適用 - ログイン、パスワードリセット、OTP にはより厳しい制限を使用
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('login', function (Request $request) {
return [
Limit::perMinute(5)->by($request->ip()),
Limit::perMinute(5)->by(strtolower((string) $request->input('email'))),
];
});
シークレットと認証情報
- シークレットをソースコントロールにコミットしない
- 環境変数とシークレットマネージャーを使用
- 公開後はキーをローテーション、セッションを無効化
暗号化された属性
保存中のシックレット列には暗号化されたキャストを使用。
protected $casts = [
'api_token' => 'encrypted',
];
セキュリティヘッダー
- 必要に応じて CSP、HSTS、フレーム保護を追加
- HTTPS リダイレクトを実施するために信頼できるプロキシ設定を使用
ヘッダーを設定するためのミドルウェア例:
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
final class SecurityHeaders
{
public function handle(Request $request, \Closure $next): Response
{
$response = $next($request);
$response->headers->add([
'Content-Security-Policy' => "default-src 'self'",
'Strict-Transport-Security' => 'max-age=31536000', // add includeSubDomains/preload only when all subdomains are HTTPS
'X-Frame-Options' => 'DENY',
'X-Content-Type-Options' => 'nosniff',
'Referrer-Policy' => 'no-referrer',
]);
return $response;
}
}
CORS と API 公開
config/cors.phpでオリジンを制限- 認証済みルートではワイルドカードオリジンを回避
// config/cors.php
return [
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
'allowed_origins' => ['https://app.example.com'],
'allowed_headers' => [
'Content-Type',
'Authorization',
'X-Requested-With',
'X-XSRF-TOKEN',
'X-CSRF-TOKEN',
],
'supports_credentials' => true,
];
ログと個人情報
- パスワード、トークン、フルカードデータをログに記録しない
- 構造化ログで機密フィールドをマスク
use Illuminate\Support\Facades\Log;
Log::info('User updated profile', [
'user_id' => $user->id,
'email' => '[REDACTED]',
'token' => '[REDACTED]',
]);
依存関係セキュリティ
composer auditを定期的に実行- 依存関係をケアをもって固定し、CVE で迅速にアップデート
署名付き URL
一時的な改ざん防止リンクに署名付きルートを使用。
use Illuminate\Support\Facades\URL;
$url = URL::temporarySignedRoute(
'downloads.invoice',
now()->addMinutes(15),
['invoice' => $invoice->id]
);
use Illuminate\Support\Facades\Route;
Route::get('/invoices/{invoice}/download', [InvoiceController::class, 'download'])
->name('downloads.invoice')
->middleware('signed');
Alternatives
Compare before choosing
affaan-m/ECC
laravel-security
Laravel security best practices — authentication, authorization, Eloquent safety, CSRF, XSS prevention, API security, and secure deployment configurations.
affaan-m/ECC
laravel-security
Buenas prácticas de seguridad en Laravel para autenticación/autorización, validación, CSRF, asignación masiva, subida de archivos, secretos, limitación de velocidad y despliegue seguro.
affaan-m/ECC
laravel-security
Laravel security best practices for authn/authz, validation, CSRF, mass assignment, file uploads, secrets, rate limiting, and secure deployment.
affaan-m/ECC
laravel-security
Use it for data analysis and engineering tasks; the detail page covers purpose, installation, and practical steps.