Update Apache SSL configuration and enhance security features across multiple files. Changed X-Frame-Options to SAMEORIGIN for better security, added optional Content Security Policy headers for testing, and improved password handling with HaveIBeenPwned checks during user registration and password reset. Implemented passkey login functionality in the authentication flow, including UI updates for user experience. Enhanced image upload processing with size limits and validation, and added rate limiting for various API endpoints to prevent abuse.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 51s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 51s
This commit is contained in:
@@ -4,6 +4,7 @@ import path from 'path'
|
||||
import sharp from 'sharp'
|
||||
import { getUserFromToken, verifyToken, hasAnyRole } from '../../utils/auth.js'
|
||||
import { randomUUID } from 'crypto'
|
||||
import { clamp } from '../../utils/upload-validation.js'
|
||||
|
||||
// Handle both dev and production paths
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
@@ -155,10 +156,36 @@ export default defineEventHandler(async (event) => {
|
||||
const filename = `${titleSlug}_${randomUUID().substring(0, 8)}${ext}`
|
||||
const previewFilename = `preview_${filename}`
|
||||
|
||||
// Verschiebe die Datei zum neuen Namen
|
||||
// Originalbild verarbeiten: re-encode (EXIF entfernen) + Pixel/DIM-Limit
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
const originalPath = path.join(GALERIE_DIR, 'originals', filename)
|
||||
await fs.rename(file.path, originalPath)
|
||||
|
||||
const maxPixels = Number(process.env.IMAGE_MAX_PIXELS || 20_000_000) // 20MP
|
||||
const maxDim = Number(process.env.IMAGE_MAX_DIM || 4000) // px
|
||||
|
||||
const meta = await sharp(file.path).metadata()
|
||||
const w = meta.width || 0
|
||||
const h = meta.height || 0
|
||||
|
||||
let pipeline = sharp(file.path).rotate()
|
||||
|
||||
if (w > 0 && h > 0) {
|
||||
const pixels = w * h
|
||||
if (pixels > maxPixels) {
|
||||
const scale = Math.sqrt(maxPixels / pixels)
|
||||
const nw = clamp(Math.floor(w * scale), 1, maxDim)
|
||||
const nh = clamp(Math.floor(h * scale), 1, maxDim)
|
||||
pipeline = pipeline.resize(nw, nh, { fit: 'inside', withoutEnlargement: true })
|
||||
} else if (w > maxDim || h > maxDim) {
|
||||
pipeline = pipeline.resize(maxDim, maxDim, { fit: 'inside', withoutEnlargement: true })
|
||||
}
|
||||
} else {
|
||||
pipeline = pipeline.resize(maxDim, maxDim, { fit: 'inside', withoutEnlargement: true })
|
||||
}
|
||||
|
||||
await pipeline.toFile(originalPath)
|
||||
// Temp-Datei löschen
|
||||
await fs.unlink(file.path).catch(() => {})
|
||||
|
||||
// nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
||||
const previewPath = path.join(GALERIE_DIR, 'previews', previewFilename)
|
||||
|
||||
Reference in New Issue
Block a user