T09 · Insecure Skill Coding Practices
- Location
financial_report_analyzer.py:124- Finding
Unrestricted API Endpoint Override Exposes Credentials and Uploaded Reports
- Content
View full analysis
Vulnerability Details
File Location:
financial_report_analyzer.py, lines 124-130, 143-150, 172-174, and 205-210
Vulnerability Type: Arbitrary external endpoint accepting sensitive credentials and documents
Risk Level: HighComplete Code Snippet
python parser.add_argument( "--base-url", type=str, default="", help="SoMark API base URL(覆盖 SOMARK_BASE_URL 环境变量)," "例如 https://somark.cn/api/v1(中国大陆)或 https://somark.ai/api/v1(海外)", )python data = aiohttp.FormData() data.add_field("api_key", api_key) data.add_field("file", file_path.read_bytes(), filename=file_path.name) for output_format in output_formats: data.add_field("output_formats", output_format) data.add_field("element_formats", json.dumps(element_formats, ensure_ascii=False)) data.add_field("feature_config", json.dumps(feature_config, ensure_ascii=False)) async with session.post(async_url, data=data) as resp:python async with session.post( check_url, data={"api_key": api_key, "task_id": task_id} ) as resp:python base_url = (args.base_url or os.environ.get( "SOMARK_BASE_URL", "https://somark.cn/api/v1" )).rstrip("/") if not base_url: print("错误:SoMark API base URL 不能为空") raise SystemExit(1) async_url = f"{base_url}/parse/async" check_url = f"{base_url}/parse/async_check"The unsafe override is also documented in
SKILL.md, lines 167-185:markdown #### `--base-url` (Optional) This argument overrides the SoMark API base URL. Use it to switch between regional endpoints. If omitted, the `SOMARK_BASE_URL` environment variable is used. If that is also unset, the default is `https://somark.cn/api/v1` (mainland China). ```bash # Mainland China (default) --base-url "https://somark.cn/api/v1" # Outside mainland China --base-url "https://somark.ai/api/v1"text ### Technical Analysis The script accepts an arbitrary base URL from either the `--base-url` command-line argument or the `SOMARK_BASE_URL` environment v ...[truncated 3118 chars]- Remediation
View remediation
Remediation Suggestions
-
Replace arbitrary URLs with a region selector. Prefer a constrained option such as
--region china|global, internally mapped to fixed endpoints:python APPROVED_BASE_URLS = { "china": "https://somark.cn/api/v1", "global": "https://somark.ai/api/v1", } -
If URL overrides must remain, enforce an exact allowlist. Parse the URL with
urllib.parse.urlsplitand require:- Scheme exactly equal to
https. - Hostname exactly equal to
somark.cnorsomark.ai. - No username or password.
- Expected port only.
- An approved path prefix.
- No fragments or unexpected query parameters.
- Scheme exactly equal to
-
Prevent cross-origin credential forwarding. Disable redirects for credential-bearing requests or validate every redirect target before following it:
python async with session.post(async_url, data=data, allow_redirects=False) as resp: ... -
Separate custom endpoints from production credentials. If development endpoints are required, use a distinct development credential rather than forwarding
SOMARK_API_KEY. -
Reject insecure and local destinations. Explicitly reject HTTP, IP literals, loopback addresses, link-local addresses, and private-network addresses.
-
Minimize credential transmission. Prefer an authorization header over multipart form fields if supported by the service, and avoid including secrets in error messages or logs.
-
Update the documentation. Remove examples or guidance that imply unrestricted endpoint overrides. Document the approved regional endpoints and explain that credentials and reports must never be sent to untrusted servers.
-
Add automated security tests. Verify rejection of:
http://endpoints.- Attacker-controlled domains.
- Lookalike and subdomain-confusion hosts.
- URLs containing credentials.
- Loopback, private, and link-local destinations.
- Redirects from an approved origin to an unapp ...[truncated 13 chars]
-
