T09 · Insecure Skill Coding Practices
- Location
paper_digest.py:124- Finding
Unrestricted API Endpoint Allows Credential and Document Disclosure
- Content
View full analysis
Vulnerability Details
File Location:
paper_digest.py, lines 124–135 and 184–189
Vulnerability Type: Unvalidated external API endpoint
Risk Level: HighVulnerable Code
python async def submit_task( session: aiohttp.ClientSession, file_path: Path, api_key: str, output_formats: list[str], element_formats: dict[str, str], feature_config: dict[str, bool], async_url: str, ) -> str: 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 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"Technical Analysis
The
--base-urlcommand-line option andSOMARK_BASE_URLenvironment variable are accepted without validating the URL scheme, hostname, port, embedded credentials, or destination. The resulting URL is passed directly toaiohttp.ClientSession.post().The submission request contains both the complete user-selected document and
SOMARK_API_KEY. Consequently, anyone who can influence the command-line arguments or process environment can redirect these sensitive values to an arbitrary server. A plaintext HTTP endpoint may also expose them to network interception.Although the documentation identifies two legitimate regional SoMark endpoints, the implementation neither allowlists those endpoints nor requires HTTPS. Redirect handling is also not explicitly restricte ...[truncated 1940 chars]
- Remediation
View remediation
Remediation Suggestions
-
Allowlist trusted service endpoints. Permit only the documented regional endpoints by default:
https://somark.cn/api/v1https://somark.ai/api/v1
-
Require HTTPS. Parse the URL with
urllib.parse.urlsplit()and reject non-HTTPS schemes, missing hostnames, fragments, embedded usernames or passwords, and unexpected ports. -
Validate the normalized destination. Compare normalized scheme, hostname, port, and path rather than relying on string prefixes, which can be bypassed by hosts such as
somark.cn.attacker.example. -
Restrict redirects. Disable automatic redirects for requests carrying credentials and files, or validate every redirect destination against the same allowlist before following it:
python async with session.post(async_url, data=data, allow_redirects=False) as resp: -
Make custom endpoints an explicit advanced option. If self-hosted endpoints must be supported, require a separate opt-in flag and display the exact destination before transmitting the API key or document. Custom endpoints should still require HTTPS unless an explicit development-only override is used.
-
Reduce credential exposure. Prefer an authorization header if supported by the API, avoid including credentials in diagnostic output, and clearly instruct users to rotate the key after suspected disclosure.
-
Add security tests. Verify rejection of HTTP URLs, deceptive subdomains, embedded credentials, unexpected ports, malformed URLs, and cross-origin redirects.
-
