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/python/09-ssrf.md

View on GitHub
---
id: SSRF
severity_max: HIGH
applies_to: python
---

# SSRF (Server-Side Request Forgery) — Python Specialization

> Override cho rule chung `rules/generic/09-ssrf.md`. Áp dụng khi `primary_language: python`.

## Intent (Python-specific)

Vibe code Python rất thường viết các tính năng "fetch URL", "webhook", "import from URL", "screenshot URL", "import RSS" — dùng `requests`, `urllib`, `httpx`, `aiohttp` để fetch URL người dùng cung cấp. Không validate → attacker fetch `http://169.254.169.254/latest/meta-data/iam/security-credentials/` (AWS metadata endpoint) chiếm token IAM, hoặc fetch `http://localhost:6379` (Redis), `http://10.0.0.1:8080` (internal service). Cùng họ: **Open Redirect** — `flask.redirect(request.args['next'])` mà không whitelist host → phishing trên domain của bạn.

## Khi nào CRITICAL/HIGH (cap HIGH)

- `requests.get/post/request(user_url)` không validate host
- `urllib.request.urlopen(user_url)` / `urllib3.request`
- `httpx.get/post/request` sync hoặc async với L1 URL
- `aiohttp.ClientSession().get(user_url)`
- `flask.redirect(request.args.get('next'))` không whitelist (Open Redirect)
- Django `HttpResponseRedirect(request.GET['next'])` không gọi `url_has_allowed_host_and_scheme()`
- FastAPI `RedirectResponse(url=request.query['next'])` không validate
- Webhook URL được fetch từ DB nhưng nguồn gốc là L1 (user nhập lúc subscribe)
- Hosting trên AWS/GCP/Azure (có metadata endpoint) — tăng impact

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

- URL từ env/config (L3) — vẫn chấp nhận nếu chỉ admin set
- Có validate host bằng allowlist domain
- Có chặn IP private (RFC1918) + loopback trước khi fetch
- Endpoint chỉ admin với guard rõ ràng

## Cách reasoning

1. **Grep** sink: `requests\.(get|post|put|delete|head|patch|request)`, `urlopen`, `httpx\.`, `aiohttp\.`, `redirect\(`, `HttpResponseRedirect`, `RedirectResponse`
2. **Read** function chứa call, trace URL từ:
   - Flask: `request.args`, `request.form`, `request.json`
   - Django: `request.GET`, `request.POST`, `request.data` (DRF)
   - FastAPI: query/body parameter, `Body()`, `Query()`
3. **Trace L1→sink** — đặc biệt chú ý URL đi vòng qua DB (subscriber webhook URL, RSS feed URL được lưu DB)
4. **Verify**:
   - Có parse URL và check host whitelist?
   - Có chặn IP private/loopback bằng `ipaddress.ip_address(socket.gethostbyname(host)).is_private`?
   - Có giới hạn scheme (`http`/`https` only)?
   - Open redirect: có dùng `is_safe_url` (Django) hoặc whitelist domain (Flask)?
   - `requests` có `allow_redirects=False` không (chống follow redirect lừa)?

## Search patterns

```
# requests library
requests\.(get|post|put|delete|head|patch|request)\s*\(\s*(request\.|f["'])
requests\.Session\(\)\.\w+\s*\(\s*(request\.|f["'])

# urllib
urllib\.request\.urlopen\s*\(\s*(request\.|f["'])
urlopen\s*\(\s*(request\.|f["'])

# httpx (sync + async)
httpx\.(get|post|put|delete|head|patch|request)\s*\(\s*(request\.|f["'])
httpx\.AsyncClient\(\)\.\w+\s*\(

# aiohttp
aiohttp\.ClientSession\([^)]*\)\.\w+\s*\(\s*(request\.|f["'])
session\.get\s*\(\s*(request\.|f["'])

# Open Redirect
flask.*redirect\s*\(\s*request\.(args|form|values)
HttpResponseRedirect\s*\(\s*request\.(GET|POST)
RedirectResponse\s*\(\s*(url\s*=\s*)?(request\.|.*query)

# AWS metadata target trong code (red flag)
169\.254\.169\.254
metadata\.google\.internal

# fetch / urlretrieve
urlretrieve\s*\(\s*(request\.|f["'])
```

## Examples

### HIGH — flag

```python
# Flask + requests fetch URL user
@app.post('/fetch')
def fetch_url():
    url = request.json['url']  # L1
    r = requests.get(url, timeout=5)
    return jsonify(content=r.text[:1000])
# Exploit: url=http://169.254.169.254/latest/meta-data/iam/security-credentials/role-name
# → trả về AWS credentials trong response
```

```python
# Django webhook subscription
def trigger_webhook(request):
    hook = Webhook.objects.get(id=request.POST['hook_id'])
    requests.post(hook.url, json={'event': 'x'})  # L2: URL từ DB, gốc L1
    # User register webhook URL = http://localhost:8500/v1/agent/services/ (Consul)
```

```python
# FastAPI screenshot service
@app.post('/screenshot')
async def screenshot(url: str):  # L1
    async with httpx.AsyncClient() as client:
        r = await client.get(url)
    return {"html": r.text}
```

```python
# Open Redirect Flask
@app.route('/login')
def login():
    next_url = request.args.get('next', '/')  # L1
    if authenticated:
        return redirect(next_url)  # /login?next=https://evil.com → phishing
```

```python
# Open Redirect Django thiếu is_safe_url
def post_login(request):
    nxt = request.GET.get('next', '/')
    return HttpResponseRedirect(nxt)  # cần url_has_allowed_host_and_scheme
```

```python
# aiohttp với user URL
async def proxy(request):
    target = request.query['url']  # L1
    async with aiohttp.ClientSession() as s:
        async with s.get(target) as r:
            return web.Response(text=await r.text())
```

### NOT critical — safe

```python
# Allowlist host
from urllib.parse import urlparse
ALLOWED_HOSTS = {'api.partner.com', 'cdn.example.com'}

@app.post('/fetch')
def fetch_url():
    url = request.json['url']
    host = urlparse(url).hostname
    if host not in ALLOWED_HOSTS:
        abort(400)
    return requests.get(url, timeout=5).text
```

```python
# Chặn IP private + loopback
import ipaddress, socket
from urllib.parse import urlparse

def is_safe_url(url):
    host = urlparse(url).hostname
    try:
        ip = ipaddress.ip_address(socket.gethostbyname(host))
    except ValueError:
        return False
    return not (ip.is_private or ip.is_loopback or ip.is_link_local or ip.is_reserved)

if is_safe_url(url):
    requests.get(url)
```

```python
# Django open redirect safe
from django.utils.http import url_has_allowed_host_and_scheme

nxt = request.GET.get('next', '/')
if url_has_allowed_host_and_scheme(nxt, allowed_hosts={request.get_host()}):
    return HttpResponseRedirect(nxt)
return HttpResponseRedirect('/')
```

```python
# requests với allow_redirects=False (chống follow → bypass)
requests.get(url, timeout=5, allow_redirects=False)
```

## Fix recommendation

1. **Validate URL nhiều tầng**:
   - Parse: `urlparse(url)`, kiểm `scheme in {'http', 'https'}`
   - Resolve DNS → check IP không phải private/loopback/metadata IP
   - Block 169.254.169.254, fd00::/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8
2. **Allowlist domain** nếu domain space hẹp:
   ```python
   ALLOWED = {'webhook.partner.com', 'api.stripe.com'}
   if urlparse(url).hostname not in ALLOWED:
       raise ValueError("Host not allowed")
   ```
3. **Tắt redirect follow**: `requests.get(url, allow_redirects=False)`. Nếu phải follow → re-validate sau mỗi redirect.
4. **Open Redirect**:
   ```python
   # Django
   from django.utils.http import url_has_allowed_host_and_scheme
   if not url_has_allowed_host_and_scheme(nxt, allowed_hosts={request.get_host()}):
       nxt = '/'
   # Flask: tự whitelist hoặc dùng werkzeug.urls.url_parse
   ```
5. **Dùng lib chuyên**: `ssrf-protect`, `dns-rebinding-protector`, hoặc proxy qua egress gateway có policy.
6. **Tắt IMDSv1 trên AWS** (yêu cầu IMDSv2 với token) — defense in depth ở infra.

## Cross-references

- Generic `12-broken-access-control`: SSRF endpoint thường thiếu auth
- Generic `17-verbose-error-debug-mode`: response leak ra error có thể chứa nội dung internal
- Python `15-cors-misconfig`: SSRF + CORS misconfig = chain exploit
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