73 lines
3.4 KiB
JavaScript
73 lines
3.4 KiB
JavaScript
"use strict";
|
|
|
|
// adpanel:bp-cookie-removal — source pins for the unused adpanel.bp cookie.
|
|
//
|
|
// ensureBotProofSeed's bot-proof mechanism is the SESSION seed
|
|
// (req.session.botProofSeed, validated by isBotProofValid against the form's
|
|
// botProof field); the adpanel.bp cookie only echoed the seed to the browser
|
|
// and nothing in the repo ever read it back. These pins hold the guarantees:
|
|
// 1. no res.cookie (or cookie-setting) call for adpanel.bp remains — the
|
|
// panel must not re-issue a value-echoing cookie no reader consumes;
|
|
// 2. the name STAYS in the db-proxy panelCookieNames strip lists (both the
|
|
// panel registration in index.js and PANEL_COOKIE_NAMES in
|
|
// utils/db-proxy.js) so stale cookies already on clients are never
|
|
// forwarded to the proxied backends;
|
|
// 3. the session-side bot-proof mechanism is untouched — the seed is still
|
|
// stored on the session and still validated from the form field.
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
|
|
const ROOT = path.join(__dirname, "..");
|
|
const INDEX_JS = path.join(ROOT, "index.js");
|
|
const DB_PROXY_JS = path.join(ROOT, "utils", "db-proxy.js");
|
|
|
|
const indexSource = fs.readFileSync(INDEX_JS, "utf8");
|
|
const dbProxySource = fs.readFileSync(DB_PROXY_JS, "utf8");
|
|
|
|
test("pins: no adpanel.bp cookie is ever set again", () => {
|
|
assert.ok(
|
|
!indexSource.includes('res.cookie("adpanel.bp"'),
|
|
"ensureBotProofSeed must not re-issue the unread adpanel.bp cookie"
|
|
);
|
|
assert.ok(
|
|
!/res\.cookie\(\s*["'`]adpanel\.bp["'`]/.test(indexSource),
|
|
"no cookie-setting call for adpanel.bp may exist anywhere in index.js"
|
|
);
|
|
assert.ok(
|
|
!/["'`]adpanel\.bp["'`]\s*,\s*seed/.test(indexSource),
|
|
"no dynamic or reordered cookie write of the seed under the adpanel.bp name"
|
|
);
|
|
});
|
|
|
|
test("pins: adpanel.bp stays in the db-proxy panel cookie strip lists", () => {
|
|
const registrationStart = indexSource.indexOf("dbProxy.createProxyMiddleware({");
|
|
assert.ok(registrationStart >= 0, "the db-proxy middleware registration must exist");
|
|
const registration = indexSource.slice(registrationStart, registrationStart + 400);
|
|
assert.ok(
|
|
registration.includes('"adpanel.bp"'),
|
|
"panelCookieNames passed to dbProxy.createProxyMiddleware must still list adpanel.bp"
|
|
);
|
|
assert.ok(
|
|
/PANEL_COOKIE_NAMES\s*=\s*new Set\(\[[^\]]*"adpanel\.bp"[^\]]*\]\)/.test(dbProxySource),
|
|
"utils/db-proxy.js PANEL_COOKIE_NAMES must still list adpanel.bp"
|
|
);
|
|
});
|
|
|
|
test("pins: the session-side bot-proof mechanism is untouched", () => {
|
|
const seedFnStart = indexSource.indexOf("function ensureBotProofSeed(req, res) {");
|
|
assert.ok(seedFnStart >= 0, "ensureBotProofSeed must still exist");
|
|
const seedFn = indexSource.slice(seedFnStart, indexSource.indexOf("\n}", seedFnStart));
|
|
assert.ok(seedFn.includes("req.session.botProofSeed = seed;"), "the session seed write must remain");
|
|
assert.ok(seedFn.includes("return seed;"), "the seed return must remain");
|
|
const validateFnStart = indexSource.indexOf("function isBotProofValid(req, value) {");
|
|
assert.ok(validateFnStart >= 0, "isBotProofValid must still exist");
|
|
const validateFn = indexSource.slice(validateFnStart, indexSource.indexOf("\n}", validateFnStart));
|
|
assert.ok(
|
|
validateFn.includes("req?.session?.botProofSeed"),
|
|
"validation must keep comparing against the session seed, not a cookie"
|
|
);
|
|
});
|