xss-prevention by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill xss-prevention通过输入净化、输出编码、CSP 标头和安全编码实践,实现全面的跨站脚本攻击防护。
最小工作示例:
// 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 实体编码 - 对文本内容最安全
*/
static encodeHTML(str) {
return he.encode(str, {
useNamedReferences: true,
encodeEverything: false,
});
}
/**
* 净化 HTML - 用于富内容
*/
static sanitizeHTML(dirty) {
const config = {
ALLOWED_TAGS: [
// ... (完整实现请参阅参考指南)
references/ 目录下的详细实现:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 指南 | 内容 |
|---|---|
| Node.js XSS 防护 | Node.js XSS 防护 |
| Python XSS 防护 | Python XSS 防护 |
| React XSS 防护 | React XSS 防护 |
| 内容安全策略 | 内容安全策略 |
每周安装量
103
代码仓库
GitHub 星标数
116
首次出现
2026年1月21日
安全审计
安装于
opencode86
gemini-cli85
claude-code83
codex82
cursor78
github-copilot67
Implement comprehensive Cross-Site Scripting (XSS) prevention using input sanitization, output encoding, CSP headers, and secure coding practices.
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)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Node.js XSS Prevention | Node.js XSS Prevention |
| Python XSS Prevention | Python XSS Prevention |
| React XSS Prevention | React XSS Prevention |
| Content Security Policy | Content Security Policy |
Weekly Installs
103
Repository
GitHub Stars
116
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode86
gemini-cli85
claude-code83
codex82
cursor78
github-copilot67
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
37,500 周安装
Google Drive 批量下载文件夹工具 - 一键下载云端文件与文档转PDF
7,700 周安装
Google Sheets 工作表比较工具 | 自动识别数据差异 | Google Workspace CLI 技能
7,600 周安装
Google Workspace CLI 事件订阅续订工具 - gws-events-renew 命令详解与使用教程
7,600 周安装
数据叙事技能:将数据转化为决策故事,驱动业务行动 | 数据分析与可视化
7,600 周安装
Google Workspace CLI 文件宣布工具:在聊天空间快速分享云端硬盘文件
7,600 周安装
Google Workspace CLI gws-chat-send 命令:向聊天空间发送消息 | 命令行工具
7,600 周安装