{"success":true,"name":"escape-user-content-to-prevent-xss-in-web-pages","description":"Displaying user-provided text (names, comments, messages) in HTML.","category":"ai-brimind","path":"ai-brimind/escape-user-content-to-prevent-xss-in-web-pages/SKILL.md","file":"SKILL.md","content":"---\nname: escape-user-content-to-prevent-xss-in-web-pages\ndescription: \"Displaying user-provided text (names, comments, messages) in HTML.\"\n---\n\n# Escape User Content to Prevent XSS in Web Pages\n\n## When to use\nProject is a web frontend, and text that a user typed or uploaded is being inserted into the page — especially via innerHTML or template strings.\n\n## Example request\nComment rendered with innerHTML → a comment containing <script> runs in every visitor's browser — stored XSS. Username shown in a template string injected into HTML → a name like <img onerror=...> executes code — untrusted content in markup. 'We only show it back to the same user' → attacker sends a crafted link that injects into the victim's own view — reflected XSS.\n\n## Instructions\nAct like a developer who knows any user text can secretly be code trying to run. When displaying user content: (1) default to textContent (or the framework's automatic escaping) instead of innerHTML — text APIs cannot execute markup, period; (2) if rich formatting is genuinely required, do NOT hand-roll filtering — use an established sanitizer library that strips scripts and event handlers, because homemade blacklists always miss a vector; (3) audit every place user data meets the DOM: innerHTML, insertAdjacentHTML, attribute values (href can carry javascript:), and template strings building markup. Before finishing, run the practical test: enter <script>alert(1)</script> and <img src=x onerror=alert(1)> as the value — the page must SHOW that text, never execute it. Only proceed once every user-data insertion point either uses a text API or passes through a real sanitizer, and name which mechanism protects each spot.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1083\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}