T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:78- Finding
Configurable OCR Endpoint Can Exfiltrate API Credentials and Sensitive Documents
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py:78-112
Vulnerability Type: Unrestricted external endpoint configuration and sensitive-data transmission
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
SCNET_API_BASEvalue is read from configuration and used directly to construct the request URL. The code does not validate:- Whether the scheme is HTTPS
- Whether the destination hostname belongs to SCNet
- Whether the URL contains embedded credentials or unusual components
- Whether the endpoint is part of an approved allowlist
The resulting request includes both the bearer API credential and the complete user-selected document. Education certificates may contain names, birth dates, certificate numbers, institutional details, and other personally identifiable information.
Remote transmiss ...[truncated 1766 chars]
- Remediation
View remediation
Remediation Suggestions
- Pin the production endpoint in code to the official HTTPS origin whenever endpoint customization is not required.
- If endpoint overrides are operationally necessary, parse the URL and enforce:
- The
httpsscheme - An explicit hostname allowlist
- The expected port
- No embedded username or password
- A fixed or validated path prefix
- The
- Reject loopback, link-local, private-network, and non-approved destinations unless explicitly required for a controlled development mode.
- Disable redirects or validate every redirect destination before forwarding credentials or documents.
- Separate development endpoint support from production operation and require an explicit opt-in flag for non-production environments.
- Display or log the validated destination before upload without logging the API key or document contents.
- Document that files are transmitted to a third-party OCR service, including available privacy, retention, deletion, and data-processing terms.
- Apply restrictive permissions to
config/.envand verify them before reading credentials where the operating system supports such checks.
