From d98fff86e9be90de68468fcc4d70e26a7af13e78 Mon Sep 17 00:00:00 2001 From: ThatXliner Date: Sun, 8 Nov 2026 07:54:16 -0800 Subject: [PATCH] chore: drop the eMudhra CA filter and incident TLS probes PRs #33 and #34 added a server-side filter that removes the four compromised eMudhra roots from Node's default CA store. They also added a CI step and a script that probe the incident hosts. Node 22.23.4, 24.22.1 and 26.12.1, and Vercel's managed Node (22.x is now v22.23.4, 24.x is v24.22.2, 26.x is v26.13.0), no longer ship those roots, so the filter has nothing left to remove. The probe script tests the incident hosts, not this app, and it will break when those hosts go away. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 3 - apps/nextjs/security/emudhra-default-ca.mjs | 34 ---- apps/nextjs/src/instrumentation.js | 4 - apps/nextjs/src/middleware.ts | 2 - package.json | 4 +- scripts/check-node.mjs | 2 +- scripts/test-http-security.mjs | 162 -------------------- 7 files changed, 2 insertions(+), 209 deletions(-) delete mode 100644 apps/nextjs/security/emudhra-default-ca.mjs delete mode 100644 scripts/test-http-security.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47a13d7..465f0d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,9 +27,6 @@ jobs: - name: Setup uses: ./tooling/github/setup - - name: HTTP security contracts - run: pnpm test:security - - name: Copy env shell: bash run: cp .env.example .env diff --git a/apps/nextjs/security/emudhra-default-ca.mjs b/apps/nextjs/security/emudhra-default-ca.mjs deleted file mode 100644 index 364e7bc..0000000 --- a/apps/nextjs/security/emudhra-default-ca.mjs +++ /dev/null @@ -1,34 +0,0 @@ -import tls from "node:tls"; -import { X509Certificate } from "node:crypto"; - -// The affected trust paths are listed at https://emudhra.we-have-a-problem.com/roots.json. -const affected = new Set([ - "7DD78D5F4F13459A83DFF9ABBBA62EDBAF6F2D102BF257FD712F4D9F2746ED8D", - "F2EDAAFF3D9B701FB4D14C9F285F8C0BAD90FC3BCC1FA07D47F4718EDABA34A5", - "D7A7A0FB5D7E2731D771E9484EBCDEF71D5F0C3E0A2948782BC83EE0EA699EF4", - "86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B", -]); - -export function installEmudhraDistrust() { - if (typeof tls.setDefaultCACertificates !== "function") { - throw new Error( - "This server requires Node.js with tls.setDefaultCACertificates support.", - ); - } - const removed = []; - const certificates = tls.rootCertificates.filter((pem) => { - const certificate = new X509Certificate(pem); - const fingerprint = certificate.fingerprint256.replaceAll(":", ""); - if (!affected.has(fingerprint)) return true; - removed.push({ subject: certificate.subject, fingerprint }); - return false; - }); - if (certificates.length === 0) - throw new Error("No trusted CA certificates remain."); - tls.setDefaultCACertificates(certificates); - return { - before: tls.rootCertificates.length, - after: certificates.length, - removed, - }; -} diff --git a/apps/nextjs/src/instrumentation.js b/apps/nextjs/src/instrumentation.js index 81d223f..cc38d5e 100644 --- a/apps/nextjs/src/instrumentation.js +++ b/apps/nextjs/src/instrumentation.js @@ -1,9 +1,5 @@ export async function register() { if (process.env.NEXT_RUNTIME === "nodejs") { - const { installEmudhraDistrust } = await import( - "../security/emudhra-default-ca.mjs" - ); - installEmudhraDistrust(); await import("../sentry.server.config"); } else if (process.env.NEXT_RUNTIME === "edge") { await import("../sentry.edge.config"); diff --git a/apps/nextjs/src/middleware.ts b/apps/nextjs/src/middleware.ts index 36414a9..cc3951e 100644 --- a/apps/nextjs/src/middleware.ts +++ b/apps/nextjs/src/middleware.ts @@ -1,9 +1,7 @@ -import { installEmudhraDistrust } from "../security/emudhra-default-ca.mjs"; import { createServerClient, type CookieOptions } from "@supabase/ssr"; import { NextResponse, type NextRequest } from "next/server"; export async function middleware(request: NextRequest) { - installEmudhraDistrust(); let response = NextResponse.next({ request: { headers: request.headers, diff --git a/package.json b/package.json index 890f14b..7c7c445 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,7 @@ "typecheck": "turbo typecheck", "android": "expo run:android", "ios": "expo run:ios", - "preinstall": "node scripts/check-node.mjs", - "test:security": "node scripts/test-http-security.mjs", - "verify:tls": "node scripts/test-http-security.mjs --network" + "preinstall": "node scripts/check-node.mjs" }, "devDependencies": { "@acme/prettier-config": "workspace:^0.1.0", diff --git a/scripts/check-node.mjs b/scripts/check-node.mjs index 177a947..334666e 100644 --- a/scripts/check-node.mjs +++ b/scripts/check-node.mjs @@ -6,6 +6,6 @@ const supported = major > 26; if (!supported) { throw new Error( - "Use Node.js ^22.23.4 || ^24.22.1 || >=26.12.1 with the eMudhra trust update.", + "Use Node.js ^22.23.4 || ^24.22.1 || >=26.12.1.", ); } diff --git a/scripts/test-http-security.mjs b/scripts/test-http-security.mjs deleted file mode 100644 index ca3c8e0..0000000 --- a/scripts/test-http-security.mjs +++ /dev/null @@ -1,162 +0,0 @@ -import assert from "node:assert/strict"; -import { createServer } from "node:http"; -import { createRequire } from "node:module"; -import { once } from "node:events"; -import { channel } from "node:diagnostics_channel"; -import { X509Certificate } from "node:crypto"; -import tls from "node:tls"; -import { installEmudhraDistrust } from "../apps/nextjs/security/emudhra-default-ca.mjs"; - -const trust = installEmudhraDistrust(); -const require = createRequire( - new URL("../apps/nextjs/package.json", import.meta.url), -); -const axios = require("axios"); -const { createClient } = require("@supabase/supabase-js"); -assert.ok(trust.after > 0); -assert.ok(trust.after <= trust.before); -assert.deepEqual(installEmudhraDistrust(), trust); -const affected = new Set([ - "7DD78D5F4F13459A83DFF9ABBBA62EDBAF6F2D102BF257FD712F4D9F2746ED8D", - "F2EDAAFF3D9B701FB4D14C9F285F8C0BAD90FC3BCC1FA07D47F4718EDABA34A5", - "D7A7A0FB5D7E2731D771E9484EBCDEF71D5F0C3E0A2948782BC83EE0EA699EF4", - "86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B", -]); -for (const pem of tls.getCACertificates("default")) { - assert.ok( - !affected.has(new X509Certificate(pem).fingerprint256.replaceAll(":", "")), - ); -} -const server = createServer((request, response) => { - response.setHeader("content-type", "application/json"); - if (request.url === "/rest/v1/probe?select=*") response.end('[{"id":1}]'); - else - response.end(JSON.stringify({ method: request.method, path: request.url })); -}); -server.listen(0, "127.0.0.1"); -await once(server, "listening"); -try { - const origin = `http://127.0.0.1:${server.address().port}`; - const result = await axios.get(`${origin}/contract`, { - proxy: false, - timeout: 5000, - }); - assert.deepEqual(result.data, { method: "GET", path: "/contract" }); - const supabase = createClient(origin, "scouting-security-probe", { - auth: { - persistSession: false, - autoRefreshToken: false, - detectSessionInUrl: false, - }, - }); - const { data, error } = await supabase.from("probe").select(); - assert.equal(error, null); - assert.deepEqual(data, [{ id: 1 }]); -} finally { - server.closeAllConnections(); - await new Promise((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); -} -console.log( - JSON.stringify({ runtime: process.version, trust, contracts: "passed" }), -); - -if (process.argv.includes("--network")) { - const targets = [ - ["https://dv-g3b-emudhra.we-have-a-problem.com", "certificate_rejected"], - [ - "https://dv-g3b-aaa-emudhra.we-have-a-problem.com", - "certificate_rejected", - ], - ["https://example.com", "accepted"], - ]; - const certificateErrors = new Set([ - "UNABLE_TO_GET_ISSUER_CERT_LOCALLY", - "UNABLE_TO_VERIFY_LEAF_SIGNATURE", - "CERT_UNTRUSTED", - "CERT_REJECTED", - "CERT_REVOKED", - "SELF_SIGNED_CERT_IN_CHAIN", - ]); - const results = []; - for (const api of ["axios", "fetch", "supabase"]) { - for (const [url, expected] of targets) { - let result; - for (let attempt = 1; attempt <= 3; attempt++) { - const controller = new AbortController(); - const timer = setTimeout(() => controller.abort(), 19000); - let observedCode; - let observedStatus; - const errors = channel("undici:request:error"); - const headers = channel("undici:request:headers"); - const onError = (message) => { - observedCode = message.error?.code; - }; - const onHeaders = (message) => { - observedStatus = message.response.statusCode; - }; - errors.subscribe(onError); - headers.subscribe(onHeaders); - try { - if (api === "axios") { - const response = await axios.get(url, { - signal: controller.signal, - timeout: 19000, - proxy: false, - maxRedirects: 0, - validateStatus: () => true, - }); - observedStatus = response.status; - } else if (api === "fetch") { - const response = await fetch(url, { - signal: controller.signal, - redirect: "manual", - }); - observedStatus = response.status; - await response.body?.cancel(); - } else { - const supabase = createClient(url, "scouting-security-probe", { - auth: { - persistSession: false, - autoRefreshToken: false, - detectSessionInUrl: false, - }, - }); - await supabase - .from("probe") - .select() - .abortSignal(controller.signal); - } - } catch (error) { - observedCode = error.cause?.code ?? error.code ?? observedCode; - } finally { - clearTimeout(timer); - errors.unsubscribe(onError); - headers.unsubscribe(onHeaders); - } - const outcome = observedStatus - ? "accepted" - : certificateErrors.has(observedCode) - ? "certificate_rejected" - : "inconclusive"; - result = { - api, - url, - expected, - outcome, - code: observedCode, - status: observedStatus, - attempt, - }; - console.log(JSON.stringify(result)); - if (outcome !== "inconclusive") break; - } - results.push(result); - } - } - assert.ok( - results.every((result) => result.outcome === result.expected), - "TLS contract did not pass; acceptance and network errors are not rejection", - ); -}