mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
The /cdn/storage/avatars and /cfs/files/avatars routes in the universal file server answer before avatarServer.js, and served an avatar inline under its stored type unless that type exactly matched a short dangerous list - 'text/html; charset=utf-8' did not - with no CSP. An avatar's owner could set that type from the client, so an image-looking upload could be re-labelled and served as HTML on WeKan's origin. Only known raster image types are now served inline, under their canonical name with a restrictive CSP; anything else is a sandboxed download. The client rules for avatars and attachments allowed updating type, extension, size and meta - meta names an attachment's board and card, so a file could be moved onto another board's card. No client updates these documents; only the name may change now. Thanks to xet7 !
87 lines
3.3 KiB
JavaScript
87 lines
3.3 KiB
JavaScript
import Avatars from '/models/avatars';
|
|
import AttachmentStorageSettings from '/models/attachmentStorageSettings';
|
|
import {
|
|
hasUnsafeClientVersionFields,
|
|
touchesVersionFields,
|
|
onlyTouchesAllowedFields,
|
|
} from '/models/lib/fileVersionFields';
|
|
import { tripCanary } from '/server/lib/canary';
|
|
|
|
// What an avatar's owner may change from the client. `versions` is NOT here,
|
|
// and is refused separately below so the reason can be logged: it holds the
|
|
// server-managed on-disk path.
|
|
// AvatarMimeBleed / attachment-move sibling (2026-10-02): `type` decided how a
|
|
// file is served and `meta` names its board and card, so a client changing
|
|
// either could serve its upload as HTML or move it onto another board's card.
|
|
// No client updates these documents (uploads and renames go through the
|
|
// server); only the name may change here.
|
|
const ALLOWED_UPDATE_FIELDS = ['name'];
|
|
|
|
function isOwner(userId, doc) {
|
|
return userId && userId === doc.userId;
|
|
}
|
|
|
|
// Admin-level hard stop for avatar uploads (Admin Panel > Attachments >
|
|
// Transfer limits, default off). Mirrors the attachmentsUploadBlocked check in
|
|
// server/permissions/attachments.js. When blocked, only inserts (new uploads)
|
|
// are rejected; updating/removing an existing avatar still works.
|
|
async function avatarUploadsBlocked() {
|
|
try {
|
|
const settings = await AttachmentStorageSettings.findOneAsync({});
|
|
return settings?.limitSettings?.avatarsUploadBlocked === true;
|
|
} catch (error) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.warn('Could not read avatar upload block setting:', error);
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Avatars.allow({
|
|
async insert(userId, doc) {
|
|
// GHSA-4mxf-m8pq-xc9p: the same guard attachments have. `versions.*.path`
|
|
// says where on disk the bytes are; a client that can choose it can make
|
|
// the board exporter read any file the WeKan process can read.
|
|
if (hasUnsafeClientVersionFields(doc)) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.warn('Blocked avatar insert with client-supplied versions.path/storage');
|
|
}
|
|
// A canary: no WeKan client sends this field, so an insert carrying it is
|
|
// somebody trying PathBleed (docs/Security/Remediation/WeKan.md §12).
|
|
return tripCanary('avatar.version-path', { userId });
|
|
}
|
|
|
|
if (await avatarUploadsBlocked()) {
|
|
return false;
|
|
}
|
|
return isOwner(userId, doc);
|
|
},
|
|
// GHSA-4mxf-m8pq-xc9p: this used to be `update: isOwner` - the owner could
|
|
// set ANY field, `versions.original.path` included. Being the owner is still
|
|
// necessary, but no longer sufficient: the storage metadata is server-managed
|
|
// and a client never writes it.
|
|
update(userId, doc, fields) {
|
|
if (!isOwner(userId, doc)) {
|
|
return tripCanary('avatar.not-owner', { userId });
|
|
}
|
|
|
|
if (touchesVersionFields(fields)) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.warn('Blocked attempt to update avatar versions metadata:', fields);
|
|
}
|
|
return tripCanary('avatar.version-path', { userId });
|
|
}
|
|
|
|
if (!onlyTouchesAllowedFields(fields, ALLOWED_UPDATE_FIELDS)) {
|
|
if (process.env.DEBUG === 'true') {
|
|
console.warn('Blocked attempt to update restricted avatar fields:', fields);
|
|
}
|
|
return tripCanary('avatar.restricted-field', { userId });
|
|
}
|
|
|
|
return true;
|
|
},
|
|
remove: isOwner,
|
|
fetch: ['userId'],
|
|
});
|