From 2f4b8a64c0eedc9bac87a6730a6591f7daa06ac6 Mon Sep 17 00:00:00 2001 From: Paul Nothaft <53005142+the-luap@users.noreply.github.com> Date: Sun, 19 Jul 2026 00:40:53 +0200 Subject: [PATCH] chore(backend): ignore runtime storage in git/docker, remove dead getSafeFilename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-ups from the codex review of #834: - .gitignore: backend/storage/ is runtime-generated (media, previews, thumbnails, business docs) and was only partially ignored — E2E runs left it dangling as untracked, which is how ~12 MB of artifacts nearly landed in a commit. Ignore the whole directory (nothing under it is tracked); replaces the narrower business-docs rule. - backend/.dockerignore: the granular storage/* rules missed storage/previews, so locally generated previews were copied into production images. Exclude storage entirely — the Dockerfile creates the needed directories itself (RUN mkdir -p, Dockerfile:96). - fileSecurityUtils.js: remove getSafeFilename — zero callers across the repo, and its private extension whitelist silently drifted from the real validation paths (see #834), which is exactly the trap dead security code sets. --- .gitignore | 5 +++-- backend/.dockerignore | 4 +--- backend/src/utils/fileSecurityUtils.js | 20 -------------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 956c3b23..d066ec46 100644 --- a/.gitignore +++ b/.gitignore @@ -130,5 +130,6 @@ docker-compose.dev.yml # New layout development files new-layouts/ -# Generated CRM/accounting documents (runtime) — never commit -backend/storage/business-docs/ +# Backend runtime storage (generated media, previews, thumbnails, +# CRM/accounting documents) — never commit +backend/storage/ diff --git a/backend/.dockerignore b/backend/.dockerignore index e4d1265f..ef5a7a92 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,9 +1,7 @@ node_modules npm-debug.log .env -storage/events/active/* -storage/events/archived/* -storage/thumbnails/* +storage data/*.db logs/* coverage diff --git a/backend/src/utils/fileSecurityUtils.js b/backend/src/utils/fileSecurityUtils.js index 5eec0f0f..05dbb194 100644 --- a/backend/src/utils/fileSecurityUtils.js +++ b/backend/src/utils/fileSecurityUtils.js @@ -213,25 +213,6 @@ async function validateFileContent(filePath, expectedMimeType) { } } -/** - * Get safe filename for storage - * @param {string} originalFilename - Original filename - * @returns {string} - Safe filename - */ -function getSafeFilename(originalFilename) { - const timestamp = Date.now(); - const randomString = Math.random().toString(36).substring(2, 15); - const ext = path.extname(originalFilename).toLowerCase(); - - // Validate extension - including both image and video extensions - const validExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.svg', '.ico', '.mp4', '.m4v', '.webm', '.mov', '.avi']; - if (!validExtensions.includes(ext)) { - throw new Error('Invalid file extension'); - } - - return `upload_${timestamp}_${randomString}${ext}`; -} - /** * Create a file upload validator middleware * @param {Object} options - Validation options @@ -295,7 +276,6 @@ module.exports = { isPathSafe, validateFileType, validateFileContent, - getSafeFilename, createFileUploadValidator, ALLOWED_IMAGE_TYPES, ALLOWED_VIDEO_TYPES,