T03 · Remote Payload Retrieval and Execution
Warning
- Location
- templates/report_template.html:326
- Finding
- Mutable Remote JavaScript Is Retrieved and Executed During PDF Rendering<![CDATA[ ## Vulnerability Details **File Locations**: - `templates/report_template.html:326-330` - `scripts/to_pdf.py:26-35` - `templates/report_template.html:1002` - `templates/report_template.html:1334` - `templates/report_template.html:1368` **Vulnerability Type**: Remote executable content loaded without integrity verification **Risk Level**: Medium ### Vulnerable Code `templates/report_template.html:326-330`: ```html <script src="https://unpkg.com/d3@7/dist/d3.min.js"></script> <!-- TopoJSON: needed for V2 (regional map) and V7 (choropleth). Remove if neither used. --> <script src="https://unpkg.com/topojson-client@3/dist/topojson-client.min.js"></script> <!-- d3-sankey: ONLY needed for V8 (Sankey). Remove if not used. --> <script src="https://unpkg.com/d3-sankey@0.12.3/dist/d3-sankey.min.js"></script> ``` `scripts/to_pdf.py:26-35`: ```python with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page(viewport={"width": 860, "height": 1200}) page.goto(f"file://{abs_html}", wait_until="networkidle", timeout=timeout * 1000) page.wait_for_timeout(5000) page.pdf( path=pdf_path, format="A4", print_background=True, margin={"top": "0", "right": "0", "bottom": "0", "left": "0"}, ) ``` The template also retrieves remote map data during rendering: ```javascript d3.json('https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json').then(function(world){ ``` ```javascript d3.json('https://cdn.jsdelivr.net/npm/us-atlas@3/states-10m.json').then(function(us){ ``` ### Technical Analysis The generated report imports JavaScript directly from third-party CDNs. Several URLs use mutable major-version selectors such as `d3@7`, `topojson-client@3`, and `world-atlas@2`. None of the script elements include Subresource Integrity hashes. The PDF converter opens the HTML in Chromium and allows the imported scripts to execute. Consequently, the effective code executed during report generation ...[truncated 2186 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Vendor D3, TopoJSON, d3-sankey, fonts, and atlas datasets inside the project. 2. Modify the template to reference local, reviewed files and render reports with network access disabled. 3. If CDN use is unavoidable: - Pin exact immutable versions instead of major-version selectors. - Add verified `integrity` and `crossorigin="anonymous"` attributes to every external script. - Use a restrictive Content Security Policy that permits only explicitly required origins. 4. Intercept Playwright requests and reject all origins not on a narrow allowlist. 5. Prefer an offline browser context after all required assets have been packaged locally. 6. Keep Playwright and Chromium on a tested, security-supported release and verify downloaded browser binaries. 7. Validate remote JSON structures, enforce response-size limits, and fail closed when integrity or schema checks fail. ]]>
