T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:78- Finding
Unrestricted OCR API Endpoint Can Expose Credentials and Sensitive Identity Documents
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py, lines 78–112
Vulnerability Type: User-controlled network destination for sensitive data
Risk Level: HighVulnerable 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 reads
SCNET_API_BASEfrom its configuration and uses it directly to construct the request URL. It does not validate the URL scheme, hostname, port, or final destination before attaching both:- The
SCNET_API_KEYbearer credential. - The complete user-selected marriage-certificate file.
Marriage certificates can contain highly sensitive personal information, including names, dates of birth, certificate numbers, and government identity numbers. Although uploading the document is necessary for the declared cloud OCR functionality and is disclosed in the documentation, sending it to an arbitrary configurabl ...[truncated 1907 chars]
- The
- Remediation
View remediation
Remediation Suggestions
- Remove
SCNET_API_BASEconfigurability if alternate service endpoints are not operationally required. - If endpoint customization is necessary, parse the URL with
urllib.parse.urlparseand enforce:- The
httpsscheme. - An explicit hostname allowlist, such as
api.scnet.cn. - An approved port, normally 443.
- No embedded username or password.
- No URL fragments or unexpected path manipulation.
- The
- Construct the OCR endpoint from a trusted constant rather than concatenating an unrestricted configuration string.
- Reject redirects or verify every redirect destination before forwarding credentials and document content.
- Display the verified upload destination and obtain explicit user consent before transmitting identity documents.
- Document that the source file and extracted personal information are processed by an external service, including applicable retention and privacy considerations.
- Add automated tests confirming that HTTP URLs, unapproved hosts, embedded credentials, alternate ports, and malformed URLs are rejected.
- Use a narrowly scoped API token where supported, and provide rotation and revocation guidance in case the token is exposed.
- Remove
