Skip to content

Commit

Permalink
fix(security): validate bot access (#11978)
Browse files Browse the repository at this point in the history
* fix(security): validate bot access

* fix e2e
  • Loading branch information
EFF committed Jul 14, 2022
1 parent 04f96eb commit 4277f5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/bp/src/core/security/router-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ const checkPermissions = (workspaceService: WorkspaceService) => (
return new ForbiddenError(`User "${email}" doesn't have access to workspace "${req.workspace}"`)
}

const isBotIdValid = req.params.botId && req.params.botId !== ALL_BOTS
if (isBotIdValid && !(await workspaceService.isBotInWorkspace(req.workspace, req.params.botId))) {
return new NotFoundError(`Bot "${req.params.botId}" doesn't exist in workspace "${req.workspace}"`)
}

const role = await workspaceService.getRoleForUser(email, strategy, req.workspace)

if (!role || !checkRule(role.rules, operation, resource)) {
Expand Down
9 changes: 9 additions & 0 deletions packages/bp/src/core/users/workspace-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@ export class WorkspaceService {
return !!pipeline && pipeline.length > 1
}

async isBotInWorkspace(workspaceId: string, botId: string): Promise<boolean> {
try {
const workspace = await this.findWorkspace(workspaceId)
return workspace.bots.includes(botId)
} catch (err) {
return false
}
}

// @deprecated
async listUsers(workspaceId?: string): Promise<WorkspaceUser[]> {
if (workspaceId) {
Expand Down

0 comments on commit 4277f5c

Please sign in to comment.