T09 · Insecure Skill Coding Practices
- Location
scripts/main.py:78- Finding
Configurable OCR Endpoint Enables Credential and Sensitive Document Exfiltration
- Content
View full analysis
Vulnerability Details
File Location:
scripts/main.py, lines 78-112
Vulnerability Type: Unrestricted sensitive-data destination
Risk Level: HighThe application permits
SCNET_API_BASEto be supplied through the local configuration without validating its scheme or hostname. It then sends both the Scnet API key and the complete user-selected document to the resulting URL.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 recognition function with retry behavior. """ api_base = config['SCNET_API_BASE'] api_key = config['SCNET_API_KEY'] url = f"{api_base}/ocr/recognize" # Check whether the file exists if not os.path.isfile(file_path): sys.exit(f"Error: file does not exist - {file_path}") # Automatically detect the MIME type 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
Cloud OCR legitimately requires transmitting the selected document and an authentication credential to the service provider. However, the minimum privilege required by the declared functionality is network access to the docu ...[truncated 2406 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove runtime endpoint configurability when only the official service is supported. Define the complete OCR URL as a trusted constant:
python OCR_URL = "https://api.scnet.cn/api/llm/v1/ocr/recognize" -
If custom endpoints are operationally necessary, require an explicit opt-in and validate the parsed URL before transmitting any credential or file:
- Require the
httpsscheme. - Allowlist approved hostnames, normally only
api.scnet.cn. - Reject embedded usernames or passwords.
- Reject fragments and unexpected query strings.
- Restrict ports to approved values.
- Normalize and verify the final path.
- Require the
-
Disable automatic redirects for this sensitive upload with
allow_redirects=False, or independently validate every redirect destination before resending credentials or file content. -
Separate custom endpoint credentials from
SCNET_API_KEY. Never send a production Scnet token to an endpoint that is not verified as belonging to Scnet. -
Display the validated destination and require explicit confirmation before the first upload when nonstandard endpoints are permitted.
-
Add automated tests confirming rejection of HTTP URLs, lookalike domains, embedded credentials, unapproved ports, malformed URLs, and attacker-controlled hosts.
-
Restrict
config/.envpermissions to the owning user and document configuration-integrity requirements. If tampering is suspected, rotate the API key and review previously processed documents for potential exposure.
-
