T09 · Insecure Skill Coding Practices
- Location
prompt_browse.py:366- Finding
Stored JavaScript Injection Through Unvalidated Imported Prompt IDs
- Content
View full analysis
{html.escape(tag)}' for tag in tags) html_content += f"""{html.escape(name)}{stars}ID:\n' if tags: ...[truncated 3037 chars]{html.escape(prompt_id)}By: {html.escape(author)} Used: {usage_count} times """ if models: html_content += f' Models: {html.escape(models)}\n' html_content += '- Remediation
View remediation
' f'Copy to Clipboard\n' ) ``` Register the event handler separately: ```javascript document.querySelectorAll('.copy-btn').forEach(button => { button.addEventListener('click', event => { copyPrompt(event.currentTarget.dataset.promptId, event.currentTarget); }); }); ``` 3. **Avoid searching IDs through unrestricted text content** Associate each card with an exact, validated `data-prompt-id` value and select the matching card by that value. This prevents ambiguous matches and separates data from executable code. 4. **Validate the complete import schema** Before persistence, verify that each prompt is an object and that fields such as `id`, `name`, `text`, `category`, `tags`, `rating`, and `usage_count` have expected types and reasonable size limits. 5. **Apply a restrictive Content Security Policy** Generated pages should prohibit inline scripts and unnecessary network access. Move JavaScript into a separate local file or use a nonce/hash-based policy if a standalone file is required. CSP should be treated as defense in depth rather than a replacement for safe construction. 6. **Add regression tests** Test imported IDs containing single quotes, double quotes, angle brackets, backslashes, newlines, and JavaScript syntax. Verify that generated HTML contains no executable attacker-controlled content and that legitimate copy functiona ...[truncated 29 chars]
