T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:77- Finding
Unrestricted OCR API Endpoint Can Expose Documents and Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py, lines 77-112
Vulnerability Type: Unvalidated external service endpoint
Risk Level: MediumVulnerable Code
python config.setdefault('SCNET_API_BASE', 'https://api.scnet.cn/api/llm/v1') return config def recognize_with_retry(ocr_type, file_path, config, retry_count=0): """ 带重试机制的 OCR 识别函数。 当遇到 429 (Too Many Requests) 时,自动等待后重试。 调用 Scnet OCR API 进行识别""" api_base = config['SCNET_API_BASE'] api_key = config['SCNET_API_KEY'] url = f"{api_base}/ocr/recognize" # 检查文件是否存在 if not os.path.isfile(file_path): sys.exit(f"错误: 文件不存在 - {file_path}") # 自动检测 MIME 类型 mime_type, _ = mimetypes.guess_type(file_path) if mime_type is None: mime_type = 'application/octet-stream' headers = { 'Authorization': f'Bearer {api_key}' } try: with open(file_path, 'rb') as f: files = { 'file': (os.path.basename(file_path), f, mime_type) } data = { 'ocrType': ocr_type, 'channelTag': "scnetSkills" } response = requests.post(url, headers=headers, data=data, files=files, timeout=60)Technical Analysis
The Skill accepts
SCNET_API_BASEfrom its configuration without validating its scheme, hostname, port, or trust boundary. It then appends/ocr/recognizeand sends both the complete user-selected document and theSCNET_API_KEYbearer credential to that destination.Uploading the document and sending an authorization token to the documented Scnet API is necessary for the declared remote OCR functionality. However, allowing an arbitrary endpoint exceeds the minimum privileges needed to access that service. A modified or incorrectly configured
.envfile can redirect the request to an attacker-controlled server. A plaintexthttp://...[truncated 1576 chars]- Remediation
View remediation
Remediation Suggestions
- Parse the configured endpoint with a standard URL parser before issuing any request.
- Require the
httpsscheme and reject plaintext HTTP. - Allowlist
api.scnet.cnas the default and expected hostname. - Reject embedded user information, fragments, unexpected ports, malformed hosts, and ambiguous URL forms.
- If custom endpoints are a legitimate requirement, require an explicit security opt-in and display the exact destination before transmitting a document.
- Do not send the production Scnet credential to a custom hostname. Require a separate credential scoped to that endpoint.
- Disable redirects for upload requests or validate the scheme and hostname of every redirect target before following it.
- Document clearly that submitted files leave the local environment and are processed by an external service.
- Add automated tests covering HTTP endpoints, lookalike domains, user-information URL tricks, unexpected ports, and cross-host redirects.
