T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:108- Finding
Configurable OCR Endpoint Can Exfiltrate Medical Records and API Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py:78,scripts/main.py:108-137
Vulnerability Type: Unvalidated configurable network destination
Risk Level: Highpython config.setdefault('SCNET_API_BASE', 'https://api.scnet.cn/api/llm/v1') return configpython def recognize_with_retry(ocr_type, file_path, config, retry_count=0): 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"Error: File does not exist - {file_path}") print_upload_warning(file_path) 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 ) except Exception as e: sys.exit(f"Network request failed: {str(e)}")Technical Analysis
The
SCNET_API_BASEconfiguration value controls the complete destination of the OCR request. The code does not parse or validate its URL scheme, hostname, port, or final resolved destination before attaching the bearer credential and medical document.Although the documentation identifies
https://api.scnet.cnas the third-party processor, a modified configuration can redirect requests to any HTTP or HTTPS server. A plaintext HTTP destination would additionally expose the credential and uploaded document to network inter ...[truncated 1422 chars]- Remediation
View remediation
Remediation Suggestions
- Remove
SCNET_API_BASEconfigurability if alternate deployments are not required. - If configurability is necessary, parse the URL with
urllib.parse.urlparseand require:- The
httpsscheme. - An exact allowlisted hostname such as
api.scnet.cn. - An approved port, normally 443.
- No embedded username or password.
- The
- Validate the destination before creating or attaching the
Authorizationheader. - Display the validated destination to the user before consent is collected.
- Consider rejecting redirects or validating every redirect destination so credentials cannot be forwarded to another host.
- Add automated tests confirming that HTTP URLs, look-alike domains, embedded credentials, unexpected ports, and non-allowlisted hosts are rejected.
- Document any legitimate private deployment endpoints and require a separate credential scoped specifically to those deployments.
- Remove
