Back to list
hieupvXmasEve

review-security-rules

by hieupvXmasEve

0🍴 0📅 Jan 6, 2026

SKILL.md


name: review-security-rules description: Reviews code for security vulnerabilities and adherence to the project's Gate vs Policy authorization rules. Use before committing changes involving permissions or routes. allowed-tools: Read, Grep, Glob

Review Security & Authorization

This skill audits code for common security issues and strict adherence to the project's Authorization Rules (docs/rules/authorization.md).

Instructions

  1. Analyze Scope:

    • Focus on routes/, Controllers, Policies, and Gates.
  2. Check for Authorization Violations:

    1. Controller Authorization

    • Rule: Controllers must NEVER call Gate::allows(). They must use $this->authorize() (Policy).
    • Check: Grep Gate:: inside *Controller.php.
    • Fix: Replace with $this->authorize('action', $model).

    2. Route Authorization

    • Rule: Routes with IDs (e.g., /events/{event}) must NOT use can: middleware.
    • Reason: Middleware cannot check specific object ownership; Policy must do it.
    • Check: Look for Route::...->middleware('can:...') on routes with parameters.
    • Fix: Remove middleware, add $this->authorize() in the Controller method.

    3. Gate Definitions

    • Rule: Gates must NOT accept Models or query the DB.
    • Check: Review AuthServiceProvider or where Gates are defined.
    • Fix: Gates should only check permissions (e.g., $user->hasPermission(...)).

    4. Policy Implementation

    • Rule: Policies must check Data Rules (ownership, status), not just permissions.
    • Check: *Policy.php methods.
    • Fix: Ensure $user->id === $model->user_id or similar logic exists.
  3. Report:

    • List violations with file paths and line numbers.
    • Cite the specific rule from docs/rules/authorization.md.

Example Checks

1. Controller using Gate (Forbidden):

grep -r "Gate::" app/Http/Controllers

2. Route with ID using Middleware (Forbidden):

# Manual check of route files
# Look for: Route::get('/{id}', ...)->middleware('can:...')

3. Policy missing Data Check (Suspicious):

// Suspicious: Only checks permission
public function update(User $user, Post $post) {
    return $user->can('update_posts');
}
// Correct: Checks permission AND ownership
public function update(User $user, Post $post) {
    return $user->can('update_posts') && $post->user_id === $user->id;
}

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon