Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,519 @@
|
||||
"use strict";
|
||||
|
||||
// adpanel:branding-media-stealth-cover — behavior + source pins for the
|
||||
// stealth-mode cover of the /branding-media/:kind route (the sibling leak of
|
||||
// the favicon fix, tests/stealth-favicon-decoy.test.js):
|
||||
//
|
||||
// The finding: /branding-media/:kind is a pre-auth reachable route whose
|
||||
// response is derived from the operator's branding config — the route
|
||||
// proxies the operator's configured REMOTE asset and serves its bytes
|
||||
// (200) or the remote fetch's failure (502). /branding-media/
|
||||
// login-background was already decoyed pre-gate (an exact
|
||||
// STEALTH_ASSET_PATHS entry), but /branding-media/logo was in NEITHER the
|
||||
// set NOR any covered prefix — with a remote logo configured, under
|
||||
// STEALTH_ACTIVE with no access, the gate passed the probe straight to the
|
||||
// route, which served the operator's remote logo bytes beside its decoyed
|
||||
// sibling — a distinguishable pair that fingerprinted the panel and handed
|
||||
// the operator's configured remote asset to an unauthenticated prober.
|
||||
//
|
||||
// The fix (cover, not route logic — mirrors how login-background is
|
||||
// covered): /branding-media/logo becomes an exact STEALTH_ASSET_PATHS
|
||||
// entry. The gate then 404-decoys it (sendStealthNotFound) BEFORE the route
|
||||
// runs, with the SAME decoy shape its login-background sibling gets — one
|
||||
// mechanism for the whole closed kind surface. With stealth access (gate
|
||||
// cookie/session) or stealth off, the route serves exactly as before. The
|
||||
// route handler deliberately carries NO in-handler stealth re-check: unlike
|
||||
// /auth-assets/favicon (which needs a route-layer check only because the
|
||||
// classifier EXCLUDES it to serve the special empty-favicon 204 decoy),
|
||||
// branding-media kinds are covered by the set and would only double-cover.
|
||||
//
|
||||
// Kind inventory (pinned below): getBrandingRemoteAssetConfig's switch is
|
||||
// CLOSED at exactly "login-background" and "logo"; any other kind falls to
|
||||
// the route's constant 404 ("not found" body) — no operator-config-derived
|
||||
// content, uniform across installs. The set must mirror exactly that
|
||||
// closed list; a new kind added to the switch without a set entry
|
||||
// reintroduces this leak class.
|
||||
//
|
||||
// Spelling surface (pinned against the installed express 4.22.2 and the
|
||||
// REAL extracted classifier): the set cover matches every spelling the
|
||||
// route would serve — the shared pipeline (adpanel:stealth-asset-decoded-
|
||||
// match → adpanel:stealth-asset-normalized-match →
|
||||
// adpanel:stealth-asset-spelling-parity) decodes, send-normalizes, strips
|
||||
// the one strict:false-optional trailing slash and case-folds before the
|
||||
// set lookup, so percent-encoded spellings decode onto the entry AND the
|
||||
// router's trailing-slash and case-variant spellings classify onto it too
|
||||
// (2026-11-13: the formerly-pinned spelling-exact residual is consciously
|
||||
// reversed — /branding-media/logo/, /BRANDING-MEDIA/logo and
|
||||
// /branding-media/login-background/ served real route-backed bytes
|
||||
// pre-gate while the canonical spellings decoyed; the favicon needed a
|
||||
// spelling-agnostic route check precisely because its gate-side
|
||||
// classification is an exclusion, not an entry).
|
||||
|
||||
process.env.STEALTH_RESPONSE_FLOOR_MS = "1"; // fastest real floor value (0 falls back to 90 — parseInt(...) || 90)
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const http = require("node:http");
|
||||
|
||||
const ROOT = path.join(__dirname, "..");
|
||||
const INDEX_JS = path.join(ROOT, "index.js");
|
||||
const indexSource = fs.readFileSync(INDEX_JS, "utf8");
|
||||
|
||||
function indexOfOrThrow(needle, from = 0) {
|
||||
const idx = indexSource.indexOf(needle, from);
|
||||
assert.ok(idx >= 0, `expected source pin not found: ${needle}`);
|
||||
return idx;
|
||||
}
|
||||
|
||||
// The complete app.get(...) statement for /branding-media/:kind, bounded by
|
||||
// its catch marker + the first "});" after it (the catch is the last
|
||||
// statement of the handler).
|
||||
const BRANDING_ROUTE_SRC = (() => {
|
||||
const start = indexOfOrThrow('app.get("/branding-media/:kind"');
|
||||
const catchAt = indexOfOrThrow('console.error("[branding-media] Failed to serve remote asset:"', start);
|
||||
const end = indexSource.indexOf("});", catchAt);
|
||||
assert.ok(end > catchAt, "branding route window must be bounded");
|
||||
return indexSource.slice(start, end + 3);
|
||||
})();
|
||||
|
||||
// The REAL kind switch — the closed inventory the set must mirror.
|
||||
const KIND_SWITCH_SRC = (() => {
|
||||
const start = indexOfOrThrow("function getBrandingRemoteAssetConfig(kind, branding) {");
|
||||
const end = indexOfOrThrow("async function loadBrandingRemoteAsset(", start);
|
||||
assert.ok(end > start, "kind switch slice must be bounded");
|
||||
return indexSource.slice(start, end);
|
||||
})();
|
||||
|
||||
const SVG_HEADERS_SRC = (() => {
|
||||
const start = indexOfOrThrow("function applySvgContentSecurityHeaders(res, isFavicon = false) {");
|
||||
const end = indexOfOrThrow("function sendPrivateAssetFile(", start);
|
||||
assert.ok(end > start, "svg headers slice must be bounded");
|
||||
return indexSource.slice(start, end);
|
||||
})();
|
||||
|
||||
// Extraction (same technique as stealth-favicon-decoy.test.js): stitch the
|
||||
// REAL classifier (set + prefixes + helper + safeDecodePath) and the REAL
|
||||
// decoy senders into an evaluatable scope, plus the REAL kind switch. index.js
|
||||
// binds require("path") at module top; new Function bodies see no module
|
||||
// scope, so the module object is handed in as a parameter — the identical
|
||||
// binding.
|
||||
function loadStealthScope() {
|
||||
const floorStart = indexOfOrThrow("const STEALTH_RESPONSE_FLOOR_MS = ");
|
||||
const floorEnd = indexSource.indexOf("\n", floorStart);
|
||||
assert.ok(floorEnd > floorStart, "floor const slice must be bounded");
|
||||
const delayStart = indexOfOrThrow("function delay(ms) {");
|
||||
const delayEnd = indexOfOrThrow("function getStealthBootstrapState(req) {", delayStart);
|
||||
assert.ok(delayEnd > delayStart, "delay + floor slice must be bounded");
|
||||
const notFoundStart = indexOfOrThrow("async function sendStealthNotFound(res) {");
|
||||
const notFoundEnd = indexOfOrThrow("async function hasStealthAccess(req) {", notFoundStart);
|
||||
assert.ok(notFoundEnd > notFoundStart, "decoy sender slice must be bounded");
|
||||
const setStart = indexOfOrThrow("const STEALTH_ASSET_PATHS = new Set([");
|
||||
const setEnd = indexSource.indexOf("]);", setStart);
|
||||
assert.ok(setEnd > setStart, "STEALTH_ASSET_PATHS slice must be bounded");
|
||||
const prefixStart = indexOfOrThrow("const PRE_AUTH_STATIC_PREFIXES = [");
|
||||
const prefixEnd = indexSource.indexOf("];", prefixStart);
|
||||
assert.ok(prefixEnd > prefixStart, "PRE_AUTH_STATIC_PREFIXES slice must be bounded");
|
||||
// adpanel:stealth-asset-spelling-parity — the classifier's root-level leg
|
||||
// references the shared PRE_AUTH_STATIC_EXT const (defined later in
|
||||
// index.js, request-time evaluation); the stitched scope must carry it.
|
||||
const extStart = indexOfOrThrow("const PRE_AUTH_STATIC_EXT = ");
|
||||
const extEnd = indexSource.indexOf("\n", extStart);
|
||||
assert.ok(extEnd > extStart, "PRE_AUTH_STATIC_EXT slice must be bounded");
|
||||
const clsStart = indexOfOrThrow("function isStealthProtectedAssetPath(");
|
||||
const clsEnd = indexOfOrThrow("function isStealthProtectedLoginPath(", clsStart);
|
||||
assert.ok(clsEnd > clsStart, "classifier slice must be bounded");
|
||||
const decodeStart = indexOfOrThrow("function safeDecodePath(p)");
|
||||
const decodeEnd = indexOfOrThrow("function servePublicStatic(", decodeStart);
|
||||
assert.ok(decodeEnd > decodeStart, "safeDecodePath slice must be bounded");
|
||||
const src =
|
||||
indexSource.slice(floorStart, floorEnd) + "\n" +
|
||||
indexSource.slice(delayStart, delayEnd) + "\n" +
|
||||
indexSource.slice(notFoundStart, notFoundEnd) + "\n" +
|
||||
indexSource.slice(setStart, setEnd + 3) + "\n" +
|
||||
indexSource.slice(prefixStart, prefixEnd + 2) + "\n" +
|
||||
indexSource.slice(extStart, extEnd) + "\n" +
|
||||
indexSource.slice(clsStart, clsEnd) + "\n" +
|
||||
indexSource.slice(decodeStart, decodeEnd);
|
||||
// adpanel:stealth-mint-cap — the delay → getStealthBootstrapState window
|
||||
// now spans the mint-cap block, whose module-scope bindings (redisClient /
|
||||
// STEALTH_ACTIVE / buildSharedRateLimitRedisStore) are handed in per the
|
||||
// identical-binding rule above. A null client keeps this decoy-scoped
|
||||
// harness counter-free: the cap builds no stores and the decoy senders
|
||||
// under test are untouched.
|
||||
return new Function("path", "redisClient", "STEALTH_ACTIVE", "buildSharedRateLimitRedisStore",
|
||||
`${src}\nreturn { isStealthProtectedAssetPath, STEALTH_ASSET_PATHS, PRE_AUTH_STATIC_PREFIXES, sendStealthNotFound, STEALTH_RESPONSE_FLOOR_MS };`
|
||||
)(path, null, false, () => null);
|
||||
}
|
||||
|
||||
function loadKindSwitch(brandingUtils) {
|
||||
return new Function(
|
||||
"getExtensionFromUrl",
|
||||
"getMediaTypeFromUrl",
|
||||
"getMimeTypeForExtension",
|
||||
"getLogoExtensionFromUrl",
|
||||
`${KIND_SWITCH_SRC}\nreturn { getBrandingRemoteAssetConfig };`
|
||||
)(
|
||||
brandingUtils.getExtensionFromUrl,
|
||||
brandingUtils.getMediaTypeFromUrl,
|
||||
brandingUtils.getMimeTypeForExtension,
|
||||
brandingUtils.getLogoExtensionFromUrl
|
||||
).getBrandingRemoteAssetConfig;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Source pins
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("source: the set carries both branding kinds and documents the constraint", () => {
|
||||
const { STEALTH_ASSET_PATHS } = loadStealthScope();
|
||||
assert.ok(STEALTH_ASSET_PATHS.has("/branding-media/login-background"), "login-background keeps its set cover");
|
||||
assert.ok(STEALTH_ASSET_PATHS.has("/branding-media/logo"), "logo carries its set cover (the fix)");
|
||||
assert.strictEqual(STEALTH_ASSET_PATHS.size, 19, "only the retired CDN script is removed from the pinned set");
|
||||
// the constraint comment lives at the set, not elsewhere
|
||||
const setStart = indexOfOrThrow("const STEALTH_ASSET_PATHS = new Set([");
|
||||
const setEnd = indexSource.indexOf("]);", setStart);
|
||||
const setSlice = indexSource.slice(setStart, setEnd + 3);
|
||||
assert.ok(setSlice.includes("adpanel:branding-media-stealth-cover"), "the set must carry the adpanel:branding-media-stealth-cover comment");
|
||||
assert.ok(setSlice.includes("getBrandingRemoteAssetConfig"), "the comment must name the closed kind switch");
|
||||
assert.ok(setSlice.includes("sendStealthNotFound"), "the comment must name the decoy the gate serves");
|
||||
});
|
||||
|
||||
test("source: the branding route carries NO stealth logic — the cover lives only at the gate", () => {
|
||||
// One mechanism: no in-handler re-check forked beside the set cover (the
|
||||
// favicon's route-layer check is the exception BECAUSE that route is
|
||||
// excluded from the classifier; branding-media kinds are set-covered).
|
||||
assert.ok(!BRANDING_ROUTE_SRC.includes("STEALTH_ACTIVE"), "the route must not re-check STEALTH_ACTIVE");
|
||||
assert.ok(!BRANDING_ROUTE_SRC.includes("hasStealthAccess"), "the route must not re-check access");
|
||||
assert.ok(!BRANDING_ROUTE_SRC.includes("sendStealthNotFound"), "the route must not fork a decoy sender");
|
||||
assert.ok(!BRANDING_ROUTE_SRC.includes("sendStealthEmptyFavicon"), "the route must not fork the favicon decoy");
|
||||
assert.ok(!BRANDING_ROUTE_SRC.includes("adpanel:stealth"), "the route must not carry a stealth comment tag");
|
||||
// the favicon route's OWN in-handler check (its documented cover) is untouched
|
||||
const faviconStart = indexOfOrThrow('app.get("/auth-assets/favicon"');
|
||||
const faviconCatch = indexOfOrThrow('console.error("[auth-assets] Failed to serve favicon:"', faviconStart);
|
||||
const faviconSrc = indexSource.slice(faviconStart, faviconCatch);
|
||||
const check = "if (STEALTH_ACTIVE && !(await hasStealthAccess(req))) {";
|
||||
assert.ok(faviconSrc.includes(check), "the favicon route keeps its in-handler pre-flight");
|
||||
assert.ok(faviconSrc.indexOf(check) < faviconSrc.indexOf("const branding = loadBrandingConfig();"), "the favicon pre-flight stays first inside the guard try");
|
||||
});
|
||||
|
||||
test("source: the kind switch is CLOSED at exactly login-background and logo", () => {
|
||||
const kinds = KIND_SWITCH_SRC.match(/normalizedKind === "([a-z-]+)"/g) || [];
|
||||
assert.deepStrictEqual(
|
||||
kinds.sort(),
|
||||
['normalizedKind === "login-background"', 'normalizedKind === "logo"'],
|
||||
"the switch must stay exactly the two kinds the set mirrors — a new kind without a set entry reintroduces the leak"
|
||||
);
|
||||
});
|
||||
|
||||
test("unit: the kind switch resolves both kinds from config and 404s every other kind", () => {
|
||||
const brandingUtils = require("../utils/branding");
|
||||
const getBrandingRemoteAssetConfig = loadKindSwitch(brandingUtils);
|
||||
const branding = {
|
||||
logoUrl: "https://brand.example.com/logo.webp",
|
||||
loginBackgroundExternalUrl: "https://brand.example.com/bg.avif",
|
||||
loginBackgroundType: "image",
|
||||
};
|
||||
const logo = getBrandingRemoteAssetConfig("logo", branding);
|
||||
assert.ok(logo, "logo kind resolves");
|
||||
assert.strictEqual(logo.kind, "logo");
|
||||
assert.strictEqual(logo.sourceUrl, "https://brand.example.com/logo.webp");
|
||||
assert.strictEqual(logo.mediaType, "image");
|
||||
const bg = getBrandingRemoteAssetConfig("login-background", branding);
|
||||
assert.ok(bg, "login-background kind resolves");
|
||||
assert.strictEqual(bg.kind, "login-background");
|
||||
assert.strictEqual(bg.sourceUrl, "https://brand.example.com/bg.avif");
|
||||
for (const unknown of ["whatever", "", "LOGO/", "logo.svg", "favicon", null, undefined]) {
|
||||
assert.strictEqual(getBrandingRemoteAssetConfig(unknown, branding), null, `unknown kind falls to null: ${String(unknown)}`);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Behavioral harness: production order — stealth gate (REAL classifier, REAL
|
||||
// decoy sender) → the REAL extracted /branding-media/:kind handler →
|
||||
// fallthrough. loadBrandingRemoteAsset is stubbed (the remote-fetch machinery
|
||||
// is not under test; the COVER is) with a call counter so the pre-gate pins
|
||||
// can prove the route never ran.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function buildHarness({ stealthActive, hasAccess, branding }) {
|
||||
const express = require("express");
|
||||
const brandingUtils = require("../utils/branding");
|
||||
const { isStealthProtectedAssetPath, sendStealthNotFound } = loadStealthScope();
|
||||
const getBrandingRemoteAssetConfig = loadKindSwitch(brandingUtils);
|
||||
const app = express();
|
||||
const hasStealthAccess = async () => (stealthActive ? !!hasAccess : true);
|
||||
if (stealthActive) {
|
||||
// mirror of index.js's stealth gate middleware (asset leg): classify on
|
||||
// req.path with the REAL classifier, pass on access, else 404 decoy
|
||||
app.use(async (req, res, next) => {
|
||||
const pathName = String(req.path || "").trim();
|
||||
const isProtectedAssetPath = isStealthProtectedAssetPath(pathName);
|
||||
if (!isProtectedAssetPath) return next();
|
||||
try {
|
||||
if (await hasStealthAccess(req)) return next();
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
return sendStealthNotFound(res).catch(next);
|
||||
});
|
||||
}
|
||||
let remoteLoads = 0;
|
||||
const loadBrandingRemoteAsset = async (assetConfig) => {
|
||||
remoteLoads += 1;
|
||||
return {
|
||||
buffer: Buffer.from(assetConfig.kind === "logo" ? "REMOTE-LOGO-BYTES" : "REMOTE-BG-BYTES"),
|
||||
mimeType: assetConfig.mimeType || "image/webp",
|
||||
};
|
||||
};
|
||||
const svgHeaders = new Function(`${SVG_HEADERS_SRC}\nreturn { applySvgContentSecurityHeaders };`)().applySvgContentSecurityHeaders;
|
||||
// registers the REAL handler source on the harness app (app.get(...) returns
|
||||
// the app for chaining; registration itself is proven by the behavior tests —
|
||||
// an unregistered route would fall through to the FALLTHROUGH marker)
|
||||
new Function(
|
||||
"app",
|
||||
"brandingAssetRateLimiter",
|
||||
"loadBrandingConfig",
|
||||
"getBrandingRemoteAssetConfig",
|
||||
"loadBrandingRemoteAsset",
|
||||
"applySvgContentSecurityHeaders",
|
||||
BRANDING_ROUTE_SRC
|
||||
)(
|
||||
app,
|
||||
(req, res, next) => next(),
|
||||
() => branding,
|
||||
getBrandingRemoteAssetConfig,
|
||||
loadBrandingRemoteAsset,
|
||||
svgHeaders
|
||||
);
|
||||
app.use((req, res) => res.status(404).send("FALLTHROUGH"));
|
||||
return { app, loadCount: () => remoteLoads };
|
||||
}
|
||||
|
||||
function startServer(app) {
|
||||
const server = app.listen(0, "127.0.0.1");
|
||||
return new Promise((resolve) => server.once("listening", () => resolve(server)));
|
||||
}
|
||||
|
||||
function rawRequest(server, method, requestPath) {
|
||||
const port = server.address().port;
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request({ host: "127.0.0.1", port, path: requestPath, method }, (res) => {
|
||||
let body = "";
|
||||
res.on("data", (c) => (body += c));
|
||||
res.on("error", reject);
|
||||
res.on("end", () => resolve({ status: res.statusCode, body, headers: res.headers }));
|
||||
});
|
||||
req.on("error", reject);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// The decoy fingerprint: what an unauthenticated prober must see for every
|
||||
// covered branding kind under stealth — the SAME sendStealthNotFound shape
|
||||
// the login-background sibling already serves (404-empty, no-store, no
|
||||
// Location, stealth response floor).
|
||||
function assertGateDecoyShape(r, label) {
|
||||
assert.strictEqual(r.status, 404, label);
|
||||
assert.strictEqual(r.body, "", label);
|
||||
assert.strictEqual(r.headers.location, undefined, `${label}: no Location header`);
|
||||
assert.strictEqual(r.headers["cache-control"], "no-store, private", label);
|
||||
assert.strictEqual(r.headers["x-content-type-options"], "nosniff", label);
|
||||
assert.strictEqual(
|
||||
r.headers["content-security-policy"],
|
||||
"default-src 'none'; base-uri 'none'; frame-ancestors 'none'; object-src 'none';",
|
||||
label
|
||||
);
|
||||
}
|
||||
|
||||
test("behavior: stealth ON no-access + remote-logo branding — the logo bytes never reach the prober", async () => {
|
||||
const { app, loadCount } = buildHarness({
|
||||
stealthActive: true,
|
||||
hasAccess: false,
|
||||
branding: { logoUrl: "https://brand.example.com/logo.webp", loginBackgroundExternalUrl: null, loginBackgroundType: "video" },
|
||||
});
|
||||
let server;
|
||||
try {
|
||||
server = await startServer(app);
|
||||
const r = await rawRequest(server, "GET", "/branding-media/logo");
|
||||
assertGateDecoyShape(r, "/branding-media/logo pre-gate");
|
||||
assert.notStrictEqual(r.body, "REMOTE-LOGO-BYTES", "remote logo bytes must not leak pre-gate");
|
||||
assert.strictEqual(loadCount(), 0, "the route must never run pre-gate (no remote fetch)");
|
||||
// parity: the decoyed logo and the decoyed login-background are
|
||||
// indistinguishable to the prober
|
||||
const bgBranding = {
|
||||
logoUrl: "https://brand.example.com/logo.webp",
|
||||
loginBackgroundExternalUrl: "https://brand.example.com/bg.avif",
|
||||
loginBackgroundType: "image",
|
||||
};
|
||||
const { app: app2 } = buildHarness({ stealthActive: true, hasAccess: false, branding: bgBranding });
|
||||
const server2 = await startServer(app2);
|
||||
try {
|
||||
const bg = await rawRequest(server2, "GET", "/branding-media/login-background");
|
||||
assertGateDecoyShape(bg, "/branding-media/login-background pre-gate parity");
|
||||
const logo2 = await rawRequest(server2, "GET", "/branding-media/logo");
|
||||
assertGateDecoyShape(logo2, "/branding-media/logo pre-gate parity");
|
||||
} finally {
|
||||
server2.close();
|
||||
}
|
||||
const head = await rawRequest(server, "HEAD", "/branding-media/logo");
|
||||
assert.strictEqual(head.status, 404, "HEAD no-access → decoy");
|
||||
assert.strictEqual(head.body, "", "HEAD decoy body empty");
|
||||
} finally {
|
||||
if (server) server.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("behavior: stealth ON no-access — encoded spelling decodes onto the covered entry", async () => {
|
||||
const { app, loadCount } = buildHarness({
|
||||
stealthActive: true,
|
||||
hasAccess: false,
|
||||
branding: { logoUrl: "https://brand.example.com/logo.webp", loginBackgroundExternalUrl: null, loginBackgroundType: "video" },
|
||||
});
|
||||
let server;
|
||||
try {
|
||||
server = await startServer(app);
|
||||
const r = await rawRequest(server, "GET", "/branding-media/%6Cogo");
|
||||
assertGateDecoyShape(r, "/branding-media/%6Cogo pre-gate");
|
||||
assert.strictEqual(loadCount(), 0, "the encoded spelling must not reach the route either");
|
||||
} finally {
|
||||
if (server) server.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("behavior: stealth ON gated — the route serves exactly as before the cover existed", async () => {
|
||||
const { app, loadCount } = buildHarness({
|
||||
stealthActive: true,
|
||||
hasAccess: true,
|
||||
branding: {
|
||||
logoUrl: "https://brand.example.com/logo.webp",
|
||||
loginBackgroundExternalUrl: "https://brand.example.com/bg.avif",
|
||||
loginBackgroundType: "image",
|
||||
},
|
||||
});
|
||||
let server;
|
||||
try {
|
||||
server = await startServer(app);
|
||||
const r = await rawRequest(server, "GET", "/branding-media/logo");
|
||||
assert.strictEqual(r.status, 200, "gated → the route serves");
|
||||
assert.strictEqual(r.body, "REMOTE-LOGO-BYTES", "gated → remote logo bytes");
|
||||
assert.strictEqual(r.headers["content-type"], "image/webp", "gated content-type unchanged");
|
||||
assert.strictEqual(r.headers["cache-control"], "public, max-age=300", "gated route cache posture unchanged");
|
||||
assert.strictEqual(loadCount(), 1, "the route ran once for the gated request");
|
||||
const bg = await rawRequest(server, "GET", "/branding-media/login-background");
|
||||
assert.strictEqual(bg.status, 200, "gated login-background unchanged");
|
||||
assert.strictEqual(bg.body, "REMOTE-BG-BYTES", "gated login-background bytes unchanged");
|
||||
assert.strictEqual(loadCount(), 2, "both kinds served by the route when gated");
|
||||
} finally {
|
||||
if (server) server.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("behavior: stealth OFF — gate middleware absent, route behavior identical (bytes and the route's own 404)", async () => {
|
||||
const { app, loadCount } = buildHarness({
|
||||
stealthActive: false,
|
||||
hasAccess: false,
|
||||
branding: {
|
||||
logoUrl: "https://brand.example.com/logo.webp",
|
||||
loginBackgroundExternalUrl: "https://brand.example.com/bg.avif",
|
||||
loginBackgroundType: "image",
|
||||
},
|
||||
});
|
||||
let server;
|
||||
try {
|
||||
server = await startServer(app);
|
||||
const r = await rawRequest(server, "GET", "/branding-media/logo");
|
||||
assert.strictEqual(r.status, 200, "stealth off → remote logo bytes served");
|
||||
assert.strictEqual(r.body, "REMOTE-LOGO-BYTES", "stealth off body unchanged");
|
||||
assert.strictEqual(r.headers["cache-control"], "public, max-age=300", "stealth off cache posture unchanged");
|
||||
const bg = await rawRequest(server, "GET", "/branding-media/login-background");
|
||||
assert.strictEqual(bg.status, 200, "stealth off login-background unchanged");
|
||||
assert.strictEqual(loadCount(), 2, "both kinds served by the route with stealth off");
|
||||
// with NO remote logo configured, the route's own constant 404 answers —
|
||||
// body "not found" proves the ROUTE layer answered, not the gate decoy
|
||||
const { app: app2, loadCount: loads2 } = buildHarness({
|
||||
stealthActive: false,
|
||||
hasAccess: false,
|
||||
branding: { logoUrl: null, loginBackgroundExternalUrl: null, loginBackgroundType: "video" },
|
||||
});
|
||||
const server2 = await startServer(app2);
|
||||
try {
|
||||
const none = await rawRequest(server2, "GET", "/branding-media/logo");
|
||||
assert.strictEqual(none.status, 404, "no remote logo → route's own 404 (stealth off)");
|
||||
assert.strictEqual(none.body, "not found", "the route's constant 404 body — proves the ROUTE answered, not the gate decoy (empty body)");
|
||||
assert.strictEqual(loads2(), 0, "no remote fetch without a configured logo");
|
||||
const unknown = await rawRequest(server2, "GET", "/branding-media/whatever");
|
||||
assert.strictEqual(unknown.status, 404, "unknown kind → route's own 404 (stealth off)");
|
||||
assert.strictEqual(unknown.body, "not found", "unknown kinds fall to the closed switch's null → route 404");
|
||||
} finally {
|
||||
server2.close();
|
||||
}
|
||||
} finally {
|
||||
if (server) server.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("behavior: stealth ON no-access — classifier pins for the branding surface", () => {
|
||||
const { isStealthProtectedAssetPath } = loadStealthScope();
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/logo"), true, "logo classifies PROTECTED (the fix)");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/login-background"), true, "login-background stays PROTECTED");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/%6Cogo"), true, "encoded logo spelling decodes onto the entry");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/whatever"), false, "unknown kinds stay outside the asset classification (route's constant 404, no operator content)");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/dashboard"), false, "non-asset unchanged");
|
||||
// 2026-11-13 (adpanel:stealth-asset-spelling-parity): the formerly-pinned
|
||||
// spelling-exact residual is consciously REVERSED — the router serves the
|
||||
// trailing-slash and case-variant spellings of the branding-media routes
|
||||
// (strict:false + caseSensitive:false, verified against the installed
|
||||
// express) and each spelling carried the operator's REAL remote bytes
|
||||
// pre-gate while the canonical spellings decoyed. Every spelling the route
|
||||
// would serve must classify onto the same entry.
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/logo/"), true, "trailing-slash spelling decoys (strict:false serves it)");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/BRANDING-MEDIA/logo"), true, "case-variant spelling decoys (caseSensitive:false serves it)");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/BRANDING-MEDIA/LOGO"), true, "full-uppercase spelling decoys");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/LOGO/"), true, "case + trailing-slash spelling decoys");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/login-background/"), true, "login-background trailing-slash spelling decoys");
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/Auth-Assets/Logo"), true, "case-variant /auth-assets/ branding route spelling decoys (prefix leg on the folded form)");
|
||||
// the router 404s the double-slash spelling (it normalizes onto the one-slash
|
||||
// form send-style, so it classifies onto the entry) — a bare-404 spelling
|
||||
// takes the uniform decoy, no content either way
|
||||
assert.strictEqual(isStealthProtectedAssetPath("/branding-media/logo//"), true, "double-slash spelling normalizes onto the covered one-slash form — uniform decoy");
|
||||
});
|
||||
|
||||
test("behavior: stealth ON no-access — the router-served spelling variants decoy identically (spelling-parity residual closed)", async () => {
|
||||
// adpanel:stealth-asset-spelling-parity — the leak spellings verified
|
||||
// against the pre-fix classifier: under stealth + no access each of these
|
||||
// ROUTED (express strict:false / caseSensitive:false) and served the
|
||||
// operator's remote bytes while the canonical spelling decoyed. All must
|
||||
// now take the SAME gate decoy with the route never running.
|
||||
const { app, loadCount } = buildHarness({
|
||||
stealthActive: true,
|
||||
hasAccess: false,
|
||||
branding: { logoUrl: "https://brand.example.com/logo.webp", loginBackgroundExternalUrl: "https://brand.example.com/bg.avif", loginBackgroundType: "image" },
|
||||
});
|
||||
let server;
|
||||
try {
|
||||
server = await startServer(app);
|
||||
for (const spelling of [
|
||||
"/branding-media/logo/",
|
||||
"/branding-media/login-background/",
|
||||
"/BRANDING-MEDIA/logo",
|
||||
"/BRANDING-MEDIA/LOGO",
|
||||
"/branding-media/LOGO/",
|
||||
]) {
|
||||
const r = await rawRequest(server, "GET", spelling);
|
||||
assertGateDecoyShape(r, `${spelling} pre-gate (spelling parity)`);
|
||||
assert.notStrictEqual(r.body, "REMOTE-LOGO-BYTES", `${spelling}: remote logo bytes must not leak`);
|
||||
assert.notStrictEqual(r.body, "REMOTE-BG-BYTES", `${spelling}: remote background bytes must not leak`);
|
||||
}
|
||||
assert.strictEqual(loadCount(), 0, "the route must never run for any spelling pre-gate (no remote fetch)");
|
||||
// the double-slash spelling the router 404s also decoys (uniform, no content)
|
||||
const dbl = await rawRequest(server, "GET", "/branding-media/logo//");
|
||||
assert.strictEqual(dbl.status, 404);
|
||||
assert.strictEqual(dbl.body, "");
|
||||
assert.strictEqual(loadCount(), 0);
|
||||
} finally {
|
||||
if (server) server.close();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user