[object Object]

← back to AbramsOS

ignore + 404-guard backup/snapshot files

551b5ea1175214b1091b3f79101d2f3d73a5693f · 2026-05-19 17:27:14 -0700 · Steve

.gitignore now excludes *.bak, *.bak.*, *.pre-*, *.orig, *~ so editor
swap files and pre-edit snapshots can't be accidentally committed and
end up served from /public. Backstop in server.js: any GET whose path
matches those patterns short-circuits to 404 before express.static,
so even a stray on-disk *.bak.html can never leak.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 551b5ea1175214b1091b3f79101d2f3d73a5693f
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue May 19 17:27:14 2026 -0700

    ignore + 404-guard backup/snapshot files
    
    .gitignore now excludes *.bak, *.bak.*, *.pre-*, *.orig, *~ so editor
    swap files and pre-edit snapshots can't be accidentally committed and
    end up served from /public. Backstop in server.js: any GET whose path
    matches those patterns short-circuits to 404 before express.static,
    so even a stray on-disk *.bak.html can never leak.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 .gitignore | 7 +++++++
 server.js  | 9 +++++++++
 2 files changed, 16 insertions(+)

diff --git a/.gitignore b/.gitignore
index 1b49b15..6d518fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,10 @@ logs/*
 coverage/
 *.tgz
 .npm/
+
+# snapshot / backup files — never commit, never serve
+*.bak
+*.bak.*
+*.pre-*
+*.orig
+*~
diff --git a/server.js b/server.js
index 3214c0c..9ccd9c4 100644
--- a/server.js
+++ b/server.js
@@ -51,6 +51,15 @@ app.use((req, res, next) => {
   next();
 });
 
+// Defensive 404-guard: never serve backup/snapshot files from /public, even if
+// one accidentally lands on disk (*.bak, *.bak.<n>, *.pre-*, *.orig, *~).
+app.use((req, res, next) => {
+  if (/\.(bak|orig)(\.[^/]+)?$|\.pre-[^/]+$|~$/i.test(req.path)) {
+    return res.status(404).type('text/plain').send('Not found');
+  }
+  next();
+});
+
 app.use(express.static(path.join(__dirname, 'public'), { maxAge: '0' }));
 
 // Public routes

← 20f8f36 add noreferrer to target=_blank external links  ·  back to AbramsOS  ·  Add per-site favicon (kills /favicon.ico 404) 2e0044d →