T09 · Insecure Skill Coding Practices
Warning
- Location
- extract.py:90
- Finding
- Remote PDF Files Are Downloaded over Unencrypted HTTP## Vulnerability Details **File Location**: `extract.py`, line 90 **Vulnerability Type**: Unauthenticated remote content retrieval **Risk Level**: Medium ### Vulnerable Code ```python report_id = row['报告ID'] date = row['公告日期'] pdf_url = f'http://pdf.dfcfw.com/pdf/H2_{report_id}_1.pdf' try: resp = requests.get(pdf_url, timeout=30) if len(resp.content) < 5000: continue ``` The same insecure URL scheme is documented in `SKILL.md`, line 34: ```text http://pdf.dfcfw.com/pdf/H2_{报告ID}_1.pdf ``` ### Technical Analysis The application retrieves untrusted PDF documents over plaintext HTTP and immediately processes the response with `pdfplumber` or PyMuPDF. HTTP does not provide server authentication, integrity protection, or confidentiality. A network-positioned attacker can therefore replace or modify a downloaded report. The response is accepted based only on its size. The code does not call `raise_for_status()`, validate the response content type, verify the PDF magic bytes, impose a maximum response size, or authenticate the document. PDF parsers process complex binary structures, so feeding attacker-controlled documents to them increases exposure to parser vulnerabilities and resource-exhaustion attacks. ### Attack Path 1. A user runs the extractor on a network controlled or observable by an attacker. 2. The script requests a report through `http://pdf.dfcfw.com/...`. 3. The attacker intercepts or redirects the HTTP response. 4. The attacker returns a crafted payload larger than 5,000 bytes. 5. The script writes the payload to `temp.pdf`. 6. `pdfplumber` or PyMuPDF parses the attacker-controlled file. 7. The payload corrupts extracted results, consumes excessive resources, or attempts to exploit a vulnerability in the installed parser. ### Impact Assessment An attacker can alter the generated report content and potentially cause denial of service through oversized or computat ...[truncated 286 chars]
- Remediation
- ## Remediation Suggestions - Require an HTTPS endpoint and reject redirects that downgrade to HTTP. - Call `resp.raise_for_status()` before consuming the response. - Stream downloads while enforcing a strict maximum file size. - Validate the expected content type and require the file to begin with a valid PDF signature. - Where supported, verify reports using a trusted digest or digital signature. - Parse externally sourced PDFs in a sandbox with restricted filesystem access, network access, CPU time, and memory. - Keep PyMuPDF, pdfplumber, and their transitive parsing components updated to reviewed versions.
