T09 · Insecure Skill Coding Practices
- Location
scripts/pdf_ocr.py:93- Finding
PDF URL Mode Uploads an Unnecessary Local Document
- Content
View full analysis
Vulnerability Details
File Location:
scripts/pdf_ocr.py, lines 93-108
Vulnerability Type: Excessive data transmission and unintended document disclosure
Risk Level: MediumThe PDF client permits
pdf_pathandpdf_urlto be supplied simultaneously. Rather than selecting one source, it includes both the complete local PDF and the remote URL in the request sent to iFlytek.python # Prepare multipart form data files = None data = {} if pdf_path: with open(pdf_path, 'rb') as f: files = {'file': (pdf_path.name, f.read(), 'application/pdf')} if pdf_url: data['pdfUrl'] = pdf_url if export_format: data['exportFormat'] = export_format url = f"{self.API_BASE}/start" response = requests.post(url, headers=headers, data=data, files=files, timeout=60)The command-line interface makes the risk more likely because
pdf_pathis a required positional argument even when--pdf-urlis used. The README acknowledges this behavior, whileSKILL.mddescribes the two inputs as alternatives and provides a URL-only example that the implementation does not support.Technical Analysis
URL-based OCR only requires transmitting the URL from which the service should retrieve the document. Uploading a local PDF in the same request exceeds the minimum data access required for that mode.
There is no mutual-exclusion validation such as:
python if bool(pdf_path) == bool(pdf_url): raise ValueError("Provide exactly one PDF source")Consequently, when both values are present, the request contains a multipart
filefield holding the complete local document and apdfUrlfield. TLS protects the data in transit, and the destination is the declared iFlytek OCR endpoint, so this is not a covert exfiltration channel. Nevertheless, it can disclose an additional document that is unnecessary for the selected URL workflow.The Base64 operations identified by the static pre-scan a ...[truncated 1678 chars]
- Remediation
View remediation
Remediation Suggestions
-
Enforce that exactly one document source is accepted in
start_task():python if bool(pdf_path) == bool(pdf_url): raise ValueError("Provide exactly one of pdf_path or pdf_url") -
Make the CLI inputs mutually exclusive. Because one source is positional, the cleanest approach is to replace it with explicit options:
python source = parser.add_mutually_exclusive_group(required=True) source.add_argument("--pdf-file", type=Path) source.add_argument("--pdf-url") -
Construct the request body with an exclusive branch so that a local file can never be attached in URL mode:
python if pdf_path is not None: with open(pdf_path, "rb") as f: files = {"file": (pdf_path.name, f.read(), "application/pdf")} else: data["pdfUrl"] = pdf_url -
Update
SKILL.mdandREADME.mdso that examples and parameter requirements accurately match the implementation. -
Add tests that intercept the outgoing request and verify:
- File mode includes
filebut notpdfUrl. - URL mode includes
pdfUrlbut no multipart file. - Supplying both sources is rejected before any file is opened or network request is made.
- Supplying neither source is rejected.
- File mode includes
-
Before external processing, clearly inform users that the selected document or URL will be transmitted to iFlytek and may contain sensitive information.
-
