{"success":true,"name":"neutralize-user-input-before-it-touches-html-queries-or-comm","description":"User-typed text will be shown on a page or used inside a query","category":"ai-brimind","path":"ai-brimind/neutralize-user-input-before-it-touches-html-queries-or-comm/SKILL.md","file":"SKILL.md","content":"---\nname: neutralize-user-input-before-it-touches-html-queries-or-comm\ndescription: \"User-typed text will be shown on a page or used inside a query\"\n---\n\n# Neutralize User Input Before It Touches HTML, Queries, or Commands\n\n## When to use\nThe code takes text a user typed (comment, name, search, bio) and inserts it into rendered HTML, a database query, a file path, or a shell command.\n\n## Example request\nA comment is inserted into the page with raw HTML → a user can type a script tag and run code in other people's browsers; output must be escaped or rendered as plain text (XSS). A search term is glued into a query string with string concatenation → a crafted input can change the whole query; use parameterized queries or the ORM's bindings (SQL/NoSQL injection). A filename from the user is joined into a server path → '../' can escape the folder and read other files; validate and normalize the path (path traversal). User text is passed into a system command → special characters let the user run their own commands; avoid shell calls or use safe argument arrays (command injection).\n\n## Instructions\nAct like a developer who treats every piece of user text as a potential attack payload, not just as content. Before writing the code, trace where the user's text ends up: rendered in HTML, embedded in a database query, used as a file path, placed in a URL, or passed to a command. Name the sink for each flow, because each sink has its own known defense: HTML output needs escaping or safe rendering (never raw HTML insertion), database access needs parameterized queries or the ORM's built-in bindings (never string concatenation), file paths need whitelisting and normalization, and commands need safe APIs instead of shell strings. Check first whether the framework or library already does this protection by default — most template engines escape output and most ORMs parameterize queries — and prefer that built-in mechanism over any custom cleaning function. Never try to 'filter out bad characters' with your own regex; that approach is a known failure pattern. If you cannot tell which sink the data reaches, trace the code until you can, or ask. Only write the code once each user-text flow has a named sink and a named standard defense, and explain why the defense blocks the injection class itself, not just one example attack string.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #512\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}