check-mass-assignment
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "check-mass-assignment":https://skillpi.com/zh/skills/deepskill-eb51498dd65d7662ec53b1c9a0bedba2b099c5ee0dca5aa3e64a3a8c813b3463。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
检测批量赋值漏洞。识别未受保护的模型填充、使用 Request::all() 进行创建或更新、缺少 $fillable/$guarded 定义,以及未对白名单参数进行过滤的绑定操作。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: check-mass-assignment
description: Detects mass assignment vulnerabilities. Identifies unguarded model filling, Request::all() to create/update, missing $fillable/$guarded, and parameter binding without whitelisting.Mass Assignment Security Check (A01:2021)
Analyze PHP code for mass assignment vulnerabilities where user input directly populates model attributes.
Detection Patterns
1. Request::all() Passed to Create/Update
// CRITICAL: All request data used to create model
class UserController
{
public function store(Request $request): Response
{
$user = User::create($request->all());
// Attacker can set: is_admin=true, role=superadmin, balance=999999
return new Response($user);
}
}
// CRITICAL: All input to update
class ProfileController
{
public function update(Request $request, int $id): Response
{
$user = User::findOrFail($id);
$user->update($request->all());
// Attacker modifies fields not in the form
}
}
// CORRECT: Whitelist specific fields
class UserController
{
public function store(Request $request): Response
{
$user = User::create($request->only(['name', 'email', 'password']));
return new Response($user);
}
}
2. Missing $fillable or $guarded (Laravel)
// CRITICAL: No mass assignment protection
class User extends Model
{
// No $fillable defined — all fields assignable!
// No $guarded defined — nothing protected!
}
// VULNERABLE: Empty guarded (allows everything)
class User extends Model
{
protected $guarded = []; // Disables ALL protection!
}
// CORRECT: Explicit fillable
class User extends Model
{
protected $fillable = ['name', 'email', 'password'];
// is_admin, role, etc. are NOT fillable
}
3. Array Spread / Merge Into Entity
// CRITICAL: Unfiltered array to entity constructor
class CreateUserUseCase
{
public function execute(array $data): User
{
return new User(...$data); // Any key becomes a constructor argument!
}
}
// CRITICAL: Array merge with user input
class UpdateHandler
{
public function handle(UpdateCommand $command): void
{
$entity = $this->repo->find($command->id());
$merged = array_merge($entity->toArray(), $command->data());
// User-supplied data overrides ALL fields
$this->repo->save(User::fromArray($merged));
}
}
// CORRECT: Explicit mapping
class CreateUserUseCase
{
public function execute(CreateUserCommand $command): User
{
return new User(
name: $command->name(),
email: $command->email(),
// Only mapped fields, no mass assignment
);
}
}
4. Doctrine Entity Public Setters
// VULNERABLE: All setters exposed, bulk update possible
class User
{
public function setRole(string $role): void { $this->role = $role; }
public function setIsAdmin(bool $isAdmin): void { $this->isAdmin = $isAdmin; }
public function setBalance(int $balance): void { $this->balance = $balance; }
}
// Combined with:
foreach ($request->all() as $key => $value) {
$setter = 'set' . ucfirst($key);
if (method_exists($user, $setter)) {
$user->$setter($value); // Mass assignment via reflection!
}
}
5. API Resource Without Field Filtering
// VULNERABLE: PATCH endpoint accepts any field
class UserApiController
{
public function patch(Request $request, int $id): Response
{
$user = $this->repo->find($id);
$data = json_decode($request->getContent(), true);
foreach ($data as $field => $value) {
$user->{'set' . ucfirst($field)}($value); // Any field!
}
}
}
// CORRECT: Explicit allowed fields for PATCH
class UserApiController
{
private const array PATCHABLE_FIELDS = ['name', 'email', 'phone'];
public function patch(Request $request, int $id): Response
{
$user = $this->repo->find($id);
$data = json_decode($request->getContent(), true);
foreach ($data as $field => $value) {
if (!in_array($field, self::PATCHABLE_FIELDS, true)) {
throw new BadRequestException("Field '$field' is not modifiable");
}
}
}
}
Grep Patterns
# Request::all() to create/update
Grep: "::create\(\\\$request->all\(\)\)|->update\(\\\$request->all\(\)\)" --glob "**/*.php"
Grep: "request->all\(\)" --glob "**/*Controller*.php"
# Missing fillable/guarded (Laravel)
Grep: "extends Model" --glob "**/*.php"
Grep: "\\\$fillable|\\\$guarded" --glob "**/*.php"
# Empty guarded
Grep: "\\\$guarded = \[\]" --glob "**/*.php"
# Array spread to constructor
Grep: "new.*\(\.\.\.\\\$" --glob "**/*.php"
# Dynamic setters
Grep: "->.*\\\$.*\(|method_exists.*set" --glob "**/*.php"
# array_merge with user input
Grep: "array_merge\(.*request|array_merge\(.*\\\$data" --glob "**/*.php"
Severity Classification
| Pattern | Severity |
|---|---|
| Request::all() to create/update | 🔴 Critical |
| Empty $guarded = [] | 🔴 Critical |
| Dynamic setters from user input | 🔴 Critical |
| Missing $fillable on Model | 🟠 Major |
| Array spread from unvalidated input | 🟠 Major |
| No field whitelist on PATCH | 🟡 Minor |
Output Format
### Mass Assignment: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**CWE:** CWE-915 (Improperly Controlled Modification of Dynamically-Determined Object Attributes)
**OWASP:** A01:2021 — Broken Access Control
**Issue:**
[Description of the mass assignment vulnerability]
**Attack Vector:**
Attacker adds `is_admin=true` to request body, gaining admin privileges.
**Code:**
```php
// Vulnerable code
Fix:
// With explicit field whitelisting
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 针对 PHP 开发中常见的安全漏洞(批量赋值)提供检测能力
- 属于明确场景的通用工具,具有广泛受众(PHP/Laravel 开发者)
亮点
- description 明确描述了检测目标,覆盖多种变体,边界清晰
亮点
- 文档结构清晰,包含检测模式、代码示例、grep 模式、严重性分类和输出格式
- frontmatter 完整,单文件未超限
亮点
- 提供了具体的 grep 模式用于检测,参数正确
- 覆盖了主要异常场景(如空 guarded、动态 setter),输出格式明确
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。