T09 · Insecure Skill Coding Practices
- Location
scripts/ccpa-check.py:316- Finding
Unescaped Cloud-Controlled Data in Generated HTML Report
- Content
View full analysis
= 80 else "#ff9800" if score >= 60 else "#f44336" rows = "" current_cat = "" for r in items: if r.get("category") != current_cat: current_cat = r.get("category", "") rows += f'{current_cat}\n' icon = "✅" if r.get("passed") else "❌" cls = "pass" if r.get("passed") else "fail" rec = r.get("recommendation") or "Keep it up" rows += f"""{icon}{r.get('name')}{r.get('legal_ref') or ''}{cls.upper()}{rec}\n""" ``` ### Technical Analysis The `category`, `name`, `legal_ref`, and `recommendation` values are taken from the cloud evaluation response and concatenated directly into an HTML document. The code does not perform HTML escaping, sanitization, or type validation before placing these values into element content. Consequently, values containing HTML elements or event handlers are interpreted as markup rather than displayed as text. For example, a malicious recommendation value could contain: ```html``` Exploitation requires control over, or compromise of, the response returned by the configured cloud service. Ordinary network spoofing is constrained by HTTPS certificate validation and the pinned hostname, but compromise of the service, its data source, or a trusted TLS endpoint could still supply a malicious response. The generated report also lacks a restrictive Content Security Policy that could mitigate injected active content. ### Attack Path 1. The user invokes the Skill ...[truncated 1915 chars]
- Remediation
View remediation
' f'{category}' f'\n' ) rows += ( f'' f'{icon}' f'{name}' f'{legal_ref}' f'{cls.upper()}' f'{recommendation}' f'\n' ) ``` 2. Validate the cloud response schema before rendering: - Require `items` to be a list. - Require textual fields to be strings. - Enforce reasonable maximum lengths. - Reject unexpected structures rather than coercing them into report content. - Validate numeric summary fields and the `passed` value against expected types and ranges. 3. Add a restrictive Content Security Policy to generated reports as defense in depth: ```html ``` This should not replace output escaping, but it reduces the impact of a missed injection sink. 4. Add regression tests using payloads containing tags, quotes, event handlers, and encoded markup. Verify that generated reports contain escaped text such as `<script>` and never executable markup. 5. Treat all cloud-returned report fields as untrusted, even though the destination hostname is fixed and HTTPS certificate validation is enabled. ]]>
