Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Xss Prevention

  • 428 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

xss-prevention is an agent skill that audits and fixes cross-site scripting risks through input sanitization, output encoding, Content Security Policy headers, and secure templating for developers shipping user-generated

About

xss-prevention is a useful-ai-prompts security skill for web applications displaying user-generated content, rich text editors, comment systems, search results, and dynamic HTML templates. It provides Node.js quick-start patterns using DOMPurify and he HTML entity encoding, with four reference guides covering Node.js, Python, React XSS prevention, and Content Security Policy configuration. Best practices emphasize encoding output by default, sanitizing rich HTML, validating URLs, using HTTPOnly cookies, and avoiding innerHTML and eval. Developers reach for xss-prevention before launch when auditing templates, comment forms, or search pages for reflected, stored, or DOM-based XSS vectors across JavaScript, Python, and React stacks.

  • Output encoding rules
  • Content Security Policy templates
  • HTML sanitization patterns
  • DOM XSS mitigation
  • User-generated content hardening

Xss Prevention by the numbers

  • 428 all-time installs (skills.sh)
  • Ranked #533 of 2,203 Security skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill xss-prevention

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs428
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you prevent XSS in user-generated web content?

Audit and fix cross-site scripting risks in web apps, templates, and user-generated content surfaces before public launch.

Who is it for?

Web developers shipping comment systems, rich text editors, search pages, or dynamic templates that render untrusted user input.

Skip if: Server-side authorization bugs, SQL injection, or CSRF-only reviews unrelated to HTML and JavaScript injection in the browser.

When should I use this skill?

The application displays user-generated content, uses rich text editors, renders dynamic HTML, or needs a pre-launch XSS security audit.

What you get

Sanitized rendering code, CSP header configuration, encoded output helpers, and a checklist of fixed XSS vectors across affected templates.

  • sanitized rendering helpers
  • CSP header config
  • XSS audit fixes

By the numbers

  • Includes 4 reference guides: Node.js, Python, React XSS prevention, and CSP
  • Quick-start demonstrates DOMPurify sanitizeHTML and he encodeHTML helpers

Files

SKILL.mdMarkdownGitHub ↗

XSS Prevention

Table of Contents

Overview

Implement comprehensive Cross-Site Scripting (XSS) prevention using input sanitization, output encoding, CSP headers, and secure coding practices.

When to Use

  • User-generated content display
  • Rich text editors
  • Comment systems
  • Search functionality
  • Dynamic HTML generation
  • Template rendering

Quick Start

Minimal working example:

// xss-prevention.js
const createDOMPurify = require("dompurify");
const { JSDOM } = require("jsdom");
const he = require("he");

const window = new JSDOM("").window;
const DOMPurify = createDOMPurify(window);

class XSSPrevention {
  /**
   * HTML Entity Encoding - Safest for text content
   */
  static encodeHTML(str) {
    return he.encode(str, {
      useNamedReferences: true,
      encodeEverything: false,
    });
  }

  /**
   * Sanitize HTML - For rich content
   */
  static sanitizeHTML(dirty) {
    const config = {
      ALLOWED_TAGS: [
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Node.js XSS PreventionNode.js XSS Prevention
Python XSS PreventionPython XSS Prevention
React XSS PreventionReact XSS Prevention
Content Security PolicyContent Security Policy

Best Practices

✅ DO

  • Encode output by default
  • Use templating engines
  • Implement CSP headers
  • Sanitize rich content
  • Validate URLs
  • Use HTTPOnly cookies
  • Regular security testing
  • Use secure frameworks

❌ DON'T

  • Trust user input
  • Use innerHTML directly
  • Skip output encoding
  • Allow inline scripts
  • Use eval()
  • Mix contexts (HTML/JS)

Related skills

How it compares

Use xss-prevention for browser-side injection hardening rather than general OWASP checklists that span unrelated vulnerability classes.

FAQ

What XSS techniques does xss-prevention cover?

xss-prevention implements HTML entity encoding for text, DOMPurify sanitization for rich HTML, URL validation, Content Security Policy headers, HTTPOnly cookies, and framework-specific guidance in Node.js, Python, and React reference guides.

When should xss-prevention run in development?

xss-prevention applies when web apps display user-generated content, rich text editors, comment systems, search functionality, or dynamically generated HTML templates—typically during pre-launch security review of rendering surfaces.

What should xss-prevention avoid in code?

xss-prevention warns against trusting user input, using innerHTML directly, skipping output encoding, allowing inline scripts, calling eval, and mixing HTML and JavaScript contexts without proper encoding or sanitization boundaries.

Securityappsecauditcompliance

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.