- Location
- scripts/geekbi_auth.py:698
- Finding
- Unrestricted base URL permits arbitrary authenticated request destinations and SSRF<![CDATA[
## Vulnerability Details
**File Location**: `scripts/shopee_category_info.py:33-42`, `scripts/shopee_category_list.py:33-42`, `scripts/shopee_goods_info.py:32-41`, `scripts/shopee_goods_search.py:58-66`, `scripts/shopee_mall_info.py:24-33`, `scripts/shopee_site_list.py:75-82`, `scripts/geekbi_auth.py:698-721`
**Vulnerability Type**: Unvalidated network destination and server-side request forgery
**Risk Level**: Medium
### Vulnerable Code
Each query CLI exposes an unrestricted base URL. For example:
```python
parser = argparse.ArgumentParser(description="查询 Shopee 商品并输出 JSON")
parser.add_argument("--base-url", default=DEFAULT_BASE_URL)
parser.add_argument("--param", action="append", default=[], help="查询条件,格式为 名称=值")
parser.add_argument("--timeout", type=float, default=30)
try:
params = parse_params(args.param)
payload = authenticated_json_request(
build_url(args.base_url, ENDPOINT, params), args.base_url, args.timeout
)
```
The shared request function sends requests to the resulting URL without validating its scheme, hostname, resolved address, or relationship to `base_url`:
```python
def authenticated_json_request(
url,
base_url,
timeout,
*,
method="GET",
body=None,
headers=None,
):
complete_pending_login(base_url, timeout)
request_headers = _api_headers()
if headers:
request_headers.update(headers)
authorization = _authorization_header(base_url)
if authorization:
request_headers["token"] = authorization
request = Request(
url,
data=body,
headers=request_headers,
method=method,
)
try:
with urlopen(request, timeout=timeout) as response:
response_payload = _read_json_response(response)
_raise_action_if_needed(response_payload)
return response_payload
```
### Technical Analysis
The declared production API is `https://openapi.geekbi.com`, but all public query scripts accept an ar
...[truncated 2265 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Remove `--base-url` from production-facing command-line interfaces and use the fixed GeekBI API origin.
2. If endpoint configurability is required, enforce an explicit allowlist containing only approved HTTPS hostnames, such as `openapi.geekbi.com`.
3. Reject all non-HTTPS schemes before loading authentication state or sending any request.
4. Resolve the destination and reject loopback, private, link-local, multicast, reserved, and cloud metadata address ranges.
5. Revalidate the destination after redirects, or disable cross-origin redirects for authenticated requests.
6. Verify that the final request URL has the same canonical scheme, hostname, and port as the approved base URL before attaching a token.
7. Keep endpoint injection for tests in test-only helpers rather than public production arguments.
8. Add tests for HTTP rejection, malicious domains, alternate ports, user-info URL syntax, redirects, IPv4 and IPv6 private addresses, and DNS rebinding scenarios.
]]>