snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
import { expect } from 'chai';
|
||||
import { describe, it, beforeEach } from 'mocha';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const findOneByIdAndUserIdAndRoomId = sinon.stub();
|
||||
const updateFileMetadata = sinon.stub().resolves();
|
||||
const getPath = sinon.stub().returns('/path/to/file.txt');
|
||||
const isImagePreviewSupported = sinon.stub().returns(false);
|
||||
const getFileExtension = sinon.stub().returns('txt');
|
||||
|
||||
const { parseFileIntoMessageAttachments } = proxyquire.noCallThru().load('./sendFileMessage', {
|
||||
'@rocket.chat/models': {
|
||||
Uploads: { findOneByIdAndUserIdAndRoomId, updateFileMetadata },
|
||||
Rooms: { findOneById: sinon.stub() },
|
||||
Users: { findOneById: sinon.stub() },
|
||||
},
|
||||
'meteor/check': {
|
||||
check: sinon.stub(),
|
||||
Match: {
|
||||
Maybe: sinon.stub(),
|
||||
Optional: sinon.stub(),
|
||||
ObjectIncluding: sinon.stub(),
|
||||
},
|
||||
},
|
||||
'meteor/meteor': {
|
||||
Meteor: {
|
||||
Error: class Error extends global.Error {},
|
||||
methods: sinon.stub(),
|
||||
},
|
||||
},
|
||||
'../../lib/media/file-upload/lib/FileUpload': {
|
||||
FileUpload: { getPath },
|
||||
},
|
||||
'../../lib/media/file-upload/isImagePreviewSupported': { isImagePreviewSupported },
|
||||
'../../../lib/utils/getFileExtension': { getFileExtension },
|
||||
'../../lib/callbacks': { callbacks: { runAsync: sinon.stub() } },
|
||||
'../../lib/logger/system': { SystemLogger: { error: sinon.stub() } },
|
||||
'../../lib/authorization/canAccessRoom': { canAccessRoomAsync: sinon.stub().resolves(true) },
|
||||
'./sendMessage': { executeSendMessage: sinon.stub().resolves({}) },
|
||||
});
|
||||
|
||||
describe('sendFileMessage - Mass Assignment & Type Pollution Prevention', () => {
|
||||
const mockUser = { _id: 'user123' };
|
||||
const roomId = 'room123';
|
||||
|
||||
beforeEach(() => {
|
||||
findOneByIdAndUserIdAndRoomId.reset();
|
||||
updateFileMetadata.reset();
|
||||
|
||||
findOneByIdAndUserIdAndRoomId.resolves({ _id: 'file123' });
|
||||
});
|
||||
|
||||
it('should filter out invalid types, nulls, and malicious fields before updating the database', async () => {
|
||||
const maliciousFilePayload = {
|
||||
_id: 'file123',
|
||||
name: null, // invalid type, must be ignored
|
||||
type: 'text/plain',
|
||||
size: 1024,
|
||||
description: 12345, // invalid type, must be ignored
|
||||
typeGroup: 'image', // only valid field
|
||||
content: null, // invalid type, must be ignored
|
||||
maliciousRoleAssignment: 'admin', // mass assignment, must be ignored
|
||||
$set: { bypassSecurity: true }, // mongo injection, must be ignored
|
||||
};
|
||||
|
||||
await parseFileIntoMessageAttachments(maliciousFilePayload as any, roomId, mockUser as any);
|
||||
|
||||
expect(updateFileMetadata.calledOnce).to.equal(true);
|
||||
|
||||
const [fileId, userId, safeMetadata] = updateFileMetadata.getCall(0).args;
|
||||
|
||||
expect(fileId).to.equal('file123');
|
||||
expect(userId).to.equal('user123');
|
||||
|
||||
expect(safeMetadata).to.deep.equal({
|
||||
typeGroup: 'image',
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass valid fields correctly to the database', async () => {
|
||||
const validFilePayload = {
|
||||
_id: 'file123',
|
||||
name: 'picture.jpg',
|
||||
type: 'image/jpeg',
|
||||
size: 2048,
|
||||
description: 'Description',
|
||||
typeGroup: 'image',
|
||||
content: {
|
||||
algorithm: 'rc.v1.aes-sha2',
|
||||
ciphertext: 'test',
|
||||
},
|
||||
};
|
||||
|
||||
await parseFileIntoMessageAttachments(validFilePayload as any, roomId, mockUser as any);
|
||||
|
||||
expect(updateFileMetadata.calledOnce).to.equal(true);
|
||||
|
||||
const [, , safeMetadata] = updateFileMetadata.getCall(0).args;
|
||||
|
||||
expect(safeMetadata).to.deep.equal({
|
||||
name: 'picture.jpg',
|
||||
description: 'Description',
|
||||
typeGroup: 'image',
|
||||
content: {
|
||||
algorithm: 'rc.v1.aes-sha2',
|
||||
ciphertext: 'test',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user