T09 · Insecure Skill Coding Practices
- Location
mock_server.py:656- Finding
Unauthenticated SSRF Through the Real-Request Proxy
- Content
View full analysis
Vulnerability Details
File Location:
mock_server.py:656-697
Vulnerability Type: Unrestricted server-side request forgery and sensitive-header forwarding
Risk Level: CriticalVulnerable Code
python @app.post("/mock/proxy") async def proxy_request(request: Request): """ 代理转发:把请求转发到真实目标地址,原样返回响应(不走 Mock 逻辑)。 请求体: { "target_url": "http://localhost:8080/api/user", "method": "POST", "headers": {"Authorization": "Bearer xxx"}, "body": {...} } """ import httpx data = await request.json() target_url = data.get("target_url") method = data.get("method", "POST").upper() req_headers = data.get("headers", {}) req_body = data.get("body") if not target_url: return JSONResponse( {"code": 1, "error": "target_url 不能为空"}, status_code=400 ) try: async with httpx.AsyncClient(timeout=30.0) as client: if method == "GET": resp = await client.get(target_url, headers=req_headers) elif method == "POST": resp = await client.post( target_url, headers=req_headers, json=req_body ) elif method == "PUT": resp = await client.put( target_url, headers=req_headers, json=req_body ) elif method == "DELETE": resp = await client.delete( target_url, headers=req_headers ) else: return JSONResponse( { "code": 1, "error": "不支持的请求方法: " + method }, status_code=400 )...[truncated 1930 chars]
- Remediation
View remediation
Remediation Suggestions
- Require authentication and explicit authorization for
/mock/proxy. - Disable the proxy by default and require an explicit startup flag to enable it.
- Restrict destination schemes to
https, or tohttpandhttpsonly when necessary. - Maintain an explicit allowlist of permitted destination hosts and ports.
- Resolve hostnames before connection and reject loopback, private, link-local, multicast, reserved, and unspecified addresses.
- Revalidate every redirect destination and disable redirects unless required.
- Strip
Authorization,Cookie,Proxy-Authorization, and other sensitive headers by default. - Apply request-size, timeout, concurrency, and rate limits.
- Record proxy use in a security audit log without recording secret values.
- Return a generic failure message instead of exposing detailed internal connection errors.
- Require authentication and explicit authorization for
