mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Attachments blocked client-supplied `versions.*.path`; avatars did not. The avatar allow rule was the single line `update: isOwner` - being the owner let you write ANY field of your own avatar document, `versions.original.path` included. That field is server-managed metadata: it says where on disk the bytes are. Board export then read it. For every member whose avatar is a local WeKan file, the exporter opens `versions.original.path` and embeds the bytes as base64 in `profile.avatarFile`, so an authenticated user could point their own avatar at /etc/passwd - or at anything else under WRITABLE_PATH - export a board they are a member of, and decode the file out of the JSON. Arbitrary file read as the WeKan OS user (CWE-22, CWE-73), from any account that can own an avatar. Both halves are closed. The WRITE: the guards that attachments had are now in one module, models/lib/fileVersionFields.js, and BOTH permission files import it - avatars had gone without them precisely because each collection wrote its own copy. Avatars refuse an insert carrying versions.*.path or .storage, refuse any update touching the versions subtree, and restrict updates to the same field whitelist attachments use. Being the owner is still required; it is no longer sufficient. The READ: nothing is read from a stored path unless the path RESOLVES to somewhere inside WeKan's own storage (models/lib/storagePathContainment.js). That is the half that also holds when a path is poisoned some other way - a document written before this fix, a restored backup, a bad migration. The check sits at getBase64Data, the one place the export turns a stored path into bytes for attachments and avatars alike, and at both avatar call sites. The download path in fileStoreStrategy.js has always checked containment this way; its private copy of the function is gone and it uses the shared one, so the download and the export ask the same question. tests/avatarVersionPathTraversal.test.cjs pins the payload being refused on insert and on update, that renaming an avatar still works, that ..-escapes are resolved rather than string-matched, that a sibling directory with the root as a prefix is not inside it, and that no unguarded read of a stored version path remains in the exporter. Thanks to Alpastx and xet7 ! Fixes GHSA-4mxf-m8pq-xc9p.
83 lines
3.0 KiB
JavaScript
83 lines
3.0 KiB
JavaScript
// Pure, dependency-free guards for the `versions` metadata of a stored file
|
|
// (ostrio:files: `versions.<name>.path` / `.storage`), so both the attachment
|
|
// and the avatar permission rules can use the SAME rule and cannot drift apart.
|
|
//
|
|
// GHSA-4mxf-m8pq-xc9p: attachments blocked client-supplied `versions.*.path`,
|
|
// avatars did not - their allow rule was `update: isOwner` with no field
|
|
// restriction at all. An avatar owner could therefore point
|
|
// `versions.original.path` at any file the WeKan process can read (/etc/passwd,
|
|
// anything under WRITABLE_PATH) and then export a board they are a member of:
|
|
// the exporter reads that path from disk and embeds the bytes as base64 in
|
|
// `profile.avatarFile`. That is an arbitrary file read for any authenticated
|
|
// user, so the rule now lives in ONE place and is applied to both collections.
|
|
//
|
|
// `path` and `storage` are server-managed: they say WHERE on disk the bytes
|
|
// are. A client never has a reason to set or change them, on any collection.
|
|
|
|
const SERVER_MANAGED_VERSION_FIELDS = ['path', 'storage'];
|
|
|
|
/**
|
|
* True when a document a client is trying to INSERT carries server-managed
|
|
* version metadata (`versions.<any>.path` or `.storage`).
|
|
* @param {object} fileObj the document as the client sent it
|
|
* @return {boolean}
|
|
*/
|
|
function hasUnsafeClientVersionFields(fileObj) {
|
|
const versions = fileObj && fileObj.versions;
|
|
if (!versions || typeof versions !== 'object') {
|
|
return false;
|
|
}
|
|
|
|
return Object.values(versions).some((version) => {
|
|
if (!version || typeof version !== 'object') {
|
|
return false;
|
|
}
|
|
return SERVER_MANAGED_VERSION_FIELDS.some((field) =>
|
|
Object.prototype.hasOwnProperty.call(version, field),
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* True when an UPDATE touches the `versions` subtree at all. Deliberately
|
|
* broader than hasUnsafeClientVersionFields: an update arrives as a list of
|
|
* modified field names, and `versions.original` (the whole sub-object, path
|
|
* included) is as dangerous as `versions.original.path` spelled out.
|
|
* @param {string[]} fields the modified field names Meteor passes to allow()
|
|
* @return {boolean}
|
|
*/
|
|
function touchesVersionFields(fields) {
|
|
if (!Array.isArray(fields)) {
|
|
return false;
|
|
}
|
|
return fields.some(
|
|
(field) =>
|
|
typeof field === 'string' &&
|
|
(field === 'versions' || field.startsWith('versions.')),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* True when every modified field name is in `allowedFields` (comparing the
|
|
* part before the first dot, so `meta.boardId` is allowed by `meta`).
|
|
* @param {string[]} fields the modified field names
|
|
* @param {string[]} allowedFields the whitelist
|
|
* @return {boolean}
|
|
*/
|
|
function onlyTouchesAllowedFields(fields, allowedFields) {
|
|
if (!Array.isArray(fields)) {
|
|
return false;
|
|
}
|
|
return fields.every((field) => {
|
|
if (typeof field !== 'string') return false;
|
|
return allowedFields.includes(field.split('.')[0]);
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
SERVER_MANAGED_VERSION_FIELDS,
|
|
hasUnsafeClientVersionFields,
|
|
touchesVersionFields,
|
|
onlyTouchesAllowedFields,
|
|
};
|