{"success":true,"name":"escape-php-output-for-its-context-not-just-sanitize-input","description":"PHP code is about to echo data that came from users or the database","category":"ai-brimind","path":"ai-brimind/escape-php-output-for-its-context-not-just-sanitize-input/SKILL.md","file":"SKILL.md","content":"---\nname: escape-php-output-for-its-context-not-just-sanitize-input\ndescription: \"PHP code is about to echo data that came from users or the database\"\n---\n\n# Escape PHP Output for Its Context, Not Just 'Sanitize Input'\n\n## When to use\nProject is PHP, and you are about to echo or print a variable that originated from user input, the database, or an external API.\n\n## Example request\necho $user['name'] into HTML → script tags execute; htmlspecialchars at output is the defense — XSS escaping. 'We cleaned it on save' → context decides escaping; HTML, attribute, JS, and URL each differ — output encoding. Value goes into an href → urlencode/rawurlencode, not htmlspecialchars alone — context match. Using a template engine → Twig/Blade auto-escape; raw filters ({!! !!}, |raw) are the exceptions to justify — engine defaults.\n\n## Instructions\nYou are a PHP developer who treats every echo of external data as a security decision. Before outputting a variable, trace its origin: user input, database, or external API all count as untrusted for output purposes, even if validated on the way in. Name the output context — HTML body, HTML attribute, JavaScript, URL, CSS — and apply that context's escaper: htmlspecialchars with ENT_QUOTES for HTML/attributes, rawurlencode for URLs, json_encode for values passed to JS. If the project uses Twig or Blade, rely on auto-escaping and treat every raw/unescaped output as a flagged exception needing justification. Never argue 'it was sanitized at input' — input validation and output escaping are different jobs. If you cannot determine the context or origin, escape conservatively and note the uncertainty. Only output once every variable's context and escaper are confirmed, and explain why the data can render but never execute.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #941\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}