返回提示词目录第 1297 页

排查并加固Laravel应用安全

检查应用配置、权限、输入处理与暴露接口,修复代码问题并输出风险分级、部署设置和验证结果。

完整提示词

<context>
Most Laravel compromises come from a short list. `APP_DEBUG=true` in production shows the Ignition error page with environment values and has had remote code execution bugs. A leaked `APP_KEY` lets an attacker forge encrypted cookies and signed URLs, and on apps that unserialize cookie payloads it leads to code execution, so a key that was ever committed must be rotated. `$guarded = []` or `Model::unguard()` combined with `$request->all()` lets users set `is_admin` or `tenant_id`. `{!! !!}` in Blade prints raw HTML. Controllers that call `Model::find($id)` without a policy or `authorize()` give object-level access to anyone logged in. Tooling such as Telescope, Horizon, Debugbar, phpMyAdmin or a public `/storage` symlink with private files gets left reachable. Raw queries (`DB::raw`, `whereRaw`) with interpolated input and file uploads stored under `public/` with user-chosen names round it off.
</context>

<task>
Harden this Laravel app: {{app}}
{{#concerns}}Look first at: {{concerns}}{{/concerns}}

1. Read `composer.json` and `composer.lock` for the Laravel and package versions, and run `composer audit` if available.
2. Config: check `.env.example`, `config/app.php` and deployment files for debug mode, `APP_ENV`, session cookie flags (`secure`, `http_only`, `same_site`), trusted proxies and hosts, and whether `.env` or keys are committed (check git history for `APP_KEY`, report by file only).
3. Models: list models with `$guarded = []`, missing `$fillable`, or `unguard()`, and controllers that pass `$request->all()` or `->input()` straight to `create`, `update` or `fill`. Switch them to `$request->validated()` from a Form Request and explicit `$fillable`.
4. Authorization: for every route that takes a model id or route-model binding, confirm a policy, gate or `authorize()` call checks ownership. Add missing policies following the app's pattern.
5. Output and queries: find `{!! !!}`, `DB::raw`, `whereRaw`, `orderByRaw` and `selectRaw` with user input. Escape or sanitise output, and use bindings or allowlisted column names.
6. Routes and tooling: run `php artisan route:list` and flag debug, Telescope, Horizon, log viewer and admin routes without an auth gate; check `TelescopeServiceProvider` gates and that dev packages are in `require-dev` only.
7. Abuse controls: rate limiting on login, password reset, registration and API routes; signed URLs (`signed` middleware) for email links and downloads; uploads validated by MIME and size and stored outside the public disk unless meant to be public.
8. Make the code changes, run the test suite and `php artisan config:cache` locally to catch config errors, and list config that must be set on the server.
</task>

<constraints>
- Never print the value of `APP_KEY`, database passwords or other secrets; name the file and line.
- Do not rotate `APP_KEY` yourself; explain the impact (sessions, encrypted columns, signed URLs) and the steps.
- Keep existing behaviour for legitimate users; list any change users will notice.
- Do not run migrations or commands against production.
{{> guardrails/investigate-before-answering}}
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Findings
Ranked table: severity, area, file:line, impact, fix.
## Changes
One line per file: `path`, what changed.
## Config to set outside the repo
Checklist of environment and server settings with the exact value.
## Verification
Commands run and their actual results.
## Residual risk
What still needs a decision or a server change.
</output_format>

可替换内容

  • {{app}}
  • {{#concerns}}
  • {{concerns}}
  • {{/concerns}}
  • {{> guardrails/investigate-before-answering}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、应用安全、权限校验、代码修复、部署配置

前往 AI 图片创作