diff --git a/backend/src/middleware/secureStatic.js b/backend/src/middleware/secureStatic.js index ab9d9b0..185d9d4 100644 --- a/backend/src/middleware/secureStatic.js +++ b/backend/src/middleware/secureStatic.js @@ -12,8 +12,8 @@ function secureStatic(basePath, options = {}) { const normalizedBase = path.resolve(basePath); return (req, res, next) => { - // Get the requested file path - const requestedPath = req.path; + // Get the requested file path - remove leading slash for validation + const requestedPath = req.path.startsWith('/') ? req.path.substring(1) : req.path; // Validate the path doesn't contain dangerous patterns if (!isPathSafe(requestedPath)) { diff --git a/backend/src/utils/fileSecurityUtils.js b/backend/src/utils/fileSecurityUtils.js index 624d2ad..b7fb11d 100644 --- a/backend/src/utils/fileSecurityUtils.js +++ b/backend/src/utils/fileSecurityUtils.js @@ -37,7 +37,6 @@ function isPathSafe(filePath) { // Check for common path traversal patterns const dangerousPatterns = [ /\.\.[\/\\]/, // ../ or ..\ - /^[\/\\]/, // Absolute paths /^[A-Za-z]:/, // Windows drive letters /[\x00-\x1f]/ // Control characters ];