diff --git a/.changeset/perky-tires-invite.md b/.changeset/perky-tires-invite.md new file mode 100644 index 0000000000000..d3824c95cfca4 --- /dev/null +++ b/.changeset/perky-tires-invite.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Ensures the visitor token is not present in the visitors.info response diff --git a/apps/meteor/app/livechat/server/api/lib/visitors.ts b/apps/meteor/app/livechat/server/api/lib/visitors.ts index 3caf551358a89..c302141aded02 100644 --- a/apps/meteor/app/livechat/server/api/lib/visitors.ts +++ b/apps/meteor/app/livechat/server/api/lib/visitors.ts @@ -6,7 +6,7 @@ import { callbacks } from '../../../../../server/lib/callbacks'; import { canAccessRoomAsync } from '../../../../authorization/server/functions/canAccessRoom'; export async function findVisitorInfo({ visitorId }: { visitorId: IVisitor['_id'] }) { - const visitor = await LivechatVisitors.findOneEnabledById(visitorId); + const visitor = await LivechatVisitors.findOneEnabledById(visitorId, { projection: { token: 0 } }); if (!visitor) { throw new Error('visitor-not-found'); } diff --git a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts index c4b300a8a366a..6a15e5e395be4 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts @@ -567,6 +567,18 @@ describe('LIVECHAT - visitors', () => { expect(res.body.visitor._id).to.be.equal(visitor._id); }); }); + it('should not return the visitor token', async () => { + await request + .get(api('livechat/visitors.info')) + .query({ visitorId: visitor._id }) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res: Response) => { + expect(res.body).to.have.property('success', true); + expect(res.body.visitor).to.not.have.property('token'); + }); + }); }); describe('livechat/visitors.pagesVisited', () => {