← back to Textiletuesday
server.js: 404-guard for .bak/.pre-/.orig static paths
22b4c48df82b7f072104f268f162d30a5e01ef58 · 2026-05-19 17:19:11 -0700 · Steve Abrams
Adds an Express middleware before express.static so any request for a
snapshot/backup file (e.g. index.html.bak, server.js.pre-refactor,
foo.orig) returns 404 rather than leaking the file contents. Pairs with
the .gitignore broadening so these files are both excluded from git AND
unserveable at runtime.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 22b4c48df82b7f072104f268f162d30a5e01ef58
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue May 19 17:19:11 2026 -0700
server.js: 404-guard for .bak/.pre-/.orig static paths
Adds an Express middleware before express.static so any request for a
snapshot/backup file (e.g. index.html.bak, server.js.pre-refactor,
foo.orig) returns 404 rather than leaking the file contents. Pairs with
the .gitignore broadening so these files are both excluded from git AND
unserveable at runtime.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
server.js | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/server.js b/server.js
index 8a1eaae..d2321f8 100644
--- a/server.js
+++ b/server.js
@@ -6,6 +6,15 @@ const app = express();
const PORT = process.env.PORT || 9899;
app.use(express.json());
+
+// 404-guard: never serve .bak / .pre-* / .orig snapshot files from static root
+app.use((req, res, next) => {
+ if (/\.(bak|orig)(\?|$)/i.test(req.path) || /\.pre-/i.test(req.path)) {
+ return res.status(404).send('Not found');
+ }
+ next();
+});
+
app.use(express.static(path.join(__dirname, 'public')));
const products = JSON.parse(fs.readFileSync(path.join(__dirname, 'data/products.json'), 'utf8'));
← 2bcd0cc broaden .gitignore to exclude .bak/.pre-* snapshot files
·
back to Textiletuesday
·
public/index.html: add noreferrer to all target=_blank exter 4ebea26 →