mcpField
F
frontend-mobile-security-xss-scan

frontend-mobile-security-xss-scan

github.com/rmyndharisセキュリティ1.9k39 回インストール2 週間前に更新
リポジトリ

frontend-mobile-security-xss-scan について

フロントエンド開発者やセキュリティ担当者向けの XSS 分析スキルです。React、Vue、Angular、vanilla JavaScript の注入箇所や危険な DOM・入力処理を調べ、検出結果と修正案を示します。

主な機能

  1. 01フロントエンドコードの XSS リスク検出
  2. 02危険な DOM 操作と URL 処理の確認
  3. 03フレームワーク別のチェック
  4. 04重要度別の検出結果と修正案の作成
  5. 05安全なコーディングと予防チェックリスト

活用シーン

  1. 01ユーザー入力の画面表示処理のレビュー
  2. 02HTML 操作や URL 設定のリスク確認
  3. 03スキャン結果の重要度別整理と修正案作成

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/rmyndharis/antigravity-skills --skill frontend-mobile-security-xss-scan

インストール後、Claude Code で/frontend-mobile-security-xss-scanを入力して読み込まれたか確認します。

詳細

フロントエンドコード向け XSS 脆弱性スキャナー

クロスサイトスクリプティング(XSS)の脆弱性検出と防止を専門とするフロントエンドセキュリティのスペシャリストです。React、Vue、Angular、Vanilla 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: 'Unsafe HTML manipulation',
          vulnerable_code: line.trim(),
          description: 'User-controlled data in HTML manipulation creates XSS risk',
          fix: 'Use textContent for plain text or sanitize with DOMPurify library',
          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 unsafe HTML rendering',
          vulnerable_code: line.trim(),
          description: 'Unsanitized HTML in React component creates XSS vulnerability',
          fix: 'Apply DOMPurify.sanitize() before rendering or use safe alternatives',
          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 injection',
          vulnerable_code: line.trim(),
          description: 'User input in URL assignment can execute malicious code',
          fix: 'Validate URLs and enforce http/https protocols only',
          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[] = [];

    // Check for unsafe React patterns
    const unsafePatterns = [
      'dangerouslySetInnerHTML',
      'createMarkup',
      'rawHtml'
    ];

    unsafePatterns.forEach(pattern => {
      if (code.includes(pattern) && !code.includes('DOMPurify')) {
        findings.push({
          severity: 'high',
          type: 'React XSS risk',
          description: `Pattern ${pattern} used without sanitization`,
          fix: 'Apply proper HTML sanitization'
        });
      }
    });

    return findings;
  }
}

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

    if (template.includes('v-html')) {
      findings.push({
        severity: 'high',
        type: 'Vue HTML injection',
        description: 'v-html directive renders raw HTML',
        fix: 'Use v-text for plain text or sanitize HTML'
      });
    }

    return findings;
  }
}
3. 安全なコーディング例
class SecureCodingGuide {
  getSecurePattern(vulnerability: string): string {
    const patterns = {
      html_manipulation: `
// SECURE: Use textContent for plain text
element.textContent = userInput;

// SECURE: Sanitize HTML when needed
import DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize(userInput);
element.innerHTML = clean;`,

      url_handling: `
// SECURE: Validate and sanitize URLs
function sanitizeURL(url: string): string {
  try {
    const parsed = new URL(url);
    if (['http:', 'https:'].includes(parsed.protocol)) {
      return parsed.href;
    }
  } catch {}
  return '#';
}`,

      react_rendering: `
// SECURE: Sanitize before rendering
import DOMPurify from 'dompurify';

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

    return patterns[vulnerability] || 'No secure pattern available';
  }
}
4. 自動スキャンの統合
# ESLint with security plugin
npm install --save-dev eslint-plugin-security
eslint . --plugin security

# Semgrep for XSS patterns
semgrep --config=p/xss --json

# Custom XSS scanner
node xss-scanner.js --path=src --format=json
5. レポートの生成
class XSSReportGenerator {
  generateReport(findings: XSSFinding[]): string {
    const grouped = this.groupBySeverity(findings);

    let report = '# XSS Vulnerability Scan Report\n\n';
    report += `Total Findings: ${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 += `  File: ${issue.file}:${issue.line}\n`;
        report += `  Fix: ${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-html よりも v-text を優先してください
  • Angular:組み込みのサニタイズ機能を使用してください
  • フレームワークのセキュリティ機能を回避しないでください

出力形式

  1. 脆弱性レポート:深刻度を含む詳細な検出結果
  2. リスク分析:各脆弱性の影響評価
  3. 修正の推奨事項:安全なコード例
  4. サニタイズガイド:DOMPurify の使用パターン
  5. 防止チェックリスト:XSS 防止のベストプラクティス

XSS 攻撃ベクトルの特定、実行可能な修正策の提示、安全なコーディングパターンの確立に重点を置いてください。

コメント