STUDIO & LICENSING DESK: Public essays and household demos are free; commercial White-Label software licenses, PocketGull v4.0 typefaces, archival prints, and written Principal Architect opinions are available for direct purchase.
Browse Studio Store →
Phil Gearphilgear.dev
All Writings
November 24, 20267 min readPhil GearSystems & RigorStudio & Terminal

The 125/100 Bonus-Gate Paradox: Securing Firebase, Cloud Run, and WebMCP

Why a single unhashed inline script costs 45 points on Mozilla HTTP Observatory—and how Middleware #1 CSPRNG nonces, static SHA-256 hashes, and WebMCP origin isolation keep modern Google Cloud and Firebase apps at Grade A+.

Topics:Cloud SecurityFirebaseCloud RunCSPWebMCPMozilla ObservatorySystems Architecture

Most engineering teams assume web security headers degrade gracefully: miss one directive, lose five points, fix it next sprint.

On Mozilla HTTP Observatory, the math is non-linear—and it catches thousands of otherwise thoughtful Firebase Hosting, Cloud Run, and Astro deployments off guard.

1. Why One Inline Script Costs 45 Points

Mozilla HTTP Observatory starts every site at 100 points and offers +25 to +35 bonus points for defense-in-depth isolation (Strict-Transport-Security preload, Cross-Origin-Opener-Policy, Cross-Origin-Resource-Policy, strict Referrer-Policy, and strict Content-Security-Policy).

Here is the catch: bonus points are strictly gated behind a baseline score of 90+ with zero major penalties.

  • Adding 'unsafe-inline' to script-src—often pasted in to unblock a five-line dark-mode toggle or analytics bootstrap—triggers an immediate -20 point deduction.
  • Dropping from 100 to 80 crosses below the 90 bonus gate, revoking all +25 bonus points simultaneously.
  • A single unhashed inline <script> tag drops a 125/100 (Grade A+) deployment straight to 80/100 (Grade B+)—a 45-point swing from one line of configuration.
Posture Baseline Bonus Gate Final Score Grade
External ES Modules + CSPRNG Nonce / SHA-256 100 Unlocked (+25) 125 / 100 A+
Single 'unsafe-inline' in script-src 80 (-20) Revoked (+0) 80 / 100 B+

(Note: Mozilla Observatory assigns 0 penalty to 'unsafe-inline' when confined strictly to style-src, though external stylesheets eliminate inline style tokens altogether.)

2. The “Middleware #1” Invariant on Cloud Run

On Google Cloud Run or Node SSR backends, the most common silent regression is middleware ordering. When a health check, static asset handler, or domain router mounts above the security middleware and exits early, matching responses ship with zero CSP or HSTS headers.

The fix is structural: mount a zero-dependency Middleware #1 at the top of the HTTP server, generating a fresh 128-bit OS CSPRNG nonce (crypto.randomBytes(16).toString('base64')) before any route executes:

import crypto from 'node:crypto';

export function applyObservatory125Headers(res) {
  const nonce = crypto.randomBytes(16).toString('base64');

  res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
  res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
  res.setHeader('Cross-Origin-Resource-Policy', 'same-origin');
  res.setHeader('Cross-Origin-Embedder-Policy', 'credentialless');
  res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
  res.setHeader('X-Frame-Options', 'SAMEORIGIN');
  res.setHeader('X-Content-Type-Options', 'nosniff');
  res.setHeader('Permissions-Policy', 'tools=(self)');
  res.setHeader('Origin-Agent-Cluster', '?1');

  res.setHeader(
    'Content-Security-Policy',
    [
      "default-src 'none'",
      `script-src 'self' 'nonce-${nonce}' 'strict-dynamic'`,
      "style-src 'self'",
      "img-src 'self' data:",
      "font-src 'self'",
      "connect-src 'self'",
      "frame-ancestors 'self'",
      "base-uri 'self'",
      "form-action 'self'",
      "object-src 'none'"
    ].join('; ')
  );

  return nonce;
}

3. Static Edge Hosting (firebase.json) Without SSR

Static sites deployed to Firebase Hosting have no per-request Node process to mint dynamic nonces. Instead of falling back to 'unsafe-inline', use two deterministic patterns:

  1. Externalize Client Scripts: Compile TypeScript/JavaScript into external ES modules (<script type="module" src="/app.mjs"></script>) covered cleanly by script-src 'self'.
  2. Pre-Deploy SHA-256 Verification: When a tiny synchronous theme script must stay in <head>, compute its exact UTF-8 SHA-256 digest during build verification ('sha256-...') and fail the build in CI if any unhashed inline <script> appears in dist/.

4. Hardening In-Browser AI Agents (WebMCP)

As browsers introduce client-side tool registration (navigator.modelContext / document.modelContext), CSP and origin headers gain a second responsibility: preventing cross-origin tool hijacking.

Three rules keep WebMCP deployments at 125/100:

  • Bundle Tool Registrations Externally: Register modelContext.registerTool(...) inside compiled ES modules—never inside unhashed inline <script> blocks.
  • Lock Tool Delegation to Same-Origin: Declare Permissions-Policy: tools=(self) in firebase.json and Cloud Run Middleware #1 so embedded third-party frames cannot invoke or shadow registered browser tools.
  • Preserve Agent Cluster Isolation: Set Origin-Agent-Cluster: ?1 so the browser isolates the origin’s execution process cleanly.

Security that relies on developer memory eventually drifts. Security compiled into Middleware #1 and verified in CI stays at Grade A+ on every deploy.

🤝 Open Workbench · Càirdeas (Kinship Without Gatekeeping)

Share, Adapt, or Build Upon This Work

Published 2026-11-24 · Phil Gear

Ideas grow stronger when shared openly across the workbench. If this essay sparked a useful direction for your team, keynote, or research, feel free to reference it using the citation below—or reach out anytime to collaborate:

Gear, P. (2026). The 125/100 Bonus-Gate Paradox: Securing Firebase, Cloud Run, and WebMCP. PhilGear Development Studio. https://philgear.dev/writings/the-125-bonus-gate-firebase-and-webmcp
Architectural Boundary · Diffuse Reflection

You have reached the end of this reflection.

Honor your finite cognitive budget: look away from the display, allow your thoughts to synthesize in diffuse mode, or capture reflections in the client-side scratchpad below.

Studio Services & Licensing

Work Together or License Tools

Personal tools and essays are free. Commercial licenses, fonts, archival prints, and written architecture reviews live in the Studio Store.

Technical Storytelling

Clear keynotes, essays, and visual explainers for complex engineering work.

Architecture Second Opinions

Candid written trade-off reviews for AI workflows, privacy, and cloud costs.

Calm UX & Security Audits

High-contrast legibility, low-clutter interfaces, and Grade A+ security headers.

Studio Licenses & Fonts

White-label Solvency Engine, PocketGull v4.0 fonts, and signed archival prints.

Discussion & Collaborative Feedback

Software and ideas grow through honest conversation and mutual learning.

Private Reader Scratchpad (Saved locally on your device)
Zero Third-Party Trackers · Respecting Human Attentionphilgear.dev