Commit Graph
3 Commits
Author SHA1 Message Date
Lauri Ojansivu 9b03e77de0 Validate an uploaded attachment/avatar's real content type against its
declared MIME type, and reject a dangerous mismatch (e.g. an executable
or script renamed with an image/document extension).

Restores the code from an earlier local commit (61e857d96) that a later
concurrent "Update changelog." commit (715140a2bb) accidentally reverted
by committing a stale working tree - CHANGELOG.md's entry for this
already points at 61e857d96, which still contains the original change
in its tree; this recreates it in the current tree so HEAD is not
missing the guard it documents.

fileValidation.js already sniffed content for dangerous HTML/SVG/XML
markup, but a spoofed executable (a Windows PE .exe, an ELF binary, a
Mach-O binary, or a shell/batch script) disguised with an image or
document extension and Content-Type passed through untouched, since
those binary formats were never on the dangerous-MIME deny-list.

models/lib/uploadContentMismatch.js is a pure decision module (no
server, no I/O) that flags only a MEANINGFUL, dangerous mismatch:
content that magic-byte-sniffs as executable/script while the client
declared an image/document/text/audio/video/archive type. It
deliberately does not flag compatible textual differences (text/plain
vs text/csv) to avoid false-positive breakage of legitimate uploads,
and does not flag an executable honestly declared as one (the
allow-list already governs whether executables are allowed at all).

fileValidation.js's isFileValid() - the single choke point already used
by both models/attachments.server.js and models/avatars.server.js - now
sniffs the file's real type with the `file-type` package (already a
dependency, MIT-licensed, used the same way for extension correction in
models/lib/fileTypeCorrection.js) and rejects a dangerous mismatch,
logging the blocked attempt to Admin Panel -> Problems under the
existing 'file.mime' security-log key (CWE-434, MimeBleed). Logging is
wrapped so a detection failure can never block a legitimate upload or
break the guard.

tests/uploadContentMismatch.test.cjs unit-tests the pure decision
function directly: positive cases for legitimate uploads of each
declared type, negative cases for a PE/.exe, an ELF binary, a Mach-O
binary and a shell/batch script each disguised with an image or
document type, and a search across models/ and server/ proving no
other module re-implements its own bypassing magic-byte check and that
both upload paths (attachments, avatars) go through the same guard.

Thanks to blaggacao and xet7 !

Closes #3274,
2026-09-10 20:02:50 +03:00
Lauri Ojansivu 715140a2bb Update changelog. 2026-09-10 20:01:17 +03:00
Lauri Ojansivu 61e857d96e CHANGELOG: add the "Remove all labels" rule action entry. 2026-09-10 20:00:44 +03:00