Skip to content

Practical XSS defense covering input sanitization, output encoding, and Content Security Policy for user-generated content.

CCM score
38 of 100
skills.sh installs
485
GitHub stars
396
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers HTML entity encoding, DOMPurify-based sanitization for rich content, and URL validation for web applications
  • Includes Node.js, Python, React, and Content Security Policy reference guides in a references/ directory
  • Lists explicit do and don't rules, such as avoiding raw innerHTML, eval(), and inline scripts
  • Designed for developers handling comment systems, rich text editors, search results, and template rendering

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill xss-prevention -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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)

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Security, Frontend & UI Code
First seen
Jun 3, 2026

Questions

What does the xss-prevention skill do?

The xss-prevention skill prevents Cross-Site Scripting attacks through input sanitization, output encoding, and Content Security Policy headers. It covers HTML entity encoding for text, DOMPurify sanitization for rich content, and guidance to avoid innerHTML and inline scripts.

When should I use the xss-prevention skill?

Use the xss-prevention skill when your web application displays user-generated content, such as comment systems, rich text editors, search results, or dynamic HTML and template rendering. It guides how xss-prevention handles each of these cases safely.

How do I install the xss-prevention skill?

Run npx -y skills add aj-geddes/useful-ai-prompts --skill xss-prevention -y in your project. After that, the xss-prevention skill is available to your agent for handling XSS defenses in that project.

Which category does xss-prevention belong to and what sets it apart?

The xss-prevention skill sits in the Security category, alongside azure-compliance, entra-agent-id, firebase-security-rules-auditor, security-audit, and cloudflare-one. It focuses narrowly on XSS defenses, with reference guides for Node.js, Python, React and Content Security Policy.

More from aj-geddes/useful-ai-prompts

All 258

Similar to Xss Prevention

More Security