fix(security): allow serving static files from uploads directory
- Remove overly restrictive absolute path check in isPathSafe - Strip leading slash from request path before validation - Fixes broken favicon and watermark image previews in branding page - Path traversal protection remains intact with ../ pattern checks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
This commit is contained in:
@@ -12,8 +12,8 @@ function secureStatic(basePath, options = {}) {
|
|||||||
const normalizedBase = path.resolve(basePath);
|
const normalizedBase = path.resolve(basePath);
|
||||||
|
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
// Get the requested file path
|
// Get the requested file path - remove leading slash for validation
|
||||||
const requestedPath = req.path;
|
const requestedPath = req.path.startsWith('/') ? req.path.substring(1) : req.path;
|
||||||
|
|
||||||
// Validate the path doesn't contain dangerous patterns
|
// Validate the path doesn't contain dangerous patterns
|
||||||
if (!isPathSafe(requestedPath)) {
|
if (!isPathSafe(requestedPath)) {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ function isPathSafe(filePath) {
|
|||||||
// Check for common path traversal patterns
|
// Check for common path traversal patterns
|
||||||
const dangerousPatterns = [
|
const dangerousPatterns = [
|
||||||
/\.\.[\/\\]/, // ../ or ..\
|
/\.\.[\/\\]/, // ../ or ..\
|
||||||
/^[\/\\]/, // Absolute paths
|
|
||||||
/^[A-Za-z]:/, // Windows drive letters
|
/^[A-Za-z]:/, // Windows drive letters
|
||||||
/[\x00-\x1f]/ // Control characters
|
/[\x00-\x1f]/ // Control characters
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user