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/11-csrf.md

View on GitHub
---
id: CSRF
severity_max: HIGH
applies_to: php
---

# CSRF — Cross-Site Request Forgery (PHP)

## Intent

Endpoint state-changing (POST/PUT/DELETE) trong PHP không có CSRF token / origin check → attacker host `<form action="https://target.com/transfer" method=POST>` trên site evil, victim đăng nhập sẵn target.com vào trang evil → form auto-submit (qua JS hoặc `<img>` cho GET) → request đi kèm cookie session → server thực thi.

PHP-specific:
- **Plain PHP**: KHÔNG có CSRF protection mặc định — dev phải tự implement token.
- **Laravel**: `VerifyCsrfToken` middleware auto-apply với route group `web` (trong `app/Http/Kernel.php`). Route trong `api` group dùng token bearer, KHÔNG có CSRF cookie check — nhưng API thường dùng session cookie qua Sanctum thì vẫn cần.
- **Symfony**: Form component tự generate token. Manual form thì cần `csrf_token()`.
- **WordPress**: `wp_nonce_field` / `check_admin_referer` / `wp_verify_nonce`. Plugin custom AJAX endpoint hay quên.

## Khi nào HIGH

- Endpoint state-changing dùng session cookie auth, không có CSRF token verify
- Laravel route được khai báo trong `web.php` nhưng được add vào `$except` của `VerifyCsrfToken` middleware
- WordPress AJAX (`admin-ajax.php`) handler không gọi `check_ajax_referer`
- SameSite cookie không set (hoặc `None`) — trình duyệt cũ vẫn gửi cross-site

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

- SameSite=Lax/Strict trên session cookie (modern browser block CSRF cho POST cross-site)
- Endpoint chỉ accept JSON với custom header `Content-Type: application/json` (preflight CORS chặn simple form)
- Có CORS allowlist chặt + check `Origin` header

## Khi nào INFO

- API endpoint dùng `Authorization: Bearer ...` (không session cookie) — CSRF không áp dụng vì attacker không có token

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

1. **Identify auth model**: session cookie hay bearer token? Nếu bearer → CSRF N/A.
2. **List state-changing endpoints** (POST/PUT/DELETE/PATCH):
   - Plain PHP: file `.php` xử lý `$_POST`
   - Laravel: `routes/web.php`, `routes/api.php`, controller methods
   - WordPress: hook `wp_ajax_*`, `wp_ajax_nopriv_*`, plugin action
3. **For each, verify CSRF check**:
   - Laravel: middleware `web` group? Check `$except` list trong `VerifyCsrfToken`.
   - WordPress: `check_ajax_referer('action_name', 'nonce')` hoặc `wp_verify_nonce`?
   - Plain PHP: hash_equals session token với request token?
4. **Check SameSite**: `session_set_cookie_params(['samesite' => 'Lax'])` hoặc Laravel `config/session.php` `same_site`

## Search patterns (PHP-specific)

```
# Laravel — endpoint state-changing
Route::(post|put|patch|delete)\s*\(
->post\s*\(.*Controller
->put\s*\(.*Controller

# Laravel CSRF exception (RED FLAG nếu nhiều)
protected\s+\$except\s*=\s*\[
VerifyCsrfToken

# Plain PHP — form processing
\$_POST\[                                    # POST handler — check có token verify

# WordPress AJAX
add_action\s*\(\s*['"]wp_ajax_
add_action\s*\(\s*['"]wp_ajax_nopriv_
# Nonce verify
check_ajax_referer\s*\(
wp_verify_nonce\s*\(
check_admin_referer\s*\(

# SameSite cookie
session_set_cookie_params
samesite
```

## Examples

### HIGH — flag

```php
<?php
// Plain PHP — không có token check
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $amount = $_POST['amount'];
    $to = $_POST['to'];
    transfer_money($_SESSION['user_id'], $to, $amount);  // BAD
}
```

```php
// Laravel — route trong $except
// app/Http/Middleware/VerifyCsrfToken.php
protected $except = [
    '/transfer',  // BAD: bypass CSRF cho endpoint state-changing
    'api/*',      // OK nếu API thực sự dùng bearer, nhưng cần verify
];
```

```php
<?php
// WordPress plugin AJAX không nonce
add_action('wp_ajax_delete_post', 'my_delete');
function my_delete() {
    $id = $_POST['post_id'];
    wp_delete_post($id);  // BAD: không check_ajax_referer
    wp_die();
}
```

### NOT critical — safe

```php
<?php
// Plain PHP — token CSRF
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!isset($_POST['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
        http_response_code(403);
        die('CSRF');
    }
    transfer_money(...);
}
// Trong form:
// <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
```

```php
// Laravel — middleware web auto check, form blade @csrf
// resources/views/transfer.blade.php
<form method="POST" action="/transfer">
    @csrf
    ...
</form>
// Hoặc AJAX gửi header X-CSRF-TOKEN từ meta tag
```

```php
// WordPress — nonce
add_action('wp_ajax_delete_post', 'my_delete');
function my_delete() {
    check_ajax_referer('delete_post_action', 'nonce');  // OK
    if (!current_user_can('delete_posts')) wp_die();
    wp_delete_post($_POST['post_id']);
    wp_die();
}
```

```php
// SameSite cookie
// Laravel config/session.php
'same_site' => 'lax',
'secure' => true,
'http_only' => true,
```

## Fix recommendation

1. **Laravel**: KHÔNG add route quan trọng vào `$except`. Form Blade dùng `@csrf`. AJAX gửi `X-CSRF-TOKEN` từ `<meta name="csrf-token">`.
2. **WordPress**:
   - `wp_nonce_field('action_name', 'nonce_name')` trong form
   - `check_admin_referer('action_name', 'nonce_name')` trong handler
   - AJAX: `wp_localize_script` truyền nonce → JS gửi → server `check_ajax_referer`
3. **Plain PHP**:
   - Generate token: `$_SESSION['csrf_token'] = bin2hex(random_bytes(32));`
   - Verify: `hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])` (constant-time compare)
   - Rotate sau mỗi lần dùng cho sensitive action
4. **SameSite**: set `Lax` (default modern) hoặc `Strict` cho session cookie.
5. **Origin header check**: backup defense — verify `Origin`/`Referer` header trùng app domain.
6. **Re-authenticate** cho action cực nhạy (xóa account, đổi password, chuyển tiền): require nhập lại mật khẩu.

## Cross-references

- Rule `12-broken-access-control`: CSRF + IDOR = attacker force victim xóa tài nguyên người khác
- Rule `04-idor`: cùng họ "missing check" — CSRF check authenticity of request, IDOR check authorization of resource
- Rule `17-verbose-error-debug-mode`: stack trace leak CSRF token nếu log to response
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