check-mass-assignment

Detect mass-assignment vulnerabilities. Identify unprotected model filling, use of Request::all() for create/update operations, missing $fillable/$guarded definitions, and parameter binding without whitelist filtering.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "check-mass-assignment" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-eb51498dd65d7662ec53b1c9a0bedba2b099c5ee0dca5aa3e64a3a8c813b3463. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Detect mass-assignment vulnerabilities. Identify unprotected model filling, use of Request::all() for create/update operations, missing $fillable/$guarded definitions, and parameter binding without whitelist filtering.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Detects mass assignment vulnerabilities. Identifies unguarded model filling, Request::all() to create/update, missing $fillable/$guarded, and parameter binding without whitelisting.
Inputs and outputs
Grep: "array_merge\(.*request|array_merge\(.*\\\$data" --glob "**/*.php" ```
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
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

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 针对 PHP 开发中常见的安全漏洞(批量赋值)提供检测能力
  • 属于明确场景的通用工具,具有广泛受众(PHP/Laravel 开发者)
Trigger Precision95/100

Highlights

  • description 明确描述了检测目标,覆盖多种变体,边界清晰
Structure and Standards95/100

Highlights

  • 文档结构清晰,包含检测模式、代码示例、grep 模式、严重性分类和输出格式
  • frontmatter 完整,单文件未超限
Execution Reliability90/100

Highlights

  • 提供了具体的 grep 模式用于检测,参数正确
  • 覆盖了主要异常场景(如空 guarded、动态 setter),输出格式明确
Evidence Verifiability (mean of the first four)91/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.