Skip to content

tanviet12/vbsec / skills/antigravity/vbs-scan-security

vbs-scan-security

Flagged

Use when scanning code for security vulnerabilities. Use when user says "scan security", "kiểm tra bảo mật", "security audit", "review security", or invokes `/vbs-scan-security`. For large scans (>20 main-language files OR >30 total OR >14 days) processes chunks sequentially. Outputs bilingual reports (vi/en). Optional `--auto-fix` (agentic patch + verify loop) and `--sca` (live CVE lookup via OSV.dev).

FileKindSize
SKILL.mdskill md28.2 KB
VERSIONother6 B
references/chunking-strategy.mdmarkdown7.2 KB
references/data-flow-classification.mdmarkdown9.5 KB
references/dependency-scan.mdmarkdown9.7 KB
references/i18n/en.mdmarkdown8.7 KB
references/i18n/vi.mdmarkdown9.4 KB
references/language-detection.mdmarkdown7.5 KB
references/load-rules.shexecutablescript5.2 KB
references/output-format.mdmarkdown26.1 KB
references/project-context.mdmarkdown2.7 KB
references/sub-agent-prompts.mdmarkdown16.5 KB
references/validate-report.pyexecutablescript8.7 KB
rules/generic/01-hardcoded-secret.mdmarkdown5.4 KB
rules/generic/02-sql-injection.mdmarkdown5.2 KB
rules/generic/03-xss.mdmarkdown4.9 KB
rules/generic/04-idor.mdmarkdown5.7 KB
rules/generic/05-slopsquatting.mdmarkdown6.1 KB
rules/generic/06-brute-force.mdmarkdown6.9 KB
rules/generic/07-mass-assignment.mdmarkdown6.3 KB
rules/generic/08-insecure-deserialization.mdmarkdown6.3 KB
rules/generic/09-ssrf.mdmarkdown6.7 KB
rules/generic/10-path-traversal.mdmarkdown6.3 KB
rules/generic/11-csrf.mdmarkdown7.8 KB
rules/generic/12-broken-access-control.mdmarkdown7.9 KB
rules/generic/13-weak-password-hashing.mdmarkdown5.2 KB
rules/generic/14-jwt-none-algorithm.mdmarkdown5.3 KB
rules/generic/15-cors-misconfig.mdmarkdown5.3 KB
rules/generic/16-unrestricted-file-upload.mdmarkdown5.9 KB
rules/generic/17-verbose-error-debug-mode.mdmarkdown5.8 KB
rules/generic/18-missing-rate-limit.mdmarkdown10.7 KB
rules/generic/19-race-condition.mdmarkdown11.5 KB
rules/generic/20-outdated-dependency.mdmarkdown7.2 KB
rules/generic/21-command-injection.mdmarkdown6.6 KB
rules/generic/22-vulnerable-dependency.mdmarkdown5.3 KB
rules/generic/23-llm-prompt-injection.mdmarkdown9.7 KB
rules/generic/24-excessive-agency.mdmarkdown10.1 KB
rules/generic/25-tenant-isolation.mdmarkdown10.1 KB
rules/generic/26-authz-path-parity.mdmarkdown10.9 KB
rules/generic/27-excessive-data-exposure.mdmarkdown10.4 KB
rules/generic/28-business-state-integrity.mdmarkdown9.5 KB
rules/generic/29-sensitive-data-in-logs.mdmarkdown9.1 KB
rules/generic/30-auth-session-lifecycle.mdmarkdown9.4 KB
rules/generic/31-resource-exhaustion.mdmarkdown9.0 KB
rules/languages/README.mdmarkdown8.5 KB
rules/languages/dart/01-hardcoded-secret.mdmarkdown7.9 KB
rules/languages/dart/03-xss.mdmarkdown5.2 KB
rules/languages/dart/05-slopsquatting.mdmarkdown4.6 KB
rules/languages/dart/10-path-traversal.mdmarkdown6.3 KB
rules/languages/dart/12-broken-access-control.mdmarkdown8.3 KB
rules/languages/dart/17-verbose-error-debug-mode.mdmarkdown6.7 KB
rules/languages/dart/20-outdated-dependency.mdmarkdown4.7 KB
rules/languages/dart/README.mdmarkdown3.7 KB
rules/languages/dotnet/02-sql-injection.mdmarkdown5.7 KB
rules/languages/dotnet/07-mass-assignment.mdmarkdown6.0 KB
rules/languages/dotnet/08-insecure-deserialization.mdmarkdown5.7 KB
rules/languages/dotnet/17-verbose-error-debug-mode.mdmarkdown5.0 KB
rules/languages/dotnet/21-command-injection.mdmarkdown5.3 KB
rules/languages/dotnet/README.mdmarkdown1.7 KB
rules/languages/go/02-sql-injection.mdmarkdown5.2 KB
rules/languages/go/08-insecure-deserialization.mdmarkdown5.0 KB
rules/languages/go/09-ssrf.mdmarkdown5.8 KB
rules/languages/go/17-verbose-error-debug-mode.mdmarkdown6.1 KB
rules/languages/go/21-command-injection.mdmarkdown5.2 KB
rules/languages/go/README.mdmarkdown2.7 KB
rules/languages/php/02-sql-injection.mdmarkdown5.8 KB
rules/languages/php/08-insecure-deserialization.mdmarkdown6.2 KB
rules/languages/php/11-csrf.mdmarkdown6.2 KB
rules/languages/php/17-verbose-error-debug-mode.mdmarkdown6.5 KB
rules/languages/php/21-command-injection.mdmarkdown6.7 KB
rules/languages/php/README.mdmarkdown2.9 KB
rules/languages/python/02-sql-injection.mdmarkdown7.2 KB
rules/languages/python/07-mass-assignment.mdmarkdown7.3 KB
rules/languages/python/08-insecure-deserialization.mdmarkdown7.3 KB
rules/languages/python/09-ssrf.mdmarkdown7.5 KB
rules/languages/python/11-csrf.mdmarkdown7.6 KB
rules/languages/python/14-jwt-none-algorithm.mdmarkdown7.5 KB
rules/languages/python/15-cors-misconfig.mdmarkdown8.0 KB
rules/languages/python/17-verbose-error-debug-mode.mdmarkdown8.4 KB
rules/languages/python/21-command-injection.mdmarkdown8.5 KB
rules/languages/python/README.mdmarkdown3.4 KB
rules/languages/typescript/02-sql-injection.mdmarkdown7.5 KB
rules/languages/typescript/03-xss.mdmarkdown6.7 KB
rules/languages/typescript/07-mass-assignment.mdmarkdown7.4 KB
rules/languages/typescript/08-insecure-deserialization.mdmarkdown7.0 KB
rules/languages/typescript/09-ssrf.mdmarkdown7.5 KB
rules/languages/typescript/11-csrf.mdmarkdown7.3 KB
rules/languages/typescript/14-jwt-none-algorithm.mdmarkdown7.0 KB
rules/languages/typescript/15-cors-misconfig.mdmarkdown7.2 KB
rules/languages/typescript/17-verbose-error-debug-mode.mdmarkdown7.2 KB
rules/languages/typescript/21-command-injection.mdmarkdown6.7 KB
rules/languages/typescript/README.mdmarkdown3.3 KB
workflows/auto-fix.mdmarkdown18.9 KB
workflows/large-review-sequential.mdmarkdown14.8 KB
workflows/small-review.mdmarkdown10.1 KB

rules/languages/php/08-insecure-deserialization.md

View on GitHub
---
id: INSECURE-DESERIALIZATION
severity_max: CRITICAL
applies_to: php
---

# Insecure Deserialization (PHP)

## Intent

PHP `unserialize()` là **RCE classic** vì nó tự gọi magic method (`__wakeup`, `__destruct`, `__toString`, `__call`) khi reconstruct object. Nếu trong codebase có class với `__destruct` thao tác file/SQL, attacker craft serialized string chứa class đó → khi `unserialize` chạy → RCE.

Phổ biến:
- `unserialize($_GET['data'])`, `unserialize($_COOKIE['session'])` — classic Phar/POP chain
- **Phar deserialization**: `file_exists()`, `file_get_contents()`, `fopen()`, `is_file()` trên `phar://` URI → auto unserialize metadata. Attacker upload file `.jpg` thực chất là `.phar`, gọi `file_exists('phar://upload.jpg/test')` → trigger.
- Laravel `Cookie::queue()` mã hóa session với APP_KEY — nếu APP_KEY leak → attacker forge cookie unserialize.
- WordPress meta value chứa serialized array, function `maybe_unserialize` chạy trên DB row do attacker insert (qua SQLi hoặc XSS update profile).

## Khi nào CRITICAL

- `unserialize($_GET / $_POST / $_COOKIE / $_REQUEST)` không có `['allowed_classes' => false]`
- File operation (`file_exists`, `fopen`, `file_get_contents`, `is_file`, `getimagesize`, `imagecreatefromjpeg`) với path L1 không validate scheme → `phar://` exploit
- `unserialize` của session/cookie không HMAC-verify trước
- Codebase chứa class có dangerous `__destruct` / `__wakeup` (Monolog, Symfony Process, Laravel — historical POP chains rất nhiều)

## Khi nào HIGH (giảm cấp)

- `unserialize($data, ['allowed_classes' => false])` — chặn object construction (PHP 7.0+)
- Có HMAC verify trước unserialize (Laravel session với APP_KEY)
- Phar disable qua `ini_set('phar.readonly', 'On')` — không chặn full nhưng giảm

## Cách reasoning (KHÔNG pattern-match thuần)

1. **Grep** sinks: `unserialize`, `maybe_unserialize` (WP), file ops với user path
2. **Read** call site:
   - Argument là L1 (`$_GET/$_POST/$_COOKIE/$_REQUEST`, Laravel `request()->...`)?
   - Argument từ DB (`->meta_value`) → L2 stored, vẫn nguy hiểm
   - Có `allowed_classes => false` option?
3. **Trace L1**:
   - Form upload filename → `getimagesize($_FILES['x']['tmp_name'])` — tmp_name safe nhưng nếu code dùng `$_FILES['x']['name']` trong path → phar
   - Cookie raw bytes → unserialize trực tiếp
4. **Inventory POP chain candidates**: composer.json có `monolog`, `laravel/framework`, `guzzlehttp/psr7` cũ → check version (CVE-known POP chain)
5. **Verify HMAC**: Laravel cookie tự sign — kiểm APP_KEY không leak qua `.env` commit (cross-ref HARDCODED-SECRET)

## Search patterns (PHP-specific)

```
# unserialize trực tiếp
unserialize\s*\(\s*\$_(GET|POST|COOKIE|REQUEST|SESSION)
unserialize\s*\(\s*\$\w+\s*\)              # check $\w+ trace nguồn
maybe_unserialize\s*\(                      # WordPress wrapper

# Không có allowed_classes
unserialize\s*\([^)]+\)                    # negative check: thiếu "allowed_classes"

# Phar deserialization sink
file_exists\s*\(\s*\$\w+
file_get_contents\s*\(\s*\$\w+
fopen\s*\(\s*\$\w+
is_file\s*\(\s*\$\w+
getimagesize\s*\(\s*\$\w+
imagecreatefrom\w+\s*\(\s*\$\w+
md5_file\s*\(\s*\$\w+
sha1_file\s*\(\s*\$\w+

# Laravel cookie / session forge
decrypt\s*\(\s*\$\w+
Crypt::decrypt
unserialize\s*\(\s*decrypt
```

## Examples

### CRITICAL — flag

```php
<?php
// Classic — RCE qua POP chain nếu app có class dangerous
$data = unserialize($_COOKIE['user']);
// attacker craft cookie chứa O:8:"DangerCls":1:{s:4:"path";s:11:"/etc/passwd";}
```

```php
<?php
// Phar deserialization
$upload_path = $_GET['file'];  // attacker: phar://upload.phar/x
if (file_exists($upload_path)) {  // BAD: trigger phar unserialize
    echo "ok";
}
```

```php
<?php
// WordPress meta đọc qua maybe_unserialize
$meta = $wpdb->get_var("SELECT meta_value FROM wp_usermeta WHERE user_id = $id");
$data = maybe_unserialize($meta);  // L2: nếu attacker insert qua SQLi → RCE
```

```php
// Laravel — không validate uploaded file mime
$path = $request->input('avatar');  // attacker control path
getimagesize($path);  // BAD: phar://avatar.phar/x trigger unserialize
```

### NOT critical — safe

```php
<?php
// allowed_classes false — chỉ deserialize scalar/array
$data = unserialize($_COOKIE['user'], ['allowed_classes' => false]);
// $data sẽ là __PHP_Incomplete_Class cho mọi object → không trigger magic method
```

```php
<?php
// JSON thay vì serialize
$data = json_decode($_COOKIE['user'], true);  // safe
```

```php
// Validate scheme + extension trước file op
$path = $request->input('file');
if (!preg_match('/^[a-zA-Z0-9._-]+$/', basename($path))) abort(400);
if (preg_match('#^phar://#i', $path)) abort(400);
$full = storage_path('uploads/' . basename($path));
file_exists($full);  // safer
```

## Fix recommendation

1. **Thay `unserialize` bằng `json_decode`** cho mọi data từ user. JSON không có magic method.
2. **Nếu phải unserialize** (legacy session), dùng `['allowed_classes' => false]` hoặc whitelist `['allowed_classes' => [SafeClass::class]]`.
3. **HMAC verify trước unserialize**:
   ```php
   if (!hash_equals($expected_hmac, hash_hmac('sha256', $data, $key))) abort(400);
   $obj = unserialize($data);
   ```
4. **Phar protection**:
   - Validate scheme: `parse_url($path, PHP_URL_SCHEME)` reject `phar`
   - `ini_set('phar.readonly', 'On')` (giảm risk)
   - Chỉ dùng `realpath()` rồi check prefix
5. **Laravel APP_KEY**: KHÔNG commit `.env`, rotate nếu leak. APP_KEY leak = forge mọi session cookie.
6. **WordPress**: validate trước khi `maybe_unserialize` từ DB nếu DB write path có thể bị tamper.
7. **Composer audit**: chạy `composer audit` thường xuyên — POP chain phụ thuộc class trong dependency.

## Cross-references

- Rule `01-hardcoded-secret`: Laravel APP_KEY leak = forge serialized cookie
- Rule `02-sql-injection`: SQLi insert serialized payload → stored deserialization
- Rule `20-outdated-dependency`: Monolog/Guzzle/Symfony cũ có POP chain documented
- Rule `17-verbose-error-debug-mode`: Ignition error page Laravel (APP_DEBUG=true) từng RCE qua deserialization CVE-2021-3129
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall