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

references/data-flow-classification.md

View on GitHub
# Data Flow Classification — Trust Levels L1-L4

Phân loại nguồn dữ liệu để quyết định 1 pattern code có thực sự là vulnerability hay không. **Đây là phương pháp luận cốt lõi của vbsec** — phân biệt giữa pattern-match thuần và phân tích bảo mật thực thụ.

## Bốn mức tin cậy

| Level | Tên | Tin cậy | Mô tả |
|---|---|---|---|
| **L1** | User-controlled input | **KHÔNG TIN** | Bất cứ thứ gì user (kể cả attacker) có thể gửi vào |
| **L2** | Database / persistent storage | Bán tin | Giá trị từ DB — có thể gốc gác từ L1 user input đã lưu trước đó |
| **L3** | Internal code / config | Tin | Hardcoded strings, config keys (đã verify), computed value từ trust source |
| **L4** | System / runtime | Tin | Env vars, file path nội bộ, framework constants |

## L1 — Untrusted sources (LUÔN coi là attacker-controlled)

### Web frameworks
- **Express/Node**: `req.body`, `req.query`, `req.params`, `req.headers`, `req.cookies`, `req.files`
- **Next.js**: `req.body` trong API routes, `searchParams`/`params` trong app router, `context.params/query` trong `getServerSideProps`
- **Fastify**: `request.body`, `request.query`, `request.params`, `request.headers`
- **NestJS**: parameters decorated với `@Body()`, `@Query()`, `@Param()`, `@Headers()`
- **Express middleware**: `req.user` SAU khi auth (đã verify) là L3; TRƯỚC auth vẫn là L1
- **Flask**: `request.form`, `request.args`, `request.json`, `request.cookies`, `request.headers`, `request.files`
- **Django**: `request.GET`, `request.POST`, `request.FILES`, `request.COOKIES`, `request.META['HTTP_*']`
- **FastAPI**: function parameters bound qua Pydantic from request body (BEFORE validation chạy là L1; AFTER Pydantic validate là L2-ish — vẫn cần escape trong sink)
- **Go net/http**: `r.URL.Query()`, `r.FormValue`, `r.PostFormValue`, `r.Header`, `r.Body`, `mux.Vars(r)`
- **Go Gin**: `c.Query`, `c.PostForm`, `c.Param`, `c.GetHeader`, `c.ShouldBind*`
- **Go Echo**: `c.QueryParam`, `c.FormValue`, `c.Param`, `c.Request().Header.Get`
- **Go Fiber**: `c.Query`, `c.Body`, `c.Params`, `c.Get` (header), `c.FormFile`
- **PHP**: `$_GET`, `$_POST`, `$_REQUEST`, `$_COOKIE`, `$_FILES`, `$_SERVER` (headers như `HTTP_*`, `REQUEST_URI`), `php://input`, `file_get_contents("php://input")`
- **Laravel**: `$request->input()`, `$request->all()`, `$request->query()`, `$request->json()`, `Input::get()`, route bindings BEFORE validation
- **Ruby/Rails**: `params[...]`, `request.body`, `request.headers`, `cookies[...]`
- **Spring (Java)**: `@RequestParam`, `@RequestBody`, `@PathVariable`, `@RequestHeader`, `@CookieValue`
- **CLI**: `os.Args` (Go), `sys.argv` (Python), `process.argv` (Node), `$argv` (PHP CLI), `ARGV` (Ruby)

### Bot/messaging
- Telegram bot: `update.Message.Text`, `message.text`, `message.caption`, callback data
- Discord/Slack bot: message content, slash command args, button payloads
- Webhook payloads: bất kỳ field nào từ external service nhưng attacker có thể spoof (nếu signature verify failed/missing → vẫn L1)

### File system / streams
- Stdin (đọc từ pipe trong CLI tool)
- Uploaded file content (kể cả filename — `req.file.originalname`)
- File path do user nhập (qua `?path=...` query param)

### Network
- DNS responses (có thể bị poison)
- External HTTP API responses **mà user control URL** (qua SSRF)

### App di động (Flutter / React Native / native)
- **Payload push**: `RemoteMessage.data`, `message.notification`, `NotificationResponse.payload` (`flutter_local_notifications`). Server của mình gửi, nhưng ai có FCM server key / quyền gửi (hoặc backend bị lạm dụng) cũng gửi được → L1 khi dùng làm đường dẫn, URL, tên file
- **Deep link / intent**: `GoRouterState.uri`, `state.pathParameters`, `state.uri.queryParameters`, `app_links` / `uni_links` `uriLinkStream`, `getInitialLink`, `PlatformDispatcher.defaultRouteName`. App hay trang web bất kỳ trên máy mở được → L1 thật
- **Clipboard**: `Clipboard.getData`, `Pasteboard`
- **File từ app khác**: `receive_sharing_intent`, `file_picker`, `image_picker`, file zip / backup người dùng chọn (cả nội dung lẫn tên file)
- **WebView**: `JavaScriptChannel.onMessageReceived`, `onNavigationRequest` URL — trang trong WebView gửi lên
- Response API của chính backend: L2 (tin như DB). Thành L1 khi dùng làm đường dẫn file, URL mở WebView, HTML render

## L2 — Database / persistent storage

Dữ liệu từ DB, Redis, S3... LUÔN có thể chứa L1 đã lưu trước đó. Treat như semi-trust:

- **Safe to use trong query** (parameterized) — DB engine xử lý đúng kể cả khi value chứa SQL syntax
- **NOT safe to interpolate vào HTML** — Stored XSS xảy ra khi L2 chứa `<script>` được render thẳng
- **NOT safe trong `exec`/shell** — nếu L2 chứa shell metacharacters → command injection
- **NOT safe khi build URL** — nếu L2 chứa redirect target → open redirect / SSRF

**Quy tắc:** L2 dùng trong cùng class sink với nguồn gốc của nó là OK (DB→DB query). L2 sang class khác (DB→HTML/shell/URL) thì treat như L1.

## L3 — Internal code

Tin tưởng được:

- Hardcoded strings, regex patterns, SQL fragments không có placeholder
- Computed values từ L3/L4 sources (vd: `sessionKey := fmt.Sprintf("user:%s", userID)` — nếu `userID` là L3 hoặc đã verified từ JWT là L3)
- Application config sau khi đã load và validate
- Internal IDs do app tự sinh (UUID v4, sequence từ DB)

**Cẩn thận:** Nếu L3 ghép với L1 và toàn bộ ghép vào sink, bộ ghép trở thành L1.

## L4 — System / runtime

Tin tưởng tuyệt đối:

- Environment variables (loaded at startup)
- File paths cố định trong code
- Framework/library constants
- Build-time variables

**Lưu ý:** Env var **không** được log/print ra response → đó là cách lộ secret (HARDCODED-SECRET rule check).

---

## Phân tích data flow (workflow cho LLM agent)

Khi gặp 1 pattern code khả nghi (vd: `db.query` có string concatenation), làm theo bước:

```
1. IDENTIFY SINK
   └─ Đây là sink loại gì? SQL? HTML? Shell? URL? File path?

2. IDENTIFY DATA INPUT
   └─ Value nào ghép vào sink? Biến tên gì?

3. TRACE BACKWARD (read full function, có thể đi qua nhiều file)
   └─ Biến đó assign từ đâu?
       ├─ Trực tiếp từ req.X / $_GET / params → L1
       ├─ Từ DB query result → L2
       ├─ Từ hardcoded string → L3
       ├─ Từ os.Getenv → L4
       └─ Từ kết hợp: dùng level cao nhất (KHÔNG TIN > tin)

4. CHECK SANITIZATION ON PATH
   └─ Giữa source và sink có:
       ├─ Parameterization? (db.query(..., [val]) — placeholder)
       ├─ Escape/encode? (HTML escape, URL encode, JSON.stringify)
       ├─ Whitelist validate? (regex match, enum check)
       └─ Type cast? (parseInt — loại bỏ non-numeric)

5. VERDICT
   ├─ L1 → sink không có sanitization → FLAG (CRITICAL/HIGH tùy rule)
   ├─ L1 → sink có sanitization phù hợp → SAFE, không flag
   ├─ L2/L3/L4 → sink → tùy class sink (xem quy tắc L2)
   └─ Không rõ → đọc thêm context, nếu vẫn không rõ thì flag với severity giảm 1 cấp + note "uncertain"
```

## Ví dụ ứng dụng

### Ví dụ 1: SQL Injection — flag CRITICAL

```python
@app.route("/user/<id>")
def get_user(id):              # id từ URL → L1
    sql = f"SELECT * FROM users WHERE id = {id}"  # L1 ghép vào SQL string
    return db.execute(sql)     # sink = SQL, không parameterize
```

**Verdict:** L1 → SQL sink, không sanitization → **CRITICAL** SQL-INJECTION.

### Ví dụ 2: Sprintf safe — không flag

```go
func GetSession(userID string) {  // userID đã từ JWT verified upstream → L3
    key := fmt.Sprintf("session:%s", userID)
    db.Where("key = ?", key).First(&session)  // parameterized
}
```

**Verdict:** L3 + parameterized → SAFE. Không flag dù có `fmt.Sprintf` quanh SQL liên quan.

### Ví dụ 3: Stored XSS — flag HIGH

```jsx
function Comment({ id }) {
  const data = useFetch(`/api/comments/${id}`)  // data từ DB → L2
  return <div dangerouslySetInnerHTML={{__html: data.body}} />  // L2 vào HTML sink
}
```

**Verdict:** L2 dùng cross-class (DB→HTML). Nếu `body` có thể chứa user input (rất khả năng) → **HIGH** stored XSS.

### Ví dụ 4: Command Injection — flag CRITICAL

```javascript
app.get('/ping', (req, res) => {
  const host = req.query.host    // L1
  exec(`ping -c 1 ${host}`, ...)  // L1 vào shell sink
})
```

**Verdict:** L1 → shell sink → **CRITICAL** COMMAND-INJECTION.

### Ví dụ 5: Trust boundary có sanitization — không flag

```python
@app.post("/user")
def create_user(user: UserCreate):  # UserCreate là Pydantic schema
    # user.email đã được Pydantic validate qua EmailStr → format ok
    # nhưng nội dung vẫn từ L1 → khi insert DB, vẫn cần parameterized
    db.execute("INSERT INTO users (email) VALUES (:email)", {"email": user.email})
```

**Verdict:** L1 → SQL sink CÓ parameterization → SAFE.

---

## Quy tắc rút gọn

> **Một dòng code có pattern nguy hiểm + L1 input + không sanitization phù hợp = vulnerability thực sự.**
>
> **Một dòng code có pattern nguy hiểm + chỉ L3/L4 = không phải vulnerability.**

Đây là lý do tại sao vbsec phải READ context, không chỉ grep. Pattern-match thuần sẽ vừa miss thật vừa fp ầm ầm.
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