From 53ea3b86336885fe54f0f2987cf42adfcf8e2f3a Mon Sep 17 00:00:00 2001 From: CanLite24 Date: Tue, 31 Mar 2026 19:55:35 -0600 Subject: [PATCH 1/3] scrambling --- index.js | 3 + scrambleMiddleware.js | 493 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 496 insertions(+) create mode 100644 scrambleMiddleware.js diff --git a/index.js b/index.js index fcb5579..8421a78 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ import { RedisStore } from "connect-redis"; import { setupCanScreen } from "./CanScreen.js" import pool from "./db.js"; import cors from "cors"; +import { scrambleMiddleware, startSessionCleanup } from './scrambleMiddleware.js'; import axios from "axios"; const __filename = fileURLToPath(import.meta.url); @@ -87,6 +88,8 @@ app.use( sessionMiddleware ); +app.use(scrambleMiddleware); +startSessionCleanup(redisClient); app.use(express.json({ limit: "50mb" })); app.use(express.urlencoded({ extended: true, limit: "50mb" })); diff --git a/scrambleMiddleware.js b/scrambleMiddleware.js new file mode 100644 index 0000000..7745279 --- /dev/null +++ b/scrambleMiddleware.js @@ -0,0 +1,493 @@ +/** + * scrambleMiddleware.js + * + * Express middleware that rewrites outgoing HTML/CSS/JS with session-unique + * random tokens so every user sees structurally different markup and code. + * + * Features: + * - CSS class & ID scrambling (regex, fast) + * - HTML attribute scrambling (class=, id=, inline