KinetixBridge

Security Architecture, Checksums & Live Source Code Audit

KinetixBridge is engineered on a Zero-Blind-Trust principle: publishers should never install opaque scripts, remote-executing Service Workers, or plugins from unverified external domains. Every client asset is served directly from https://kinetixbridge.com, pinned with browser-enforced Subresource Integrity (SHA-384), and published unminified below for line-by-line inspection.

1. Cryptographic Checksums & Same-Domain Downloads (v1.3.2)

2. Four Technical Guarantees

3. Full Unminified Source: Self-Hosted Static Service Worker (/sw.js)

'use strict';
// KinetixBridge Auditable Web Push Service Worker (v1.3.2)
// SECURITY GUARANTEE: Zero 'fetch' listeners (never intercepts page/network traffic), zero 'importScripts', zero cookie access.
const EDGE_ORIGIN = "https://kinetixbridge.com";

self.addEventListener('install', function () {
  self.skipWaiting();
});

self.addEventListener('activate', function (event) {
  event.waitUntil(self.clients.claim());
});

self.addEventListener('push', function (event) {
  let payload = { title: 'Update', body: '', icon: null, image: null, data: {} };
  if (event.data) {
    try {
      payload = Object.assign(payload, event.data.json());
    } catch (err) {
      payload.body = event.data.text();
    }
  }
  const opts = {
    body: payload.body || '',
    data: payload.data || {},
    renotify: false
  };
  if (payload.icon) opts.icon = payload.icon;
  if (payload.image) opts.image = payload.image;
  event.waitUntil(self.registration.showNotification(payload.title || 'Notification', opts));
});

self.addEventListener('notificationclick', function (event) {
  event.notification.close();
  const data = event.notification.data || {};
  const rawPath = data.click_path || '/';
  let targetUrl = EDGE_ORIGIN;
  try {
    targetUrl = rawPath.startsWith('http://') || rawPath.startsWith('https://')
      ? rawPath
      : new URL(rawPath, EDGE_ORIGIN).href;
  } catch (err) {
    targetUrl = EDGE_ORIGIN;
  }
  event.waitUntil(
    self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (winClients) {
      if (self.clients.openWindow) {
        return self.clients.openWindow(targetUrl);
      }
      if (winClients.length > 0 && 'focus' in winClients[0]) {
        winClients[0].navigate(targetUrl);
        return winClients[0].focus();
      }
    })
  );
});

4. Full Unminified Source: WordPress Plugin (kinetixbridge-push.php)

<?php
/**
 * Plugin Name: KinetixBridge Web Push & Ad-Gap
 * Plugin URI: https://kinetixbridge.com/security
 * Description: Lightweight W3C VAPID Web Push notifications and optional unsold Ad-Gap recovery. Zero customer database access, zero cookies, Subresource Integrity (SRI) pinned, and static zero-fetch Service Worker.
 * Version: 1.3.2
 * Requires at least: 5.8
 * Requires PHP: 7.4
 * Author: KinetixBridge Engineering (Trispheronex)
 * Author URI: https://kinetixbridge.com/
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

function kinetixbridge_register_settings() {
    register_setting( 'kinetixbridge_settings_group', 'kinetixbridge_site_key', array(
        'type'              => 'string',
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => '',
    ) );
    register_setting( 'kinetixbridge_settings_group', 'kinetixbridge_auto_prompt', array(
        'type'              => 'string',
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => 'true',
    ) );
}
add_action( 'admin_init', 'kinetixbridge_register_settings' );

function kinetixbridge_admin_menu() {
    add_options_page(
        'KinetixBridge Web Push',
        'KinetixBridge Push',
        'manage_options',
        'kinetixbridge-push',
        'kinetixbridge_render_settings_page'
    );
}
add_action( 'admin_menu', 'kinetixbridge_admin_menu' );

function kinetixbridge_render_settings_page() {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    $site_key    = get_option( 'kinetixbridge_site_key', '' );
    $auto_prompt = get_option( 'kinetixbridge_auto_prompt', 'true' );
    ?>
    <div class="wrap">
        <h1>KinetixBridge Web Push &amp; Unsold Ad-Gap</h1>
        <p>Enter your public <code>pub_...</code> key from <a href="https://kinetixbridge.com/" target="_blank" rel="noopener noreferrer">https://kinetixbridge.com</a>. Never enter your secret <code>tk_live_...</code> key in WordPress.</p>
        <form method="post" action="options.php">
            <?php settings_fields( 'kinetixbridge_settings_group' ); ?>
            <table class="form-table" role="presentation">
                <tr>
                    <th scope="row"><label for="kinetixbridge_site_key">Public Site Key (pub_...)</label></th>
                    <td><input name="kinetixbridge_site_key" type="text" id="kinetixbridge_site_key" value="<?php echo esc_attr( $site_key ); ?>" class="regular-text" placeholder="pub_..." /></td>
                </tr>
                <tr>
                    <th scope="row"><label for="kinetixbridge_auto_prompt">Browser Opt-In Prompt</label></th>
                    <td>
                        <select name="kinetixbridge_auto_prompt" id="kinetixbridge_auto_prompt">
                            <option value="true" <?php selected( $auto_prompt, 'true' ); ?>>Enabled (Web Push + Optional Ad-Gap)</option>
                            <option value="false" <?php selected( $auto_prompt, 'false' ); ?>>Disabled (Silent Ad-Gap Only)</option>
                        </select>
                    </td>
                </tr>
            </table>
            <?php submit_button( 'Save KinetixBridge Settings' ); ?>
        </form>
        <p>Optional shortcode for unsold ad-gap container: <code>[kinetixbridge_ad_gap]</code></p>
    </div>
    <?php
}

// Serve static, self-contained Service Worker at /?kinetixbridge_sw=1 (Zero fetch listeners, zero remote importScripts)
function kinetixbridge_serve_static_sw() {
    if ( isset( $_GET['kinetixbridge_sw'] ) && '1' === $_GET['kinetixbridge_sw'] ) {
        nocache_headers();
        header( 'Content-Type: application/javascript; charset=utf-8' );
        header( 'Service-Worker-Allowed: /' );
        header( 'X-Content-Type-Options: nosniff' );
        echo "'use strict';\n";
        echo "const EDGE_ORIGIN = 'https://kinetixbridge.com';\n";
        echo "self.addEventListener('install', function () { self.skipWaiting(); });\n";
        echo "self.addEventListener('activate', function (e) { e.waitUntil(self.clients.claim()); });\n";
        echo "self.addEventListener('push', function (e) {\n";
        echo "  var p = { title: 'Update', body: '', icon: null, image: null, data: {} };\n";
        echo "  if (e.data) { try { p = Object.assign(p, e.data.json()); } catch (err) { p.body = e.data.text(); } }\n";
        echo "  var o = { body: p.body || '', data: p.data || {}, renotify: false };\n";
        echo "  if (p.icon) o.icon = p.icon; if (p.image) o.image = p.image;\n";
        echo "  e.waitUntil(self.registration.showNotification(p.title || 'Notification', o));\n";
        echo "});\n";
        echo "self.addEventListener('notificationclick', function (e) {\n";
        echo "  e.notification.close();\n";
        echo "  var raw = (e.notification.data && e.notification.data.click_path) ? e.notification.data.click_path : '/';\n";
        echo "  var u = EDGE_ORIGIN; try { u = (raw.indexOf('http') === 0) ? raw : new URL(raw, EDGE_ORIGIN).href; } catch (err) {}\n";
        echo "  e.waitUntil(self.clients.openWindow ? self.clients.openWindow(u) : Promise.resolve());\n";
        echo "});\n";
        exit;
    }
}
add_action( 'init', 'kinetixbridge_serve_static_sw', 1 );

function kinetixbridge_inject_head_sdk() {
    if ( is_admin() ) {
        return;
    }
    $site_key = trim( (string) get_option( 'kinetixbridge_site_key', '' ) );
    if ( strlen( $site_key ) < 8 || strpos( $site_key, 'pub_' ) !== 0 ) {
        return;
    }
    $auto_prompt = ( 'false' === get_option( 'kinetixbridge_auto_prompt', 'true' ) ) ? 'false' : 'true';
    $sw_url      = home_url( '/?kinetixbridge_sw=1' );
    printf(
        '<script src="%s" integrity="%s" crossorigin="anonymous" data-site-key="%s" data-sw-path="%s" data-auto-prompt="%s" async></script>' . "\n",
        esc_url( 'https://kinetixbridge.com/sdk-v1.3.2.js' ),
        esc_attr( 'sha384-LOPhcR2qXnYBxInZCBnRd9+BUw20F9oFWaJyJqdIiyWObJcfvvvkVuQ7tMXOngUV' ),
        esc_attr( $site_key ),
        esc_attr( wp_make_link_relative( $sw_url ) ),
        esc_attr( $auto_prompt )
    );
}
add_action( 'wp_head', 'kinetixbridge_inject_head_sdk', 20 );

function kinetixbridge_gap_shortcode() {
    return '<div data-ad-gap-slot="wp-shortcode-slot"></div>';
}
add_shortcode( 'kinetixbridge_ad_gap', 'kinetixbridge_gap_shortcode' );

5. Full Unminified Source: Browser SDK (/sdk-v1.3.2.js)

(function () {
  'use strict';
  const scriptEl = document.currentScript || document.querySelector('script[data-site-key]');
  if (!scriptEl) return;

  const siteKey = (scriptEl.getAttribute('data-site-key') || '').trim();
  if (siteKey.length < 8) return;

  const edgeOrigin = new URL(scriptEl.src, window.location.href).origin;
  const swPath = scriptEl.getAttribute('data-sw-path') || '/sw.js';
  const gapSelector = scriptEl.getAttribute('data-gap-selector') || '[data-ad-gap-slot]';
  const autoPrompt = scriptEl.getAttribute('data-auto-prompt') !== 'false';

  function toUrlBase64ToUint8Array(base64String) {
    const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
    const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
    const rawData = window.atob(base64);
    const outputArray = new Uint8Array(rawData.length);
    for (let i = 0; i < rawData.length; ++i) {
      outputArray[i] = rawData.charCodeAt(i);
    }
    return outputArray;
  }

  function normalizeB64Url(str) {
    return (str || '').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
  }

  function getVisitorHash() {
    const storageKey = '_am_vhash_v1';
    try {
      let existing = window.localStorage.getItem(storageKey);
      if (existing && /^[A-Za-z0-9_-]{12,64}$/.test(existing)) return existing;
      const bytes = new Uint8Array(18);
      window.crypto.getRandomValues(bytes);
      let token = '';
      const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-';
      for (let i = 0; i < bytes.length; i++) token += chars[bytes[i] % chars.length];
      window.localStorage.setItem(storageKey, token);
      return token;
    } catch (e) {
      return 'anon_' + Math.random().toString(36).slice(2, 14) + Math.random().toString(36).slice(2, 10);
    }
  }

  function isSlotEmpty(el) {
    if (!el || el.getAttribute('data-am-filled') === '1') return false;
    const hasIframe = el.querySelector('iframe');
    if (hasIframe && hasIframe.offsetHeight > 5) return false;
    const hasImg = el.querySelector('img');
    if (hasImg && hasImg.offsetHeight > 5) return false;
    return el.offsetHeight <= 10 || el.children.length === 0;
  }

  function renderGapCreative(slotEl, creative) {
    slotEl.textContent = '';
    slotEl.setAttribute('data-am-filled', '1');

    const link = document.createElement('a');
    link.href = new URL(creative.click_path, edgeOrigin).href;
    link.target = '_blank';
    link.rel = 'noopener noreferrer sponsored';
    link.style.cssText = 'display:flex;align-items:center;gap:12px;padding:12px 14px;border:1px solid #e2e8f0;border-radius:10px;background:#ffffff;color:#0f172a;text-decoration:none;font-family:system-ui,-apple-system,sans-serif;max-width:100%;box-sizing:border-box;box-shadow:0 2px 8px rgba(15,23,42,0.06);';

    const mediaUrl = creative.icon_url || creative.image_url;
    if (mediaUrl && (mediaUrl.startsWith('https://') || mediaUrl.startsWith('http://'))) {
      const img = document.createElement('img');
      img.src = mediaUrl;
      img.alt = '';
      img.style.cssText = 'width:52px;height:52px;object-fit:cover;border-radius:8px;flex-shrink:0;';
      link.appendChild(img);
    }

    const textWrap = document.createElement('div');
    textWrap.style.cssText = 'flex:1;min-width:0;';

    const badge = document.createElement('div');
    badge.textContent = 'Sponsored';
    badge.style.cssText = 'font-size:10px;text-transform:uppercase;letter-spacing:0.06em;color:#64748b;margin-bottom:2px;';

    const title = document.createElement('div');
    title.textContent = creative.title || '';
    title.style.cssText = 'font-size:14px;font-weight:600;color:#0f172a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;';

    const body = document.createElement('div');
    body.textContent = creative.body || '';
    body.style.cssText = 'font-size:12px;color:#475569;margin-top:2px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;';

    textWrap.appendChild(badge);
    textWrap.appendChild(title);
    textWrap.appendChild(body);
    link.appendChild(textWrap);
    slotEl.appendChild(link);
  }

  async function runTimeoutCatcher(timeoutMs) {
    const waitMs = Math.max(250, Number(timeoutMs) || 800);
    window.setTimeout(async function () {
      const slots = Array.prototype.slice.call(document.querySelectorAll(gapSelector)).filter(isSlotEmpty);
      if (slots.length === 0) return;
      for (let i = 0; i < slots.length; i++) {
        try {
          const resp = await window.fetch(edgeOrigin + '/v1/public/gap-bid', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
              public_site_key: siteKey,
              visitor_hash: getVisitorHash(),
              elapsed_timeout_ms: waitMs
            })
          });
          if (!resp.ok) continue;
          const data = await resp.json();
          if (data && data.fill && data.creative) {
            renderGapCreative(slots[i], data.creative);
          }
        } catch (err) {}
      }
    }, waitMs);
  }

  async function syncPushSubscription(vapidPublicKey) {
    if (!('serviceWorker' in navigator) || !('PushManager' in window)) return false;
    const reg = await navigator.serviceWorker.register(swPath, { scope: '/' });
    await navigator.serviceWorker.ready;
    let sub = await reg.pushManager.getSubscription();
    if (!sub) {
      sub = await reg.pushManager.subscribe({
        userVisibleOnly: true,
        applicationServerKey: toUrlBase64ToUint8Array(vapidPublicKey)
      });
    }
    const subJson = sub.toJSON();
    if (!subJson || !subJson.keys) return false;
    const tz = (Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC');
    const res = await window.fetch(edgeOrigin + '/v1/public/subscribe', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        public_site_key: siteKey,
        endpoint: subJson.endpoint,
        keys: {
          p256dh: normalizeB64Url(subJson.keys.p256dh),
          auth: normalizeB64Url(subJson.keys.auth)
        },
        timezone: tz
      })
    });
    return res.ok;
  }

  function mountOptInPrompt(cfg) {
    if (!('Notification' in window) || !('serviceWorker' in navigator) || !('PushManager' in window)) return;
    if (Notification.permission === 'granted') {
      syncPushSubscription(cfg.vapid_public_key).catch(function () {});
      return;
    }
    if (Notification.permission === 'denied' || !autoPrompt) return;
    try {
      if (window.sessionStorage.getItem('_am_prompt_dismissed') === '1') return;
    } catch (e) {}

    const bar = document.createElement('div');
    bar.style.cssText = 'position:fixed;bottom:18px;right:18px;z-index:2147483646;width:320px;max-width:calc(100vw - 36px);background:#0f172a;color:#f8fafc;padding:16px;border-radius:12px;box-shadow:0 12px 28px rgba(15,23,42,0.32);font-family:system-ui,-apple-system,sans-serif;';

    const heading = document.createElement('div');
    heading.textContent = 'Stay updated with instant alerts';
    heading.style.cssText = 'font-size:14px;font-weight:600;margin-bottom:4px;';

    const subtext = document.createElement('div');
    subtext.textContent = 'Get real-time updates delivered straight to your device. Unsubscribe anytime.';
    subtext.style.cssText = 'font-size:12px;color:#cbd5e1;line-height:1.4;margin-bottom:12px;';

    const btnRow = document.createElement('div');
    btnRow.style.cssText = 'display:flex;gap:8px;justify-content:flex-end;';

    const laterBtn = document.createElement('button');
    laterBtn.type = 'button';
    laterBtn.textContent = 'Not now';
    laterBtn.style.cssText = 'background:transparent;border:1px solid #334155;color:#cbd5e1;padding:6px 12px;border-radius:7px;font-size:12px;cursor:pointer;';

    const allowBtn = document.createElement('button');
    allowBtn.type = 'button';
    allowBtn.textContent = 'Allow';
    allowBtn.style.cssText = 'background:#38bdf8;border:none;color:#0f172a;font-weight:600;padding:6px 14px;border-radius:7px;font-size:12px;cursor:pointer;';

    laterBtn.onclick = function () {
      try { window.sessionStorage.setItem('_am_prompt_dismissed', '1'); } catch (e) {}
      bar.remove();
    };

    allowBtn.onclick = async function () {
      allowBtn.disabled = true;
      try {
        const perm = await Notification.requestPermission();
        if (perm === 'granted') {
          await syncPushSubscription(cfg.vapid_public_key);
        }
      } catch (err) {}
      bar.remove();
    };

    btnRow.appendChild(laterBtn);
    btnRow.appendChild(allowBtn);
    bar.appendChild(heading);
    bar.appendChild(subtext);
    bar.appendChild(btnRow);

    if (cfg.viral_badge_enabled) {
      const credit = document.createElement('a');
      credit.href = edgeOrigin + '/';
      credit.target = '_blank';
      credit.rel = 'noopener noreferrer';
      credit.textContent = 'Powered by KinetixBridge — Open-Audit Web Push';
      credit.style.cssText = 'display:block;margin-top:10px;font-size:10px;color:#64748b;text-align:right;text-decoration:none;';
      bar.appendChild(credit);
    }

    document.body.appendChild(bar);
  }

  async function boot() {
    try {
      const resp = await window.fetch(edgeOrigin + '/v1/public/config/' + encodeURIComponent(siteKey));
      if (!resp.ok) return;
      const cfg = await resp.json();
      if (cfg.widget_type !== 'companion_backfill') {
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () { mountOptInPrompt(cfg); });
        } else {
          mountOptInPrompt(cfg);
        }
      }
      runTimeoutCatcher(cfg.timeout_threshold_ms);
    } catch (err) {}
  }

  boot();
})();