worldmonitor icon indicating copy to clipboard operation
worldmonitor copied to clipboard

[SECURITY] Add COEP / COOP headers — Spectre mitigation + SharedArrayBuffer for ML workers

Open koala73 opened this issue 7 months ago • 2 comments

Summary

vercel.json and index.html set no Cross-Origin-Embedder-Policy / Cross-Origin-Opener-Policy headers. Two compounding effects:

  1. Spectre-class side-channel hardening — without COEP: require-corp + COOP: same-origin, the page is not "cross-origin isolated" and remains exposed to a class of timing attacks Chrome's process model used to mitigate.

  2. SharedArrayBuffer disabled — many ML libraries (@xenova/transformers, onnxruntime-web's threaded mode) need crossOriginIsolated === true to use SharedArrayBuffer. Without it, they fall back to single-threaded copies — slower inference. The codebase already loads transformers + onnxruntime as workers; a perf win is on the table here too.

Likely fix

Add to vercel.json headers (and the equivalent add_header lines in nginx-security-headers.conf):

{ "key": "Cross-Origin-Opener-Policy", "value": "same-origin" },
{ "key": "Cross-Origin-Embedder-Policy", "value": "require-corp" },
{ "key": "Cross-Origin-Resource-Policy", "value": "same-origin" }

Watch out: require-corp will block any cross-origin resources (images, fonts, iframes) that don't ship Cross-Origin-Resource-Policy: cross-origin. You'll need to audit:

  • YouTube embeds, Cloudflare insights, Sentry — most major CDNs already send the header. Spot-check before deploy.
  • Map tile providers (Protomaps, MapLibre tiles) — verify CORP support.
  • Any remaining cross-origin assets need to be self-hosted or proxied.

Easy first step: deploy in report-only mode for a few days and watch the COEP report endpoint for blocked resources before flipping to enforce.

Severity

MEDIUM (hardening + perf). Real win for ML perf if SharedArrayBuffer becomes available.

Source

Manual code review (deepseek security audit, validated 2026-05-01).

koala73 avatar May 01 '26 19:05 koala73

Opened #3609 as the first-stage fix for this.

I kept COOP/COEP in report-only mode instead of enforcing immediately because WorldMonitor loads several third-party frames/assets, and require-corp can break production resource loading if any dependency is not ready. This gives maintainers a safe signal-gathering step before enforcement.

The PR also keeps Vercel and self-hosted nginx headers aligned and adds deploy-config guardrails so this rollout cannot accidentally switch to enforced COOP/COEP. Full enforcement can follow once report-only violations are reviewed.

lspassos1 avatar May 05 '26 19:05 lspassos1

Current status after rechecking main:

  • The safe first stage proposed here shipped through #3912 (superseding #3609).
  • Vercel and self-hosted nginx both send report-only COOP/COEP headers.
  • Reporting-Endpoints is wired to the bounded/redacting /api/security/report collector.
  • Guardrails intentionally prevent an accidental switch to enforced headers.

The remaining work is therefore the production-enforcement decision, not another header PR. I am leaving this issue open because enabling COOP: same-origin / COEP: require-corp without reviewing production reports and auditing the current third-party frame/asset matrix could break real dashboard surfaces.

The next implementation should start from collected violation data, document the incompatible resources and their proxy/self-host/removal treatment, then make the enforcement change with focused deployment tests. There is no open lspassos1 PR to recover for that second stage today.

lspassos1 avatar Aug 30 '26 15:08 lspassos1