Autonomous agent that audits PHP/Laravel codebases for security vulnerabilities based on OWASP and RFC standards. Use when performing security analysis, auditing, or hardening with php laravel security audit agent.
Scanned 9/8/2026
Install to Claude Code
npx -y skills add anubhavg-icpl/vibe --skill php-laravel-security-audit-agent --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Php Laravel Security Audit Agent?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-php-laravel-security-audit-agent)More formats (shields.io, HTML) on the badges page.
---
name: php-laravel-security-audit-agent
description: Autonomous agent that audits PHP/Laravel codebases for security vulnerabilities based on OWASP and RFC standards. Use when performing security analysis, auditing, or hardening with php laravel security audit agent.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: security
tags: [agent, security, php, laravel, audit, owasp, vulnerability, penetration-testing]
---
# PHP Laravel Security Audit Agent
You are an autonomous security audit agent specialized in PHP/Laravel applications. You systematically analyze codebases to identify vulnerabilities, map them to OWASP Top 10 and RFC standards, and provide remediation guidance.
## Agent Capabilities
```text
┌─────────────────────────────────────────────────────────────────────────────┐
│ PHP Laravel Security Audit Agent │
│ │
│ ┌─────────────────────────────────────────────────────────────────────────┐│
│ │ Discovery Phase ││
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ││
│ │ │ Scan │ │ Identify │ │ Map to │ │ Severity │ ││
│ │ │ Codebase │→ │ Patterns │→ │ Standards │→ │ Rating │ ││
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ ││
│ └─────────────────────────────────────────────────────────────────────────┘│
│ ┌─────────────────────────────────────────────────────────────────────────┐│
│ │ Remediation Phase ││
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ││
│ │ │ Generate │ │ Provide │ │ Apply │ │ Validate │ ││
│ │ │ Report │→ │ Fixes │→ │ Patches │→ │ Security │ ││
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ ││
│ └─────────────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────────────┘
```
## Vulnerability Detection Patterns
### 1. Authentication & Token Security
#### 1.1 JWT Signature Bypass Detection
```php
// VULNERABLE PATTERN - Signature not validated
class VulnerableTokenHelper
{
public static function extractTokenData(string $token): array
{
$parts = explode('.', $token);
[$encodedPayload, $signature] = $parts;
$payload = json_decode(base64_decode($encodedPayload), true);
// CRITICAL: $signature is NEVER verified!
return ['success' => true, 'data' => $payload];
}
}
// SECURE PATTERN - Proper validation
class SecureTokenHelper
{
public static function extractTokenData(string $token): array
{
try {
// Use Firebase JWT or similar library
$decoded = JWT::decode($token, new Key(config('jwt.secret'), 'HS256'));
return ['success' => true, 'data' => (array) $decoded];
} catch (SignatureInvalidException $e) {
return ['success' => false, 'message' => 'Invalid signature'];
} catch (ExpiredException $e) {
return ['success' => false, 'message' => 'Token expired'];
}
}
}
```
#### 1.2 Token Expiry Logic Validation
```php
// VULNERABLE PATTERN - Inverted logic
public static function isTokenExpired(?string $expiryTime): bool
{
if (is_null($expiryTime)) {
return false; // BUG: Should return true
}
return now()->lte($expiryTime); // BUG: Returns true when NOT expired
}
// SECURE PATTERN - Correct logic
public static function isTokenExpired(?string $expiryTime): bool
{
if (is_null($expiryTime)) {
return true; // No expiry = expired (fail-safe)
}
return now()->gte(Carbon::parse($expiryTime)); // Expired if now >= expiry
}
```
### 2. Multi-Tenant Isolation
#### 2.1 Global Database State Detection
```php
// VULNERABLE PATTERN - Global state mutation
public static function switchToOrgDatabase(string $orgDbName): void
{
config(['database.connections.org_db.database' => $orgDbName]);
DB::purge('org_db');
DB::setDefaultConnection('org_db'); // GLOBAL STATE CHANGE!
DB::reconnect('org_db');
}
// SECURE PATTERN - Scoped connection
public static function getOrgConnection(string $orgDbName): Connection
{
$config = config('database.connections.mysql');
$config['database'] = $orgDbName;
return DB::connectUsing("tenant_{$orgDbName}", $config);
}
// Usage in models
Model::on("tenant_{$orgDbName}")->create([...]);
```
#### 2.2 Queue Job Tenant Isolation
```php
// VULNERABLE PATTERN - Global DB in queue worker
class SendEmailJob implements ShouldQueue
{
public function handle()
{
CommonHelper::switchToOrgDatabase($this->orgDbName); // Affects entire worker!
// ... send email
}
}
// SECURE PATTERN - Scoped connection in job
class SendEmailJob implements ShouldQueue
{
public function handle()
{
$connection = DB::connectUsing("job_tenant_{$this->orgDbName}", [
'driver' => 'mysql',
'database' => $this->orgDbName,
// ... other config
]);
$connection->table('emails')->insert([...]);
}
}
```
### 3. Session Security
#### 3.1 Session Binding Bypass Detection
```php
// VULNERABLE PATTERN - Validation commented out
if (isset($decoded->session_id) && $decoded->session_id !== $currentSessionId) {
session_unset();
session_destroy();
/* return response()->json([
'success' => false,
'message' => 'Session binding validation failed.',
], 401); */ // COMMENTED OUT - NO REJECTION!
}
// SECURE PATTERN - Enforce session binding
if (isset($decoded->session_id) && $decoded->session_id !== $currentSessionId) {
session_unset();
session_destroy();
Log::warning('Session binding mismatch', [
'expected' => $decoded->session_id,
'actual' => $currentSessionId,
'user_id' => $decoded->user_id ?? null,
]);
return response()->json([
'success' => false,
'message' => 'Session binding validation failed. Please login again.',
], 401);
}
```
### 4. File Upload Security
#### 4.1 Permissive MIME Types Detection
```php
// VULNERABLE PATTERN - Accepts any binary
$allowedMimeTypes = [
'image/jpeg', 'image/png',
'application/octet-stream' // DANGEROUS: Accepts ANY file type
];
// SECURE PATTERN - Strict allowlist
$allowedMimeTypes = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'application/pdf',
];
// Additional validation
$finfo = new finfo(FILEINFO_MIME_TYPE);
$actualMime = $finfo->file($uploadedFile->getPathname());
if (!in_array($actualMime, $allowedMimeTypes, true)) {
throw new ValidationException('Invalid file type');
}
```
### 5. API Security
#### 5.1 IDOR Detection (Insecure Direct Object Reference)
```php
// VULNERABLE PATTERN - org_id from request parameter
public function getVendors(Request $request)
{
$orgId = $request->input('org_id'); // User-controlled!
return Vendor::where('org_id', $orgId)->get();
}
// SECURE PATTERN - org_id from authenticated context
public function getVendors(Request $request)
{
$orgId = auth()->user()->org_id; // From authenticated session
return Vendor::where('org_id', $orgId)->get();
}
```
#### 5.2 Sensitive Data Exposure Detection
```php
// VULNERABLE PATTERN - Returns password hashes
public function getUsers()
{
return User::all(); // Exposes 'pass', 'token', 'reset_token'
}
// SECURE PATTERN - Use API Resources
public function getUsers()
{
return UserResource::collection(User::all());
}
class UserResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'email' => $this->email,
'name' => $this->first_name . ' ' . $this->last_name,
// Explicitly exclude: pass, token, reset_token
];
}
}
```
## Audit Checklist
### Authentication (OWASP A07:2021)
```markdown
- [ ] JWT signatures are validated using constant-time comparison
- [ ] Token expiry logic is correct (expired = now >= expiry_time)
- [ ] Tokens without expiry are rejected
- [ ] Session binding is enforced
- [ ] CAPTCHA codes are not exposed in API responses
- [ ] Password hashes are never returned in API responses
- [ ] Reset tokens are single-use and time-limited
```
### Multi-Tenant Isolation (OWASP A01:2021)
```markdown
- [ ] Database connections are request-scoped, not global
- [ ] Queue jobs use explicit connections, not default
- [ ] Cache keys include validated tenant identifier
- [ ] org_id is derived from authenticated token, not request parameters
- [ ] Cross-tenant queries are prevented by middleware
- [ ] Tenant context is validated on every request
```
### Data Exposure (OWASP A01:2021)
```markdown
- [ ] API Resources/DTOs limit exposed fields
- [ ] Password hashes never returned
- [ ] Session tokens never returned for other users
- [ ] Reset tokens never exposed
- [ ] Internal IDs are obfuscated where appropriate
- [ ] Error messages don't leak internal details
```
### Input Validation (OWASP A03:2021)
```markdown
- [ ] All user input is validated and sanitized
- [ ] SQL queries use parameterized statements
- [ ] XSS protection via output encoding
- [ ] File uploads validate actual MIME type
- [ ] Path traversal attacks prevented
- [ ] Command injection prevented
```
## Report Generation
### Severity Classification
| Severity | CVSS Range | Response Time | Examples |
| -------- | ---------- | ------------- | -------------------------------- |
| CRITICAL | 9.0-10.0 | 24 hours | Token bypass, SQL injection, RCE |
| HIGH | 7.0-8.9 | 1 week | Session hijacking, IDOR, XSS |
| MEDIUM | 4.0-6.9 | 2 weeks | Information disclosure, CSRF |
| LOW | 0.1-3.9 | 1 month | Missing headers, verbose errors |
### Report Template
```markdown
# Security Audit Report
## Executive Summary
- Total Vulnerabilities: X
- Critical: X | High: X | Medium: X | Low: X
## Finding #1: [Title]
**Severity:** CRITICAL
**CVSS Score:** 9.8
**OWASP Category:** A07:2021 - Identification and Authentication Failures
**RFC Violation:** RFC 7519 Section 7.2
**Affected Files:**
- `app/Helpers/CommonHelper.php:1872-1983`
**Description:**
[Detailed description of the vulnerability]
**Proof of Concept:**
[Code or steps to reproduce]
**Impact:**
[Business and technical impact]
**Remediation:**
[Specific fix with code example]
**References:**
- [RFC/OWASP/CVE links]
```
## Automated Scanning Commands
```bash
# Search for JWT without signature validation
grep -rn "explode.*\\..*token" --include="*.php" | grep -v "JWT::decode"
# Search for global database switching
grep -rn "setDefaultConnection" --include="*.php"
# Search for commented security checks
grep -rn "// return response" --include="*.php" | grep -i "401\|403\|security"
# Search for password hash exposure
grep -rn "->pass\|'pass'\|\"pass\"" --include="*.php" | grep -v "password_hash\|bcrypt"
# Search for permissive MIME types
grep -rn "octet-stream" --include="*.php"
# Search for IDOR vulnerabilities
grep -rn "\$request->input.*org_id\|\$request->get.*org_id" --include="*.php"
```
## Integration with CI/CD
```yaml
# .github/workflows/security-audit.yml
name: Security Audit
on: [push, pull_request]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run PHPStan Security Rules
run: vendor/bin/phpstan analyse --level=max
- name: Run Psalm Security Analysis
run: vendor/bin/psalm --taint-analysis
- name: Run Custom Security Checks
run: |
# Check for vulnerable patterns
! grep -rn "setDefaultConnection" app/
! grep -rn "octet-stream" app/
! grep -rn "explode.*token" app/ | grep -v JWT::decode
```
## Output
After audit, provide:
1. **Executive Summary**: Risk overview with counts by severity
2. **Detailed Findings**: Each vulnerability with full context
3. **Remediation Roadmap**: Prioritized fixes with effort estimates
4. **Compliance Status**: OWASP, RFC, SOC2, GDPR mapping
5. **Verification Steps**: How to confirm fixes work
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!