T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:78- Finding
Configurable API base can expose credentials and sensitive documents to an arbitrary server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py:78-112
Vulnerability Type: Unrestricted sensitive-data transmission 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 optional
SCNET_API_BASEsetting is used directly to construct the request URL without validating its scheme, hostname, port, or trust relationship. The resulting request contains both the Scnet bearer credential and the complete user-selected document.Although uploading a document is necessary for the declared remote OCR functionality, the documented service only requires access to
https://api.scnet.cn/api/llm/v1/ocr/recognize. Permitting an unrestricted destination exceeds that minimum requirement. A malicious or incorrectly modified configuration can use an attacker-controlled HTTPS host or even plaintext HTTP.The HTT ...[truncated 1417 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
SCNET_API_BASEconfigurability unless custom service endpoints are an explicit functional requirement. - If configuration is required, parse the URL and enforce:
- The
httpsscheme. - An explicit allowlist of trusted hostnames.
- Expected ports only.
- No embedded username or password.
- A normalized, expected API path.
- The
- Bind the Scnet bearer token to the official Scnet hostname and refuse to attach it to any other destination.
- Disable automatic redirects with
allow_redirects=False, or validate every redirect target before resending credentials or files. - Display the upload destination and obtain informed user consent before sending identity-related documents.
- Document the external transmission, expected recipient, retention implications, and fields that may be extracted.
- Add tests confirming that HTTP URLs, unapproved hosts, unexpected ports, and cross-origin redirects are rejected.
- Remove
