Skip to content

2001105254-netizen/RacePulsePH / .agents/skills/modern-web-guidance

modern-web-guidance

Flagged

Search tool for modern web development best practices. MANDATORY: Execute FIRST for all HTML/CSS and clientside JS tasks. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns. Trigger immediately for: modals/dialogs/popovers, tables, dark mode, anchor positioning, container queries, view transitions, scroll-driven animations, parallax/reveals, forms, validation, autofill, accessibility, custom selects, scrollbars, CWV (LCP, INP, CLS), content-visibility, fetch priority, image optimization, security, passkeys, HTML sanitization, web components, dates/timezones, built-in AI, WebAssembly, standard HTML/CSS/DOM in frameworks, etc. DO NOT trigger for: backend (SQL, ORMs, API routes), infra/scripts (CI/CD, Docker, Actions, Python/Go, Git), or tooling/trivial (Vite, tsconfig, ESLint, tests, copy/renames, 3P docs), etc.

FileKindSize
SKILL.mdskill md9.6 KB
guides/accessibility/accessibility.mdmarkdown50.5 KB
guides/accessibility/accessible-error-announcement.mdmarkdown13.3 KB
guides/accessibility/accessible-generated-content.mdmarkdown2.2 KB
guides/accessibility/respect-os-text-scale.mdmarkdown7.1 KB
guides/built-in-ai/language-detection.mdmarkdown3.6 KB
guides/built-in-ai/language-model.mdmarkdown19.0 KB
guides/built-in-ai/prompt-api.mdmarkdown19.0 KB
guides/built-in-ai/summarizer.mdmarkdown6.2 KB
guides/built-in-ai/translator.mdmarkdown7.2 KB
guides/css/animate-to-intrinsic-sizes.mdmarkdown5.7 KB
guides/css/atrule-support-conditionals.mdmarkdown5.6 KB
guides/css/calculate-with-intrinsic-sizes.mdmarkdown10.4 KB
guides/css/child-state-based-styling.mdmarkdown4.9 KB
guides/css/content-based-styling.mdmarkdown5.2 KB
guides/css/css-layout.mdmarkdown21.2 KB
guides/css/css.mdmarkdown12.3 KB
guides/css/design-token-reactivity.mdmarkdown5.8 KB
guides/css/dynamic-sibling-styling.mdmarkdown3.6 KB
guides/css/fluid-scaling.mdmarkdown3.2 KB
guides/css/individual-transform-properties.mdmarkdown3.6 KB
guides/css/overflow-clipping-control.mdmarkdown8.1 KB
guides/css/reduce-style-repetition.mdmarkdown3.9 KB
guides/css/responsive-design.mdmarkdown1.8 KB
guides/css/selector-atrule-combinations.mdmarkdown3.6 KB
guides/css/size-aware-styling.mdmarkdown2.9 KB
guides/css/style-parent-with-has.mdmarkdown13.6 KB
guides/css/usage-aware-component-variations.mdmarkdown5.1 KB
guides/forms/animated-select-picker.mdmarkdown8.5 KB
guides/forms/autofill-address-form.mdmarkdown4.9 KB
guides/forms/autofill-highlight-inputs.mdmarkdown3.5 KB
guides/forms/autofill-payment-form.mdmarkdown9.7 KB
guides/forms/autofill-sign-in-form.mdmarkdown10.5 KB
guides/forms/autofill-sign-up-form.mdmarkdown11.6 KB
guides/forms/brand-consistent-forms.mdmarkdown8.4 KB
guides/forms/branded-select-styling.mdmarkdown5.6 KB
guides/forms/custom-select-picker-layouts.mdmarkdown7.8 KB
guides/forms/form-fields-automatically-fit-contents.mdmarkdown5.9 KB
guides/forms/forms.mdmarkdown18.9 KB
guides/forms/ime-safe-enter-submit.mdmarkdown6.3 KB
guides/forms/required-field-feedback.mdmarkdown13.9 KB
guides/forms/rich-media-picker.mdmarkdown10.5 KB
guides/forms/select-menu-interaction.mdmarkdown12.9 KB
guides/forms/slider.mdmarkdown6.5 KB
guides/forms/sms-otp-form.mdmarkdown12.5 KB
guides/forms/switch.mdmarkdown2.5 KB
guides/forms/validate-input-after-interaction.mdmarkdown17.2 KB
guides/html/accessible-web-components.mdmarkdown5.1 KB
guides/html/custom-elements.mdmarkdown9.3 KB
guides/html/form-associated-custom-elements.mdmarkdown4.9 KB
guides/html/html.mdmarkdown20.8 KB
guides/html/prerendering-custom-elements.mdmarkdown3.6 KB
guides/html/shadow-dom.mdmarkdown3.8 KB
guides/html/styling-web-components.mdmarkdown8.7 KB
guides/html/web-components.mdmarkdown6.6 KB
guides/js/calculate-event-differentials.mdmarkdown8.3 KB
guides/js/capture-location-agnostic-data.mdmarkdown9.7 KB
guides/js/coordinate-global-events.mdmarkdown4.0 KB
guides/js/sort-high-precision-timestamps.mdmarkdown6.6 KB
guides/js/support-global-calendar-systems.mdmarkdown5.8 KB
guides/performance/batch-analytics-events.mdmarkdown6.4 KB
guides/performance/break-up-long-tasks.mdmarkdown2.2 KB
guides/performance/calculate-total-foreground-time.mdmarkdown2.9 KB
guides/performance/conditional-async-dependencies.mdmarkdown5.3 KB
guides/performance/defer-rendering-heavy-content.mdmarkdown6.3 KB
guides/performance/defer-work-until-scroll-ends.mdmarkdown3.3 KB
guides/performance/deliver-optimized-decorative-images.mdmarkdown2.8 KB
guides/performance/deprioritize-background-fetches.mdmarkdown1.8 KB
guides/performance/detect-initial-visibility-state.mdmarkdown4.6 KB
guides/performance/efficient-background-processing.mdmarkdown5.0 KB
guides/performance/faster-spa-view-transitions.mdmarkdown3.6 KB
guides/performance/flicker-free-client-side-ab-testing.mdmarkdown8.5 KB
guides/performance/full-session-analytics.mdmarkdown5.7 KB
guides/performance/identify-heavy-scripts.mdmarkdown4.2 KB
guides/performance/identify-inp-causes.mdmarkdown8.7 KB
guides/performance/improve-next-page-load-performance.mdmarkdown7.2 KB
guides/performance/interaction-paint-timing.mdmarkdown11.2 KB
guides/performance/interactions-in-complex-layouts.mdmarkdown3.4 KB
guides/performance/lazy-load-video-and-audio.mdmarkdown9.3 KB
guides/performance/optimize-image-priority.mdmarkdown4.5 KB
guides/performance/optimize-preload-priority.mdmarkdown3.3 KB
guides/performance/optimize-script-priority.mdmarkdown2.6 KB
guides/performance/out-of-order-html-streaming.mdmarkdown12.1 KB
guides/performance/performance.mdmarkdown20.6 KB
guides/performance/resolution-optimized-pseudo-elements.mdmarkdown2.3 KB
guides/performance/schedule-tasks-by-priority.mdmarkdown2.3 KB
guides/privacy/privacy.mdmarkdown11.0 KB
guides/pwa/install-web-app.mdmarkdown15.0 KB
guides/pwa/migrate-web-app-origin.mdmarkdown3.6 KB
guides/security/client-side-encryption.mdmarkdown14.8 KB
guides/security/digital-signatures.mdmarkdown9.9 KB
guides/security/local-network-access.mdmarkdown12.3 KB
guides/security/passkey-authentication.mdmarkdown11.5 KB
guides/security/passkey-conditional-create.mdmarkdown7.9 KB
guides/security/passkey-management.mdmarkdown17.3 KB
guides/security/passkey-reauthentication.mdmarkdown6.4 KB
guides/security/passkey-registration.mdmarkdown10.3 KB
guides/security/passkeys.mdmarkdown4.9 KB
guides/security/quick-sign-ins.mdmarkdown17.5 KB
guides/security/restrict-outbound-connections.mdmarkdown13.2 KB
guides/security/sanitize-untrusted-html.mdmarkdown5.6 KB
guides/security/secure-external-subresources.mdmarkdown14.5 KB
guides/security/security.mdmarkdown29.3 KB
guides/security/trusted-types.mdmarkdown7.3 KB
guides/security/validate-origins.mdmarkdown12.7 KB
guides/security/verify-email-ownership.mdmarkdown14.5 KB
guides/ui-atoms/carousel-slide-effects.mdmarkdown10.1 KB
guides/ui-atoms/component-specific-light-dark-theme.mdmarkdown9.5 KB
guides/ui-atoms/icons.mdmarkdown17.9 KB
guides/ui-atoms/position-aware-tooltips.mdmarkdown8.3 KB
guides/ui-atoms/pull-to-reveal.mdmarkdown5.0 KB
guides/ui-atoms/responsive-table.mdmarkdown4.4 KB
guides/ui-atoms/scroll-position-aware-elements.mdmarkdown3.6 KB
guides/ui-atoms/scroll-progress-indicator.mdmarkdown6.6 KB
guides/ui-atoms/scrollability-affordance-hints.mdmarkdown11.9 KB
guides/ui-atoms/shrinking-header-on-scroll.mdmarkdown7.0 KB
guides/ui-atoms/single-line-overflow.mdmarkdown16.1 KB
guides/ui-atoms/state-aware-sticky-headers.mdmarkdown6.7 KB
guides/ui-atoms/viewport-aware-dropdowns.mdmarkdown9.9 KB
guides/ui-behaviors/2d-panning.mdmarkdown9.2 KB
guides/ui-behaviors/anchor-positioning-tab-underline.mdmarkdown3.1 KB
guides/ui-behaviors/animate-element-entry-exit.mdmarkdown7.7 KB
guides/ui-behaviors/animate-to-from-top-layer.mdmarkdown10.7 KB
guides/ui-behaviors/carousel-snap-highlights.mdmarkdown7.5 KB
guides/ui-behaviors/consistent-cross-document-transitions.mdmarkdown13.9 KB
guides/ui-behaviors/cross-document-transitions.mdmarkdown4.4 KB
guides/ui-behaviors/custom-button-actions.mdmarkdown8.2 KB
guides/ui-behaviors/declarative-dialog-popover-control.mdmarkdown7.6 KB
guides/ui-behaviors/directional-navigation-transitions.mdmarkdown5.1 KB
guides/ui-behaviors/drag-and-drop.mdmarkdown16.4 KB
guides/ui-behaviors/drag.mdmarkdown6.8 KB
guides/ui-behaviors/dynamic-sibling-animations.mdmarkdown2.6 KB
guides/ui-behaviors/dynamic-sort.mdmarkdown6.9 KB
guides/ui-behaviors/group-element-transitions.mdmarkdown6.2 KB
guides/ui-behaviors/highlight-text-ranges.mdmarkdown6.4 KB
guides/ui-behaviors/interactive-content-reveal.mdmarkdown5.7 KB
guides/ui-behaviors/interest-triggered-action-previews.mdmarkdown4.9 KB
guides/ui-behaviors/interest-triggered-tooltips.mdmarkdown19.8 KB
guides/ui-behaviors/light-dismiss-a-dialog.mdmarkdown4.1 KB
guides/ui-behaviors/motion.mdmarkdown7.6 KB
guides/ui-behaviors/move-dom-element-without-losing-state.mdmarkdown3.8 KB
guides/ui-behaviors/parallax-scroll-effects.mdmarkdown9.5 KB
guides/ui-behaviors/persistent-top-layer-ui.mdmarkdown2.3 KB
guides/ui-behaviors/physics-based-easing.mdmarkdown5.8 KB
guides/ui-behaviors/platform-controls-dismiss-dialog.mdmarkdown2.6 KB
guides/ui-behaviors/prevent-page-scroll-under-modal-dialog.mdmarkdown5.0 KB
guides/ui-behaviors/same-document-transitions.mdmarkdown8.3 KB
guides/ui-behaviors/scoped-component-transitions.mdmarkdown11.7 KB
guides/ui-behaviors/scroll-completion-effects.mdmarkdown7.5 KB
guides/ui-behaviors/scroll-entry-exit-effects.mdmarkdown9.8 KB
guides/ui-behaviors/scroll-snap-realtime-feedback.mdmarkdown10.7 KB
guides/ui-behaviors/scroll-snap-state-sync.mdmarkdown4.8 KB
guides/ui-behaviors/scroll-target-on-load.mdmarkdown3.4 KB
guides/ui-behaviors/scrollytelling.mdmarkdown8.8 KB
guides/ui-behaviors/search-hidden-content.mdmarkdown6.8 KB
guides/ui-behaviors/sortable-table.mdmarkdown7.7 KB
guides/ui-behaviors/spatial-navigation.mdmarkdown6.8 KB
guides/ui-behaviors/swipe-to-remove.mdmarkdown33.9 KB
guides/ui-behaviors/swipe-to-reveal.mdmarkdown14.2 KB
guides/ui-components/accordion.mdmarkdown14.7 KB
guides/ui-components/app-menus.mdmarkdown15.7 KB
guides/ui-components/breadcrumbs.mdmarkdown12.3 KB
guides/ui-components/card.mdmarkdown8.2 KB
guides/ui-components/carousel.mdmarkdown15.1 KB
guides/ui-components/checkbox.mdmarkdown5.7 KB
guides/ui-components/copy-button.mdmarkdown14.5 KB
guides/ui-components/dark-mode-toggle.mdmarkdown9.2 KB
guides/ui-components/dialog.mdmarkdown12.1 KB
guides/ui-components/hovercard.mdmarkdown20.9 KB
guides/ui-components/menu.mdmarkdown31.1 KB
guides/ui-components/navbar.mdmarkdown17.8 KB
guides/ui-components/navigation-drawer.mdmarkdown20.3 KB
guides/ui-components/persistent-app-tours.mdmarkdown11.2 KB
guides/ui-components/persistent-toast-notifications.mdmarkdown13.8 KB
guides/ui-components/progress-ring.mdmarkdown6.9 KB
guides/ui-components/progress.mdmarkdown10.6 KB
guides/ui-components/scrollspy.mdmarkdown6.9 KB
guides/ui-components/spinner.mdmarkdown5.9 KB
guides/ui-components/stack-drill-down.mdmarkdown36.5 KB
guides/ui-components/tabs.mdmarkdown21.7 KB
guides/ui-components/toolbar.mdmarkdown21.5 KB
guides/user-experience/content-first-noise-reduction.mdmarkdown8.3 KB
guides/user-experience/form-factor-adaptation.mdmarkdown6.0 KB
guides/user-experience/natural-interactions.mdmarkdown9.7 KB
guides/visual-design/adapt-scrollbar-to-contrast-preferences.mdmarkdown3.6 KB
guides/visual-design/apply-webgl-shaders.mdmarkdown13.1 KB
guides/visual-design/browser-ui-theming.mdmarkdown4.1 KB
guides/visual-design/color.mdmarkdown4.4 KB
guides/visual-design/complex-shapes.mdmarkdown3.5 KB
guides/visual-design/contrast-color.mdmarkdown7.1 KB
guides/visual-design/custom-text-decorations.mdmarkdown16.4 KB
guides/visual-design/customize-scrollbar-color-and-thickness.mdmarkdown2.7 KB
guides/visual-design/dark-mode.mdmarkdown16.8 KB
guides/visual-design/equal-width-text-lines.mdmarkdown6.4 KB
guides/visual-design/export-html-media-from-canvas.mdmarkdown17.1 KB
guides/visual-design/expose-canvas-content-to-browser-features.mdmarkdown19.6 KB
guides/visual-design/improve-text-layout-and-legibility.mdmarkdown5.1 KB
guides/visual-design/interactive-content-in-3d-scenes.mdmarkdown19.2 KB
guides/visual-design/precise-text-alignment.mdmarkdown4.8 KB
guides/visual-design/shaped-cutouts.mdmarkdown7.1 KB

guides/security/validate-origins.md

View on GitHub
# Compare and validate web origins and sites

While comparing `event.origin` against a fixed, port-normalized string literal (such as `event.origin === 'https://app.example.com'`) works for simple allowlists, manual string comparisons and regular expressions break down when validating arbitrary URLs, DOM link elements, cross-subdomain redirects, or sandboxed messages:

- **Prefix and substring spoofing:** Checking `url.startsWith('https://app.example.com')` is bypassed by `'https://app.example.com.attacker.example'`.
- **Unnormalized URLs:** Full URLs with paths, query strings, or explicit default ports (`'https://app.example.com:443/path'`) do not match `'https://app.example.com'` under string equality without first parsing and normalizing.
- **Public Suffix List mistakes:** Splitting hostnames on `.` to check same-site relationships fails on multi-label public suffixes (such as `.co.uk` or shared hosting domains like `.github.io`) and ignores scheme mismatches (`http:` vs. `https:`).
- **Opaque `"null"` origin collisions:** Sandboxed iframes (`<iframe sandbox="allow-scripts">`) and `data:` URLs serialize `event.origin` to the literal string `"null"`. Comparing two serialized runtime origins with `originA === originB` falsely equates two unrelated opaque contexts (`"null" === "null"`).

The **`Origin` API** (`Origin.from()`, `isSameOrigin()`, `isSameSite()`, and `opaque`) provides structured, spec-compliant origin and schemeful same-site comparisons backed by the browser's URL parser and Public Suffix List.

## Choosing the right comparison for your scenario

- **Use `isSameOrigin()` for strict privilege boundaries:** Require an exact `(scheme, host, port)` match when handling cross-window `postMessage` commands (such as an embedded checkout or auth popup) or deciding whether to attach credentials. Even a different subdomain (`https://blog.example.com` vs. `https://app.example.com`) is a different origin and must be rejected so a vulnerability on one subdomain cannot control another.
- **Use `isSameSite()` for cross-subdomain navigation and link classification:** Allow any subdomain or port sharing the same scheme and registrable domain when validating post-login redirect URLs (`?returnTo=https://billing.example.co.uk/orders`) or classifying links as internal vs. external. `isSameSite()` rejects both `http:` scheme downgrades and sibling tenants on shared public suffixes (`.co.uk`, `.github.io`).
- **Use `origin.opaque` and `Origin.from(event)` for opaque or sandboxed contexts:** Reject `data:` URLs for redirects (`origin.opaque === true`), or pin the opaque `Origin` extracted via `Origin.from(event)` when communicating with a specific `<iframe sandbox="allow-scripts">` widget whose serialized `event.origin` is `"null"`.

## 1. Verify Exact Origins for Privileged Actions (`Origin.from()` and `isSameOrigin()`)

Use `Origin.from()` to extract an `Origin` object and compare it against a trusted `Origin` using `isSameOrigin()`:

- **Both sides must be `Origin` instances:** `isSameOrigin(other)` and `isSameSite(other)` only accept an `Origin` object—passing a raw string throws a `TypeError`.
- **Supported `Origin.from()` inputs:**
  - Serialized URL strings (for example, `'https://app.example.com:443/path'`). Note that any invalid URL string—for instance `'example'`, or the `'null'` string serialized by `event.origin` for opaque origins—causes `Origin.from()` to throw a `TypeError`.
  - Platform objects that define origin-extraction steps in the HTML specification: `Origin`, `URL`, `HTMLAnchorElement` (`<a>`), `HTMLAreaElement` (`<area>`), same-origin `Window` or `WorkerGlobalScope` (`Origin.from(self)`), and browser-dispatched `MessageEvent` instances (`Origin.from(event)`).
  - Objects such as `Location`, `WorkerLocation`, `Document`, `Request`, and `Response` do **not** define origin-extraction steps and throw a `TypeError` if passed directly to `Origin.from()`—pass `self` (for the current context) or `request.url` / `response.url` instead.
- **Handle both browser-dispatched and synthetic `MessageEvent` instances:** Real browser `postMessage` events carry an internal origin extracted by `Origin.from(event)`, whereas synthetic `new MessageEvent('message', { origin })` events created in unit tests only populate the `event.origin` string and throw on `Origin.from(event)`. Falling back to `Origin.from(event.origin)` inside a `try...catch` handles both cleanly while still rejecting invalid or `"null"` strings.

```javascript
// Replace with your application's trusted origin(s)
const TRUSTED_ORIGIN = Origin.from('https://app.example.com');

function extractOrigin(candidate) {
  try {
    return Origin.from(candidate);
  } catch (err) {
    // Synthetic new MessageEvent('message', { origin }) objects in tests lack an
    // internal browser origin; fall back to parsing candidate.origin if it is a URL.
    if (typeof MessageEvent !== 'undefined' && candidate instanceof MessageEvent) {
      return Origin.from(candidate.origin);
    }
    throw err;
  }
}

export function isTrustedSameOrigin(candidate) {
  try {
    return extractOrigin(candidate).isSameOrigin(TRUSTED_ORIGIN);
  } catch {
    // Rejects invalid URLs, "null" strings, or unsupported objects
    return false;
  }
}

window.addEventListener('message', (event) => {
  if (!isTrustedSameOrigin(event)) return;

  // Safe to process privileged commands from the verified origin
});
```

## 2. Validate Cross-Subdomain Redirects and Links (`isSameSite()`)

When validating redirect targets (such as `?returnTo=` parameters) or internal links across subdomains of the same registrable domain (for example, `https://app.example.co.uk` and `https://billing.example.co.uk:8443`), use `isSameSite()`:

- `isSameSite()` performs a **schemeful same-site** comparison: `https://sub.example.com` and `http://sub.example.com` are **not** same-site because their schemes differ.
- `isSameSite()` uses the browser's built-in **Public Suffix List**, so distinct tenants on shared public suffixes (such as `https://tenant-a.github.io` and `https://tenant-b.github.io`, or `https://a.co.uk` and `https://b.co.uk`) evaluate to `false`.

```javascript
// Replace with your application's primary origin
const APP_ORIGIN = Origin.from('https://app.example.co.uk');

export function isAllowedSameSiteUrl(candidateUrlOrElement) {
  try {
    return extractOrigin(candidateUrlOrElement).isSameSite(APP_ORIGIN);
  } catch {
    return false;
  }
}

// true: same scheme (https) and same registrable domain (example.co.uk)
isAllowedSameSiteUrl('https://billing.example.co.uk:8443/checkout');

// false: scheme downgrade (http vs. https) is rejected by schemeful same-site
isAllowedSameSiteUrl('http://billing.example.co.uk/checkout');
```

## 3. Distinguish and Pin Opaque Origins (`origin.opaque` and `Origin.from(event)`)

Sandboxed iframes (`<iframe sandbox="allow-scripts">`), `data:` URLs, and `new Origin()` produce **opaque origins** (`origin.opaque === true`). While their string serialization is always `"null"`, `Origin.from(event)` extracts the sender's actual underlying opaque origin from a browser-dispatched `MessageEvent`:

- Two messages sent from the **same** sandboxed iframe yield `Origin` objects that are `isSameOrigin()` with each other (`true`).
- Messages sent from **different** sandboxed iframes—or separate `Origin.from('data:...')` / `new Origin()` calls—yield distinct opaque origins that evaluate `isSameOrigin()` to `false`, preventing `"null" === "null"` spoofing across unrelated opaque contexts.
- `new Origin()` creates a fresh, unique opaque origin that matches nothing except itself, which is useful as a default deny-all sentinel before an expected peer origin is pinned once on initialization.

```javascript
// Initialize with a unique opaque sentinel that matches no other origin
let pinnedSandboxOrigin = new Origin();
let isSandboxPinned = false;

export function handleSandboxedWidgetMessage(event, expectedWidgetWindow) {
  try {
    const senderOrigin = Origin.from(event);

    // Pin the opaque origin only once on initialization from the expected sandboxed iframe
    if (!isSandboxPinned && event.source === expectedWidgetWindow && event.data?.type === 'init') {
      pinnedSandboxOrigin = senderOrigin;
      isSandboxPinned = true;
    }

    // Subsequent messages from the SAME sandboxed iframe match pinnedSandboxOrigin;
    // messages from any other sandboxed iframe (also event.origin === "null") return false.
    return senderOrigin.isSameOrigin(pinnedSandboxOrigin);
  } catch {
    return false;
  }
}
```

## Best practices

- **DO** convert both sides of a comparison to `Origin` instances via `Origin.from()` before calling `isSameOrigin(other)` or `isSameSite(other)`.
- **DO** pass a browser-dispatched `MessageEvent` directly to `Origin.from(event)` when you need to preserve opaque origin identity, and use `Origin.from(self)` (rather than `Location` or `Document`, which throw `TypeError`) to obtain the current execution context's `Origin`.
- **DO** wrap `Origin.from()` calls on untrusted or runtime inputs in a `try...catch` block so invalid URLs, `"null"` strings, or unsupported objects safely return `false` instead of throwing an uncaught `TypeError`.
- **DO NOT** compare two runtime `event.origin` or `url.origin` strings directly without first rejecting `"null"` (`origin !== 'null'`), as two unrelated opaque origins both serialize to `"null"`.
- **DO NOT** validate origins or sites with `startsWith()`, `includes()`, `endsWith()`, or naive `.split('.')` hostname slicing.

## Fallback strategy

Browser support for Origin: Limited availability.
Supported by: Chrome 145 (Feb 2026), Edge 145 (Feb 2026), and Safari 26.5 (May 2026).
Unsupported in: Firefox.

If your Baseline target includes browsers that do not yet support the `Origin` interface, feature-detect `'Origin' in globalThis` and fall back to parsing URLs with `new URL()`:

- **Same-origin fallback (tuple origins):** Extract the URL string (using `event.origin` for `MessageEvent` objects or `candidate.href` for link elements), parse both the candidate and trusted URLs with `new URL()`, reject `"null"` opaque origins (`candidateUrl.origin !== 'null'`), and compare `candidateUrl.origin === trustedUrl.origin`. Because an opaque origin is never same-origin with a tuple origin like `'https://app.example.com'`, immediately rejecting `'null'` matches `Origin.isSameOrigin()`.
- **Same-site fallback (caveat):** The `URL` interface does not expose the browser's Public Suffix List. In browsers without `Origin`, only perform suffix matching against an explicit, known private registrable domain that you control (verifying both `protocol` and an exact or dot-prefixed `hostname` match), or use a maintained Public Suffix List library.
- **Opaque / sandboxed iframe fallback:** Browsers without `Origin` do not expose distinct opaque origin identities on `MessageEvent` (`event.origin` is always `"null"`). If you intentionally accept messages from a known sandboxed `<iframe sandbox="allow-scripts">`, verify `event.source === expectedWidgetWindow` (or communicate over a dedicated `MessageChannel` `MessagePort` transferred to the iframe on initialization) rather than comparing `event.origin`.

```javascript
// Replace with your trusted reference URL and known registrable domain
const TRUSTED_URL = 'https://app.example.com';
const TRUSTED_SITE_DOMAIN = 'example.com';

function extractUrlString(candidate) {
  if (typeof candidate === 'string') return candidate;
  if (typeof MessageEvent !== 'undefined' && candidate instanceof MessageEvent) {
    return candidate.origin;
  }
  if (candidate === globalThis) {
    return globalThis.location?.href ?? '';
  }
  return candidate?.href ?? '';
}

function extractOrigin(candidate) {
  try {
    return Origin.from(candidate);
  } catch (err) {
    if (typeof MessageEvent !== 'undefined' && candidate instanceof MessageEvent) {
      return Origin.from(candidate.origin);
    }
    throw err;
  }
}

export function checkSameOriginWithFallback(candidate) {
  try {
    if ('Origin' in globalThis) {
      return extractOrigin(candidate).isSameOrigin(Origin.from(TRUSTED_URL));
    }
    const candidateUrl = new URL(extractUrlString(candidate));
    const trustedUrl = new URL(TRUSTED_URL);
    return candidateUrl.origin !== 'null' && candidateUrl.origin === trustedUrl.origin;
  } catch {
    return false;
  }
}

export function checkSameSiteWithFallback(candidate) {
  try {
    if ('Origin' in globalThis) {
      return extractOrigin(candidate).isSameSite(Origin.from(TRUSTED_URL));
    }
    const candidateUrl = new URL(extractUrlString(candidate));
    const trustedUrl = new URL(TRUSTED_URL);
    return (
      candidateUrl.origin !== 'null' &&
      candidateUrl.protocol === trustedUrl.protocol &&
      (candidateUrl.hostname === TRUSTED_SITE_DOMAIN ||
        candidateUrl.hostname.endsWith(`.${TRUSTED_SITE_DOMAIN}`))
    );
  } catch {
    return false;
  }
}
```
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall