Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: Improve permissions check on settings endpoints #32350

Merged
merged 20 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5cea67f
chore: bump 7.0.0
ggazzo Apr 8, 2024
9b3d017
fix!: api login should not suggest which credential is wrong (#32159)
ggazzo Apr 9, 2024
8d5b603
chore!: remove hipchat importer (#32154)
pierre-lehnen-rc Apr 11, 2024
c2ab323
chore!: Removed Mongo 4.4. support and added 7.0 (#32162)
ggazzo Apr 12, 2024
68fee68
rebase with mongo
ggazzo Apr 24, 2024
4a1e86b
chore: Improve permissions check on settings endpoints
matheusbsilva137 Apr 30, 2024
94b238d
chore: bump 7.0.0
ggazzo Apr 8, 2024
fcc9265
fix!: api login should not suggest which credential is wrong (#32159)
ggazzo Apr 9, 2024
cd0313b
chore!: remove hipchat importer (#32154)
pierre-lehnen-rc Apr 11, 2024
405da2a
chore!: Removed Mongo 4.4. support and added 7.0 (#32162)
ggazzo Apr 12, 2024
ce31b9d
rebase with mongo
ggazzo Apr 24, 2024
1c13d06
chore!: Improve permissions check on channels endpoints (#32330)
matheusbsilva137 May 3, 2024
8f45647
chore: Improve permissions check on cloud endpoints (#32331)
matheusbsilva137 May 3, 2024
ecaa003
chore: Improve permissions check on instances endpoints (#32334)
matheusbsilva137 May 3, 2024
5ee72d7
chore: Improve permissions check on LDAP endpoints (#32335)
matheusbsilva137 May 3, 2024
cb2fa7f
chore!: Improve permissions check on mailer endpoints (#32336)
matheusbsilva137 May 3, 2024
c42eef9
chore: Improve permissions check on users endpoints (#32353)
matheusbsilva137 May 7, 2024
88baaeb
Merge branch 'release-7.0.0' into chore/permissions-check-settings
matheusbsilva137 May 7, 2024
a38a680
Merge branch 'release-7.0.0' into chore/permissions-check-settings
matheusbsilva137 May 10, 2024
45c063f
test: add missing returns/awaits
matheusbsilva137 May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions apps/meteor/app/api/server/v1/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,15 @@ API.v1.addRoute(

API.v1.addRoute(
'settings/:_id',
{ authRequired: true },
{
authRequired: true,
permissionsRequired: {
GET: { permissions: ['view-privileged-setting'], operation: 'hasAll' },
POST: { permissions: ['edit-privileged-setting'], operation: 'hasAll' },
},
},
{
async get() {
if (!(await hasPermissionAsync(this.userId, 'view-privileged-setting'))) {
return API.v1.unauthorized();
}
const setting = await Settings.findOneNotHiddenById(this.urlParams._id);
if (!setting) {
return API.v1.failure();
Expand All @@ -164,10 +167,6 @@ API.v1.addRoute(
post: {
twoFactorRequired: true,
async action(): Promise<ResultFor<'POST', '/v1/settings/:_id'>> {
if (!(await hasPermissionAsync(this.userId, 'edit-privileged-setting'))) {
return API.v1.unauthorized();
}

if (typeof this.urlParams._id !== 'string') {
throw new Meteor.Error('error-id-param-not-provided', 'The parameter "id" is required');
}
Expand Down
60 changes: 56 additions & 4 deletions apps/meteor/tests/end-to-end/api/08-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { before, describe, it, after } from 'mocha';

import { getCredentials, api, request, credentials } from '../../data/api-data.js';
import { updateSetting } from '../../data/permissions.helper';
import { updatePermission, updateSetting } from '../../data/permissions.helper';

describe('[Settings]', function () {
this.retries(0);
Expand Down Expand Up @@ -57,8 +57,18 @@ describe('[Settings]', function () {
});

describe('[/settings/:_id]', () => {
it('should return one setting', (done) => {
request
before(async () => {
await updatePermission('view-privileged-setting', ['admin']);
await updatePermission('edit-privileged-setting', ['admin']);
});

after(async () => {
await updatePermission('view-privileged-setting', ['admin']);
await updatePermission('edit-privileged-setting', ['admin']);
});

it('should succesfully return one setting (GET)', async () => {
return request
.get(api('settings/Site_Url'))
.set(credentials)
.expect('Content-Type', 'application/json')
Expand All @@ -67,8 +77,50 @@ describe('[Settings]', function () {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('_id', 'Site_Url');
expect(res.body).to.have.property('value');
});
});

it('should fail returning a setting if user does NOT have the view-privileged-setting permission (GET)', async () => {
matheusbsilva137 marked this conversation as resolved.
Show resolved Hide resolved
await updatePermission('view-privileged-setting', []);
return request
.get(api('settings/Site_Url'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(403)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'User does not have the permissions required for this action [error-unauthorized]');
});
});

it('should succesfully set the value of a setting (POST)', async () => {
return request
.post(api('settings/LDAP_Enable'))
.set(credentials)
.send({
value: false,
})
.end(done);
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});
});

it('should fail updating the value of a setting if user does NOT have the edit-privileged-setting permission (POST)', async () => {
await updatePermission('edit-privileged-setting', []);
return request
.post(api('settings/LDAP_Enable'))
.set(credentials)
.send({
value: false,
})
.expect('Content-Type', 'application/json')
.expect(403)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'User does not have the permissions required for this action [error-unauthorized]');
});
});
});

Expand Down
Loading