mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
fix: imported fixes 09-18-2025 (#37000)
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com> Co-authored-by: Julio Araujo <julio.araujo@rocket.chat> Co-authored-by: Abhinav Kumar <abhinav@avitechlab.com>
This commit is contained in:
parent
d7da2c0da3
commit
c8e778a64a
5
.changeset/grumpy-berries-arrive.md
Normal file
5
.changeset/grumpy-berries-arrive.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@rocket.chat/meteor': patch
|
||||
---
|
||||
|
||||
Security Hotfix (https://docs.rocket.chat/docs/security-fixes-and-updates)
|
||||
@ -811,12 +811,15 @@ export class APIClass<
|
||||
if (options.authRequired || options.authOrAnonRequired) {
|
||||
const user = await api.authenticatedRoute.call(this, this.request);
|
||||
this.user = user!;
|
||||
this.userId = String(this.request.headers.get('x-user-id'));
|
||||
this.userId = this.user?._id;
|
||||
const authToken = this.request.headers.get('x-auth-token');
|
||||
this.token = (authToken && Accounts._hashLoginToken(String(authToken)))!;
|
||||
}
|
||||
|
||||
if (!this.user && options.authRequired && !options.authOrAnonRequired && !settings.get('Accounts_AllowAnonymousRead')) {
|
||||
const shouldPreventAnonymousRead = !this.user && options.authOrAnonRequired && !settings.get('Accounts_AllowAnonymousRead');
|
||||
const shouldPreventUserRead = !this.user && options.authRequired;
|
||||
|
||||
if (shouldPreventAnonymousRead || shouldPreventUserRead) {
|
||||
const result = api.unauthorized('You must be logged in to do this.');
|
||||
// compatibility with the old API
|
||||
// TODO: MAJOR
|
||||
|
||||
@ -3503,10 +3503,10 @@ describe('[Channels]', () => {
|
||||
roomId: testChannel._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(400)
|
||||
.expect(401)
|
||||
.expect((res) => {
|
||||
expect(res.body).to.have.a.property('success', false);
|
||||
expect(res.body).to.have.a.property('error', 'Enable "Allow Anonymous Read" [error-not-allowed]');
|
||||
expect(res.body).to.have.a.property('error', 'You must be logged in to do this.');
|
||||
})
|
||||
.end(done);
|
||||
});
|
||||
|
||||
@ -681,6 +681,53 @@ describe('[Users]', () => {
|
||||
]),
|
||||
);
|
||||
|
||||
it('should fail when request is without authentication credentials', async () => {
|
||||
await request
|
||||
.get(api('users.info'))
|
||||
.query({
|
||||
userId: targetUser._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(401)
|
||||
.expect((res) => {
|
||||
expect(res.body).to.have.property('success', false);
|
||||
expect(res.body).to.have.property('error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('authentication', () => {
|
||||
before(() => updateSetting('Accounts_AllowAnonymousRead', true));
|
||||
after(() => updateSetting('Accounts_AllowAnonymousRead', false));
|
||||
it('should fail when request is without authentication credentials and Anonymous Read is enabled', async () => {
|
||||
await request
|
||||
.get(api('users.info'))
|
||||
.query({
|
||||
userId: targetUser._id,
|
||||
})
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(401)
|
||||
.expect((res) => {
|
||||
expect(res.body).to.have.property('success', false);
|
||||
expect(res.body).to.have.property('error');
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when request is without token and Anonymous Read is enabled', async () => {
|
||||
await request
|
||||
.get(api('users.info'))
|
||||
.query({
|
||||
userId: targetUser._id,
|
||||
})
|
||||
.set({ 'X-User-Id': credentials['X-User-Id'] })
|
||||
.expect('Content-Type', 'application/json')
|
||||
.expect(401)
|
||||
.expect((res) => {
|
||||
expect(res.body).to.have.property('success', false);
|
||||
expect(res.body).to.have.property('error');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when the user does not exist', (done) => {
|
||||
void request
|
||||
.get(api('users.info'))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user