T09 · Insecure Skill Coding Practices
- Location
scripts/generate_portal.py:275- Finding
Stored HTML and JavaScript Injection in the News Portal Generator
- Content
View full analysis
{source}{summary}''' ``` ### Technical Analysis The generator places remotely supplied article fields directly into an HTML document without contextual output encoding: - `title`, `source`, and `summary` are inserted into HTML element bodies without HTML escaping. - `url` is inserted into an `href` attribute without attribute escaping or URL-scheme validation. - The content is obtained from external news services through `scripts/fetch_news.py`, making these values untrusted. - No Content Security Policy is added to the generated page to reduce the impact of injected scripts. - The external link uses `target="_blank"` without `rel="noopener noreferrer"`. An attacker-controlled title such as the following could introduce executable markup: ```html``` An attacker-controlled URL could use a dangerous scheme: ```text javascript:alert(document.domain) ``` The first payload may execute when the generated portal is opened. The second generally requires the user to click the malicious article link. ### Attack Path 1. An attacker submits a story or other content to one of the configured news sources, or compromises a source response. 2. The source returns an attacker-controlled title, description, source f ...[truncated 1249 chars]
- Remediation
View remediation
... ``` 5. Add a restrictive Content Security Policy appropriate for the generated portal. Avoid inline scripts where possible and move JavaScript into a separately trusted asset. 6. Add automated tests for hostile inputs, including: ```text"> javascript:alert(1) data:text/html, ``` The tests should verify that markup is rendered as text and that dangerous URL schemes are replaced or rejected. ]]>
