Skip to content

Commit

Permalink
Disallow service token creation based on permission
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Jan 31, 2023
1 parent cb080b3 commit 6711979
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/src/controllers/v2/serviceTokenDataController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
SALT_ROUNDS
} from '../../config';
import { userHasWorkspaceAccess } from '../../ee/helpers/checkMembershipPermissions';
import { ABILITY_READ } from '../../variables/organization';

/**
* Return service token data associated with service token on request
Expand Down Expand Up @@ -37,6 +39,11 @@ export const createServiceTokenData = async (req: Request, res: Response) => {
expiresIn
} = req.body;

const hasAccess = await userHasWorkspaceAccess(req.user, workspaceId, environment, ABILITY_READ)
if (!hasAccess) {
throw UnauthorizedRequestError({ message: "You do not have the necessary permission(s) perform this action" })
}

const secret = crypto.randomBytes(16).toString('hex');
const secretHash = await bcrypt.hash(secret, SALT_ROUNDS);

Expand Down Expand Up @@ -100,4 +107,8 @@ export const deleteServiceTokenData = async (req: Request, res: Response) => {
return res.status(200).send({
serviceTokenData
});
}
}

function UnauthorizedRequestError(arg0: { message: string; }) {
throw new Error('Function not implemented.');
}

0 comments on commit 6711979

Please sign in to comment.