From 649724de1170bcdda98c9925d9330f4bfe6a75bb Mon Sep 17 00:00:00 2001 From: Do Siki Date: Mon, 27 Apr 2026 01:11:51 +0200 Subject: [PATCH] feat: add basic auth protection to CMS editor --- content-editor.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/content-editor.js b/content-editor.js index 9837e57..4e5322c 100644 --- a/content-editor.js +++ b/content-editor.js @@ -356,7 +356,20 @@ if (toast) setTimeout(() => toast.remove(), 3500); // ── Server ─────────────────────────────────────────────────────────────────── +const CMS_USER = process.env.CMS_USER || 'admin'; +const CMS_PASS = process.env.CMS_PASS || 'mozdit2026'; + const server = http.createServer(async (req, res) => { + // Basic Auth verification + const b64auth = (req.headers.authorization || '').split(' ')[1] || ''; + const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':'); + + if (login !== CMS_USER || password !== CMS_PASS) { + res.writeHead(401, { 'WWW-Authenticate': 'Basic realm="mozdIT CMS"' }); + res.end('Access denied'); + return; + } + const u = new URL(req.url, `http://localhost:${PORT}`); const fileKey = u.searchParams.get('file') || 'home'; const activeFile = FILES[fileKey] ? fileKey : 'home';