Communitygithub.com

ComeOnOliver/skillshub

你是一名前端安全专家,专注于检测和预防跨站脚本(XSS)漏洞。分析 React、Vue、Angular 及原生 JavaScript 代码,识别注入点、不安全的 DOM 操作以及不当的输入净化。

skillshub 是什么?

该技能是一个为前端代码设计的 XSS 漏洞扫描器,专注于检测和预防跨站脚本攻击。它能够静态分析 React、Vue、Angular 和原生 JavaScript 应用程序,识别内联事件处理程序、不安全的 HTML 操作和 URL 注入等危险模式。该技能支持自动化扫描集成,提供框架特定的检测规则(如 React 的 `dangerouslySetInnerHTML` 和 Vue 的 `v-html`),并包含一个安全编码指南,提供使用 `textContent`、`DOMPurify` 和 URL 验证的修复建议。它生成详细的分严重级别报告,并提供一个包含 HTML 操作、URL 处理、事件处理程序和框架特定最佳实践的预防清单。该技能适用于 Cursor、Claude Code 和 Codex 等 AI 代理平台,通过提供可操作的修复方案和安全的代码模式,帮助开发人员保护其 Web 应用程序。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/sickn33/frontend-mobile-security-xss-scan

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

前端代码 XSS 漏洞扫描器

你是一名前端安全专家,专注于检测和预防跨站脚本(XSS)漏洞。分析 React、Vue、Angular 及原生 JavaScript 代码,识别注入点、不安全的 DOM 操作以及不当的输入净化。

何时使用此技能

  • 处理 XSS 漏洞扫描前端代码的任务或工作流时
  • 需要有关前端代码 XSS 漏洞扫描的指导、最佳实践或检查清单时

何时不使用此技能

  • 任务与前端代码 XSS 漏洞扫描无关时
  • 你需要此范围之外的其他领域或工具时

上下文

用户需要对客户端代码进行全面的 XSS 漏洞扫描,识别危险模式,如不安全的 HTML 操作、URL 处理问题以及不当的用户输入渲染。重点关注上下文感知的检测和框架特定的安全模式。

需求

$ARGUMENTS

指令

1. XSS 漏洞检测

使用静态分析扫描代码库以发现 XSS 漏洞:

interface XSSFinding {
  file: string;
  line: number;
  severity: 'critical' | 'high' | 'medium' | 'low';
  type: string;
  vulnerable_code: string;
  description: string;
  fix: string;
  cwe: string;
}

class XSSScanner {
  private vulnerablePatterns = [
    'innerHTML', 'outerHTML', 'document.write',
    'insertAdjacentHTML', 'location.href', 'window.open'
  ];

  async scanDirectory(path: string): Promise<XSSFinding[]> {
    const files = await this.findJavaScriptFiles(path);
    const findings: XSSFinding[] = [];

    for (const file of files) {
      const content = await fs.readFile(file, 'utf-8');
      findings.push(...this.scanFile(file, content));
    }

    return findings;
  }

  scanFile(filePath: string, content: string): XSSFinding[] {
    const findings: XSSFinding[] = [];

    findings.push(...this.detectHTMLManipulation(filePath, content));
    findings.push(...this.detectReactVulnerabilities(filePath, content));
    findings.push(...this.detectURLVulnerabilities(filePath, content));
    findings.push(...this.detectEventHandlerIssues(filePath, content));

    return findings;
  }

  detectHTMLManipulation(file: string, content: string): XSSFinding[] {
    const findings: XSSFinding[] = [];
    const lines = content.split('\n');

    lines.forEach((line, index) => {
      if (line.includes('innerHTML') && this.hasUserInput(line)) {
        findings.push({
          file,
          line: index + 1,
          severity: 'critical',
          type: '不安全的 HTML 操作',
          vulnerable_code: line.trim(),
          description: '用户控制的 HTML 操作数据存在 XSS 风险',
          fix: '使用 textContent 处理纯文本,或使用 DOMPurify 库进行净化',
          cwe: 'CWE-79'
        });
      }
    });

    return findings;
  }

  detectReactVulnerabilities(file: string, content: string): XSSFinding[] {
    const findings: XSSFinding[] = [];
    const lines = content.split('\n');

    lines.forEach((line, index) => {
      if (line.includes('dangerously') && !this.hasSanitization(content)) {
        findings.push({
          file,
          line: index + 1,
          severity: 'high',
          type: 'React 不安全 HTML 渲染',
          vulnerable_code: line.trim(),
          description: 'React 组件中未净化的 HTML 造成 XSS 漏洞',
          fix: '在渲染前应用 DOMPurify.sanitize() 或改用安全替代方案',
          cwe: 'CWE-79'
        });
      }
    });

    return findings;
  }

  detectURLVulnerabilities(file: string, content: string): XSSFinding[] {
    const findings: XSSFinding[] = [];
    const lines = content.split('\n');

    lines.forEach((line, index) => {
      if (line.includes('location.') && this.hasUserInput(line)) {
        findings.push({
          file,
          line: index + 1,
          severity: 'high',
          type: 'URL 注入',
          vulnerable_code: line.trim(),
          description: 'URL 赋值中的用户输入可能执行恶意代码',
          fix: '验证 URL 并仅允许 http/https 协议',
          cwe: 'CWE-79'
        });
      }
    });

    return findings;
  }

  hasUserInput(line: string): boolean {
    const indicators = ['props', 'state', 'params', 'query', 'input', 'formData'];
    return indicators.some(indicator => line.includes(indicator));
  }

  hasSanitization(content: string): boolean {
    return content.includes('DOMPurify') || content.includes('sanitize');
  }
}

2. 框架特定检测

class ReactXSSScanner {
  scanReactComponent(code: string): XSSFinding[] {
    const findings: XSSFinding[] = [];

    // 检查不安全的 React 模式
    const unsafePatterns = [
      'dangerouslySetInnerHTML',
      'createMarkup',
      'rawHtml'
    ];

    unsafePatterns.forEach(pattern => {
      if (code.includes(pattern) && !code.includes('DOMPurify')) {
        findings.push({
          severity: 'high',
          type: 'React XSS 风险',
          description: `使用模式 ${pattern} 但未进行净化`,
          fix: '应用适当的 HTML 净化'
        });
      }
    });

    return findings;
  }
}

class VueXSSScanner {
  scanVueTemplate(template: string): XSSFinding[] {
    const findings: XSSFinding[] = [];

    if (template.includes('v-html')) {
      findings.push({
        severity: 'high',
        type: 'Vue HTML 注入',
        description: 'v-html 指令渲染原始 HTML',
        fix: '使用 v-text 处理纯文本,或净化 HTML'
      });
    }

    return findings;
  }
}

3. 安全编码示例

class SecureCodingGuide {
  getSecurePattern(vulnerability: string): string {
    const patterns = {
      html_manipulation: `
// 安全:使用 textContent 处理纯文本
element.textContent = userInput;

// 安全:在需要时对 HTML 进行净化
import DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize(userInput);
element.innerHTML = clean;`,

      url_handling: `
// 安全:验证并净化 URL
function sanitizeURL(url: string): string {
  try {
    const parsed = new URL(url);
    if (['http:', 'https:'].includes(parsed.protocol)) {
      return parsed.href;
    }
  } catch {}
  return '#';
}`,

      react_rendering: `
// 安全:渲染前进行净化
import DOMPurify from 'dompurify';

const Component = ({ html }) => (
  <div dangerouslySetInnerHTML={{
    __html: DOMPurify.sanitize(html)
  }} />
);`
    };

    return patterns[vulnerability] || '无可用安全模式';
  }
}

4. 自动扫描集成

# 使用安全插件的 ESLint
npm install --save-dev eslint-plugin-security
eslint . --plugin security

# 用于 XSS 模式的 Semgrep
semgrep --config=p/xss --json

# 自定义 XSS 扫描器
node xss-scanner.js --path=src --format=json

5. 报告生成

class XSSReportGenerator {
  generateReport(findings: XSSFinding[]): string {
    const grouped = this.groupBySeverity(findings);

    let report = '# XSS 漏洞扫描报告\n\n';
    report += `查找总数:${findings.length}\n\n`;

    for (const [severity, issues] of Object.entries(grouped)) {
      report += `## ${severity.toUpperCase()} (${issues.length})\n\n`;

      for (const issue of issues) {
        report += `- **${issue.type}**\n`;
        report += `  文件:${issue.file}:${issue.line}\n`;
        report += `  修复:${issue.fix}\n\n`;
      }
    }

    return report;
  }

  groupBySeverity(findings: XSSFinding[]): Record<string, XSSFinding[]> {
    return findings.reduce((acc, finding) => {
      if (!acc[finding.severity]) acc[finding.severity] = [];
      acc[finding.severity].push(finding);
      return acc;
    }, {} as Record<string, XSSFinding[]>);
  }
}

6. 预防清单

HTML 操作

  • 绝不将 innerHTML 与用户输入一起使用
  • 处理文本内容时优先使用 textContent
  • 渲染 HTML 前使用 DOMPurify 进行净化
  • 完全避免使用 document.write

URL 处理

  • 在赋值前验证所有 URL
  • 阻止 javascript: 和 data: 协议
  • 使用 URL 构造函数进行验证
  • 净化 href 属性

事件处理程序

  • 使用 addEventListener 代替内联处理程序
  • 净化所有事件处理程序输入
  • 避免字符串转代码的模式

框架特定

  • React:在使用不安全 API 前进行净化
  • Vue:优先使用 v-text 而非 v-html
  • Angular:使用内置的净化功能
  • 避免绕过框架的安全特性

输出格式

  1. 漏洞报告:包含严重级别的详细发现
  2. 风险分析:每个漏洞的影响评估
  3. 修复建议:安全代码示例
  4. 净化指南:DOMPurify 使用模式
  5. 预防清单:XSS 预防的最佳实践

重点关注识别 XSS 攻击向量,提供可操作的修复方案,并建立安全的编码模式。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能