mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
AssignedBleed follow-up, GHSA-3cgr-47wm-9cc9. An assigned-only member
(isNormalAssignedOnly, isCommentAssignedOnly, isReadAssignedOnly) sees only
the cards assigned to them. 1a218ead02 applied that to the attachment API,
but six other paths asked only for board membership, which such a member
has:
- the /cdn/storage/attachments and /cfs/files/attachments downloads
(universalFileServer isAuthorizedForBoard) served any card's file;
- Attachments.protected, ostrio:files' own download check, likewise;
- the legacy /cfs/files/attachments route likewise;
- searchAttachmentDocumentText matched the extracted text of every card's
PDF/DOCX/XLSX/PPTX on the board and returned snippets with their
attachment and card ids - no id needed, and it supplied the ids for the
downloads;
- legacyBoardAttachments without a cardId published every legacy
attachment record of the board;
- linkedListCards published every card of the source list.
The downloads now also ask mayReadBoardAttachment(), which names the
refusing path in Admin Panel -> Problems (authz.assigned, medium: never
disables). The document search and the legacy publication are narrowed to
the member's cards (assignedOnlyCardIds); asking the publication for a card
not assigned to them is refused and recorded, as card details always pass
the open card. Linked-list cards take the source board's
assignedOnlyCardScope; searching and viewing a linked list are ordinary
use, so those are not recorded.
The board's own files - background (sidebar or API upload) and map image -
carry no card and are part of the board every member sees; they stay
readable, where the attachment API refused them to an assigned-only
member. Any other card-less file is still refused.
tests/assignedOnlyReads.test.cjs pins each path, the board-file rule and
the refusal source, and fails when any file in server/ or models/ that
serves attachment or document data lacks the rule without a stated
exemption. The Playwright spec checks both downloads refuse the hidden
card's file but not the member's own, that the search finds only the
member's card, and that the owner is unaffected. Four source guards that
pinned the old lines now pin the new ones.
Thanks to crypto-nidh and xet7 !
100 lines
6.3 KiB
JavaScript
100 lines
6.3 KiB
JavaScript
'use strict';
|
|
|
|
// wekan/wekan#3275: /cdn/storage/attachments/<id>/thumbnail.
|
|
// Run: node tests/attachmentThumbnail.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const sharp = require('sharp');
|
|
const { isThumbnailPath, canThumbnail, thumbnailUrl, THUMBNAIL_EDGE } = require('../models/lib/attachmentThumbnail.js');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = file => fs.readFileSync(path.join(ROOT, file), 'utf8');
|
|
|
|
async function loadImageLib() {
|
|
const thumbnails = await import('../server/lib/imageThumbnail.js');
|
|
const { gifCacheKey } = await import('../server/lib/imageGif.js');
|
|
return { ...thumbnails, gifCacheKey };
|
|
}
|
|
|
|
async function main() {
|
|
// Only exactly "<id>/thumbnail" asks for one.
|
|
assert.ok(isThumbnailPath('/abc123/thumbnail'));
|
|
assert.ok(isThumbnailPath('/abc123/thumbnail?x=1'));
|
|
for (const p of ['/abc123', '/abc123/original/photo.png', '/abc123/thumbnail/extra', '/thumbnail', '', null, '/abc/THUMBNAIL']) {
|
|
assert.ok(!isThumbnailPath(p), String(p));
|
|
}
|
|
// Raster images only - never SVG, never a non-image.
|
|
assert.ok(canThumbnail({ type: 'image/png' }));
|
|
assert.ok(canThumbnail({ type: 'image/jpeg; charset=binary' }));
|
|
assert.ok(canThumbnail({ name: 'photo.JPG' }), 'a migrated file with only a name');
|
|
for (const doc of [{ type: 'image/svg+xml' }, { name: 'drawing.svg' }, { type: 'application/pdf' }, { type: 'text/html', name: 'x.png' },
|
|
{ name: 'README' }, null, {}]) {
|
|
assert.ok(!canThumbnail(doc), JSON.stringify(doc));
|
|
}
|
|
assert.equal(thumbnailUrl('/cdn/storage/attachments/abc'), '/cdn/storage/attachments/abc/thumbnail');
|
|
assert.equal(thumbnailUrl('/sub/cdn/storage/attachments/abc/'), '/sub/cdn/storage/attachments/abc/thumbnail');
|
|
assert.equal(thumbnailUrl(''), '');
|
|
console.log(' ok - thumbnail paths and eligible files');
|
|
|
|
// Conversion: a WebP no larger than THUMBNAIL_EDGE, never enlarged.
|
|
const lib = await loadImageLib();
|
|
const big = await sharp({ create: { width: 3000, height: 1000, channels: 3, background: '#224488' } }).jpeg().toBuffer();
|
|
const meta = await sharp(await lib.convertImageBufferToThumbnail(big)).metadata();
|
|
assert.deepEqual([meta.format, meta.width, meta.height], ['webp', THUMBNAIL_EDGE, 171]);
|
|
const small = await sharp({ create: { width: 40, height: 30, channels: 4, background: '#fff0' } }).png().toBuffer();
|
|
const smallMeta = await sharp(await lib.convertImageBufferToThumbnail(small)).metadata();
|
|
assert.deepEqual([smallMeta.width, smallMeta.height], [40, 30], 'never enlarged');
|
|
// Negative: not an image, empty, or not a buffer.
|
|
for (const bad of [Buffer.from('not an image'), Buffer.alloc(0), 'png']) {
|
|
await assert.rejects(() => lib.convertImageBufferToThumbnail(bad));
|
|
}
|
|
console.log(' ok - conversion makes a bounded WebP and refuses non-images');
|
|
|
|
// Cache: bounded by count, least recently used out, keyed by file version.
|
|
for (let i = 0; i < 510; i += 1) lib.rememberThumbnail(`k${i}`, Buffer.from([i % 256]));
|
|
assert.equal(lib.cachedThumbnail('k0'), null, 'the oldest entries were evicted');
|
|
assert.equal(lib.cachedThumbnail('k9'), null);
|
|
assert.ok(lib.cachedThumbnail('k509'));
|
|
// Reading k10 (now the oldest) makes it recent, so the next insert evicts k11.
|
|
assert.ok(lib.cachedThumbnail('k10'));
|
|
lib.rememberThumbnail('fresh', Buffer.from([1]));
|
|
assert.ok(lib.cachedThumbnail('k10'), 'reading an entry keeps it');
|
|
assert.equal(lib.cachedThumbnail('k11'), null, 'the least recently used goes first');
|
|
// Bounded by bytes too: one oversized buffer is never cached.
|
|
lib.rememberThumbnail('huge', Buffer.alloc(65 * 1024 * 1024));
|
|
assert.equal(lib.cachedThumbnail('huge'), null);
|
|
const v1 = lib.gifCacheKey({ _id: 'a', versions: { original: { size: 1, sha256: 'x' } } });
|
|
const v2 = lib.gifCacheKey({ _id: 'a', versions: { original: { size: 2, sha256: 'y' } } });
|
|
assert.notEqual(v1, v2, 'a replaced file does not reuse the old thumbnail');
|
|
console.log(' ok - the cache is bounded and keyed by file version');
|
|
|
|
// The route: thumbnails come after every access check the original has.
|
|
const route = read('server/routes/universalFileServer.js');
|
|
const handler = route.slice(route.indexOf("WebApp.handlers.use('/cdn/storage/attachments'"), route.indexOf("WebApp.handlers.use('/cdn/storage/avatars'"));
|
|
const at = text => { const i = handler.indexOf(text); assert.notEqual(i, -1, text); return i; };
|
|
const thumbnail = at('const wantsThumbnail = isThumbnailPath(');
|
|
for (const check of ['isAuthorizedForBoard(req, board, attachment,', 'isActiveSiteLogo(', 'attachmentDownloadLimits.blocked',
|
|
'attachmentDownloadLimits.maxBytes', 'isStorageReadEnabled(storageName)']) {
|
|
assert.ok(at(check) < thumbnail, `${check} runs before a thumbnail is served`);
|
|
}
|
|
assert.match(handler, /if \(wantsThumbnail && !canThumbnail\(attachment\)\) \{\s*res\.writeHead\(404\);/);
|
|
assert.match(handler, /convertImageBufferToThumbnail\(await boundedStreamBuffer\(readStream\)\)/);
|
|
assert.match(handler, /res\.writeHead\(302, \{ Location: Meteor\.absoluteUrl\(`cdn\/storage\/attachments\/\$\{fileId\}`\)/);
|
|
// CacheBleed (GHSA-w3qg-pf27-g68r): cached as the original is - private and
|
|
// revalidated - through the shared helper (tests/fileCacheHeaders.test.cjs).
|
|
assert.match(route.slice(route.indexOf('function sendThumbnail')), /\.\.\.privateFileCacheHeaders\(\)/);
|
|
assert.doesNotMatch(route.slice(route.indexOf('function sendThumbnail')), /'Cache-Control': 'public/,
|
|
'a thumbnail of a private board is never publicly cacheable');
|
|
// The client uses it where images are shown small, and only there.
|
|
assert.match(read('client/components/cards/attachments.jade'), /img\.attachment-thumbnail\(src="\{\{attachmentPreviewUrl this\}\}"/);
|
|
// The cover is an img now (v12.12 email: a CSS background had no URL and no
|
|
// fallback); it still uses the thumbnail, and only when there is one.
|
|
assert.match(read('client/components/cards/minicard.jade'), /img\.minicard-cover-image\(alt="" src="\{\{attachmentPreviewUrl cover\}\}\?dummyReloadAfterSessionEstablished/);
|
|
assert.match(read('client/components/cards/attachments.js'), /return canThumbnail\(attachment\) \? thumbnailUrl\(url\) : url;/);
|
|
console.log(' ok - the route checks access first, and the gallery and cover use it');
|
|
}
|
|
|
|
main().catch(error => { console.error(error); process.exitCode = 1; });
|