Skip to content

tanviet12/vbsec / skills/codex/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.8 KB
VERSIONother6 B
agents/openai.yamlconfig313 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.9 KB
workflows/small-review.mdmarkdown10.1 KB

rules/generic/04-idor.md

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

# Insecure Direct Object Reference (IDOR)

## Intent

Endpoint nhận `id` từ user và trả về / sửa resource **mà không kiểm tra resource đó thuộc về user nào**. Attacker chỉ cần đổi số trong URL: `GET /api/orders/123` → `GET /api/orders/124` để **đọc đơn hàng người khác, đọc CMND, xem hóa đơn, sửa profile, xóa tài khoản khác**.

Vibe code cực dính lỗi này vì frontend ẩn nav nên dev tưởng "ai biết URL đâu", nhưng API gọi trực tiếp được. Đây là top 1 trong OWASP Top 10 2021 (Broken Access Control).

## Khi nào HIGH

- Endpoint nhận ID qua URL param / query / body và truy vấn DB **chỉ bằng ID đó**, không kèm `user_id = current_user`
- Resource là dữ liệu cá nhân, đơn hàng, chat, file upload, profile, billing
- Có auth (đã login) nhưng KHÔNG có ownership check

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

- Resource là public (vd: bài blog đã publish, sản phẩm catalog)
- ID là UUID v4 random (khó đoán) — vẫn rủi ro nếu UUID leak qua nơi khác
- Endpoint chỉ admin gọi (có middleware role check), nhưng vẫn nên có ownership

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

1. **Grep** các route handler: `app.get`, `@app.route`, `router.get/post/put/delete` với path chứa `:id`, `<id>`, `{id}`
2. **Read** body handler đầy đủ: query DB chỉ bằng `id`, hay có thêm `user_id` / `owner_id`?
3. **Trace**: ID đến từ URL → L1. Resource trả về có chứa data nhạy cảm không?
4. **Verify auth layer**:
   - Middleware có gắn `req.user` từ JWT/session không?
   - Query có `WHERE id=? AND user_id=?` hoặc `.filter(owner=request.user)` không?
   - Có ACL/policy layer (CanCan, Pundit, casbin) không?
5. Chú ý: chỉ có `requireAuth` middleware (check đã login) **KHÔNG ĐỦ** — phải check ownership của từng resource.

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

### Routes nhận ID

```
@app\.route\s*\([^)]*<int:id>
router\.(get|put|patch|delete)\s*\(\s*["'][^"']*:id
app\.(get|put|patch|delete)\s*\(\s*["'][^"']*:id
Route::(get|put|patch|delete)\s*\(\s*["'][^"']*\{id\}
\.MapGet\s*\(\s*"[^"]*\{id\}
```

### Query không có user_id

```
findById\s*\(\s*req\.params\.id\s*\)         # Mongoose
\.findUnique\s*\(\s*\{\s*where:\s*\{\s*id    # Prisma — check tiếp có user_id không
Model\.objects\.get\s*\(\s*id\s*=             # Django — KHÔNG có user
\.find\s*\(\s*params\[:id\]\s*\)              # Rails
SELECT.*FROM.*WHERE\s+id\s*=\s*\?            # raw SQL — chỉ id
```

### Dấu hiệu thiếu ownership

```
# Có req.user nhưng không dùng trong query
req\.user\.id                                # tốt — kiểm tra dùng ở đâu
current_user\.id
```

## Examples

### HIGH — flag

```javascript
// Express — bất kỳ ai login đều xem được order của người khác
app.get("/api/orders/:id", requireAuth, async (req, res) => {
  const order = await Order.findById(req.params.id);   // KHÔNG check user
  res.json(order);
});
```

```python
# Django — thiếu ownership
@login_required
def view_invoice(request, invoice_id):
    invoice = Invoice.objects.get(id=invoice_id)   # bất kỳ ai cũng đọc được
    return render(request, "invoice.html", {"invoice": invoice})
```

```php
<?php
// Laravel — không filter theo user
public function show($id) {
    $document = Document::find($id);
    return view('document.show', compact('document'));
}
```

```javascript
// PATCH endpoint — bất kỳ ai đổi được profile người khác
app.patch("/api/users/:id", requireAuth, async (req, res) => {
  await User.updateOne({ _id: req.params.id }, req.body);  // không check ownership
});
```

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

```javascript
// Có ownership check
app.get("/api/orders/:id", requireAuth, async (req, res) => {
  const order = await Order.findOne({ _id: req.params.id, userId: req.user.id });
  if (!order) return res.status(404).end();
  res.json(order);
});
```

```python
# Django — filter theo owner
@login_required
def view_invoice(request, invoice_id):
    invoice = get_object_or_404(Invoice, id=invoice_id, owner=request.user)
    return render(request, "invoice.html", {"invoice": invoice})
```

```ruby
# Rails — Pundit authorize
def show
  @document = Document.find(params[:id])
  authorize @document   # policy check
end
```

```javascript
// Resource public (bài blog đã publish) — OK
app.get("/api/posts/:id", async (req, res) => {
  const post = await Post.findOne({ _id: req.params.id, status: "published" });
  res.json(post);
});
```

## Fix recommendation

1. **Luôn filter theo owner trong query**:
   ```javascript
   // Trước (BAD)
   const order = await Order.findById(req.params.id);
   // Sau (GOOD)
   const order = await Order.findOne({ _id: req.params.id, userId: req.user.id });
   ```
2. **Dùng policy/ACL layer**:
   - Rails: Pundit / CanCanCan
   - Node: casbin, accesscontrol
   - Django: `django-guardian`, `PermissionRequiredMixin`
   - Laravel: Policies + `authorize()`
3. **Soft 404 khi không sở hữu**: trả 404 (không phải 403) để tránh leak thông tin "resource tồn tại".
4. **UUID v4 thay vì auto-increment INT**: phòng thủ phụ, không thay thế ownership check.
5. **Test E2E**: tạo 2 user, user A tạo resource, user B thử truy cập bằng ID — phải bị từ chối. Viết test này cho mọi resource endpoint.

## Cross-references

- Rule `02-sql-injection`: IDOR + SQLi = nuke
- Rule `07-mass-assignment`: cùng họ "trust input" — input có thể chứa `user_id` ghi đè owner
- Rule `11-csrf`: PUT/DELETE IDOR endpoint mà thiếu CSRF = exploit qua link
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