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 cloud endpoints #32331

Merged
merged 1 commit into from
May 3, 2024
Merged
Changes from all commits
Commits
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
25 changes: 4 additions & 21 deletions apps/meteor/app/api/server/v1/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { check } from 'meteor/check';

import { CloudWorkspaceRegistrationError } from '../../../../lib/errors/CloudWorkspaceRegistrationError';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { hasRoleAsync } from '../../../authorization/server/functions/hasRole';
import { getCheckoutUrl } from '../../../cloud/server/functions/getCheckoutUrl';
import { getConfirmationPoll } from '../../../cloud/server/functions/getConfirmationPoll';
Expand All @@ -20,17 +19,13 @@ import { API } from '../api';

API.v1.addRoute(
'cloud.manualRegister',
{ authRequired: true },
{ authRequired: true, permissionsRequired: ['register-on-cloud'] },
{
async post() {
check(this.bodyParams, {
cloudBlob: String,
});

if (!(await hasPermissionAsync(this.userId, 'register-on-cloud'))) {
return API.v1.unauthorized();
}

const registrationInfo = await retrieveRegistrationStatus();

if (registrationInfo.workspaceRegistered) {
Expand All @@ -48,18 +43,14 @@ API.v1.addRoute(

API.v1.addRoute(
'cloud.createRegistrationIntent',
{ authRequired: true },
{ authRequired: true, permissionsRequired: ['manage-cloud'] },
{
async post() {
check(this.bodyParams, {
resend: Boolean,
email: String,
});

if (!(await hasPermissionAsync(this.userId, 'manage-cloud'))) {
return API.v1.unauthorized();
}

const intentData = await startRegisterWorkspaceSetupWizard(this.bodyParams.resend, this.bodyParams.email);

if (intentData) {
Expand All @@ -73,32 +64,24 @@ API.v1.addRoute(

API.v1.addRoute(
'cloud.registerPreIntent',
{ authRequired: true },
{ authRequired: true, permissionsRequired: ['manage-cloud'] },
{
async post() {
if (!(await hasPermissionAsync(this.userId, 'manage-cloud'))) {
return API.v1.unauthorized();
}

return API.v1.success({ offline: !(await registerPreIntentWorkspaceWizard()) });
},
},
);

API.v1.addRoute(
'cloud.confirmationPoll',
{ authRequired: true },
{ authRequired: true, permissionsRequired: ['manage-cloud'] },
{
async get() {
const { deviceCode } = this.queryParams;
check(this.queryParams, {
deviceCode: String,
});

if (!(await hasPermissionAsync(this.userId, 'manage-cloud'))) {
return API.v1.unauthorized();
}

if (!deviceCode) {
return API.v1.failure('Invalid query');
}
Expand Down
Loading