fix: do not allow thumb deletion route to arbitrarily delete other files in uploads folder

v1.18.x
Julian Lam 4 years ago
parent 5950683316
commit c09c238e3f

@ -64,8 +64,9 @@ Thumbs.delete = async function (id, relativePath) {
if (associated) { if (associated) {
await db.sortedSetRemove(set, relativePath); await db.sortedSetRemove(set, relativePath);
}
if (existsOnDisk) { if (existsOnDisk) {
await file.delete(absolutePath); await file.delete(absolutePath);
}
} }
}; };

@ -127,6 +127,7 @@ describe('Topic thumbs', () => {
describe(`.delete()`, () => { describe(`.delete()`, () => {
it('should remove a file from sorted set AND disk', async () => { it('should remove a file from sorted set AND disk', async () => {
await topics.thumbs.associate(1, thumbPaths[0]);
await topics.thumbs.delete(1, thumbPaths[0]); await topics.thumbs.delete(1, thumbPaths[0]);
assert.strictEqual(await db.isSortedSetMember('topic:1:thumbs', thumbPaths[0]), false); assert.strictEqual(await db.isSortedSetMember('topic:1:thumbs', thumbPaths[0]), false);
@ -140,6 +141,12 @@ describe('Topic thumbs', () => {
assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, thumbPaths[1]), false); assert.strictEqual(await db.isSortedSetMember(`draft:${uuid}:thumbs`, thumbPaths[1]), false);
assert.strictEqual(await file.exists(`${nconf.get('upload_path')}/${thumbPaths[1]}`), false); assert.strictEqual(await file.exists(`${nconf.get('upload_path')}/${thumbPaths[1]}`), false);
}); });
it('should not delete the file from disk if not associated with the tid', async () => {
createFiles();
await topics.thumbs.delete(uuid, thumbPaths[0]);
assert.strictEqual(await file.exists(`${nconf.get('upload_path')}/${thumbPaths[0]}`), true);
});
}); });
describe('HTTP calls to topic thumb routes', () => { describe('HTTP calls to topic thumb routes', () => {

Loading…
Cancel
Save