T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:374- Finding
Stored HTML Injection and Cross-Site Scripting in Generated Gradient Previews
- Content
View full analysis
{name}''') html = f''' Gradient Preview body {{ font-family: -apple-system, sans-serif; background: #111; color: #eee; padding: 2rem; }} h1 {{ text-align: center; }} .grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }} .card {{ border-radius: 12px; overflow: hidden; background: #222; }} .swatch {{ height: 160px; }} .info {{ padding: 1rem; font-size: 0.85rem; }} code {{ color: #8be9fd; word-break: break-all; }}{css}Gradient Preview ({len(records)} gradients)
{"".join(cards)}''' ``` ### Technical Analysis Gradient names and CSS definitions originate from command-line input and are persisted in `~/.gradient/data.jsonl`. The preview command retrieves these values and inserts them directly into an HTML document without context-sensitive encoding. The `name` value is inserted into an HTML element body: ```html {name} ``` Consequently, an attacker-controlled name containing HTML elements or event-handler attributes is interpreted as executable markup instead of text. The generated CSS is inserted into both an HTML attribute and an element body: ```html{css}``` Because colors and other gradient components are not validated against strict CSS grammars, specially crafted input can include quotat ...[truncated 2206 chars]- Remediation
View remediation
` and `` content, but it is not a substitute for validating a CSS declaration placed in an attribute. Prefer generating a safe class or validated CSS rule rather than interpolating arbitrary text into `style`. 4. **Consider generating the document with safe DOM APIs.** If client-side rendering is used, assign untrusted values through `textContent`, not `innerHTML`, and set only validated style properties. 5. **Add a restrictive Content Security Policy as defense in depth.** Avoid inline event handlers and consider a policy such as: ```html ``` This should supplement, not replace, proper encoding and validation. 6. **Validate existing persisted records.** Older records in `~/.gradient/data.jsonl` may already contain malicious values. Validate or safely encode them whenever previews are generated, even after input validation is added to creation and update commands. 7. **Add regression tests** covering name ...[truncated 276 chars]
