-
-
Notifications
You must be signed in to change notification settings - Fork 18
Implement dashboard permissions validation and add end-to-end tests for dashboard access #1712
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ import { Inject, Injectable, NotFoundException, Scope } from '@nestjs/common'; | |
| import AbstractUseCase from '../../../../common/abstract-use.case.js'; | ||
| import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js'; | ||
| import { BaseType } from '../../../../common/data-injection.tokens.js'; | ||
| import { CedarAction } from '../../../cedar-authorization/cedar-action-map.js'; | ||
| import { CedarAuthorizationService } from '../../../cedar-authorization/cedar-authorization.service.js'; | ||
| import { Messages } from '../../../../exceptions/text/messages.js'; | ||
| import { FindAllDashboardsDs } from '../data-structures/find-all-dashboards.ds.js'; | ||
| import { FoundDashboardDto } from '../dto/found-dashboard.dto.js'; | ||
|
|
@@ -16,12 +18,13 @@ export class FindAllDashboardsUseCase | |
| constructor( | ||
| @Inject(BaseType.GLOBAL_DB_CONTEXT) | ||
| protected _dbContext: IGlobalDatabaseContext, | ||
| private readonly cedarAuthService: CedarAuthorizationService, | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| public async implementation(inputData: FindAllDashboardsDs): Promise<FoundDashboardDto[]> { | ||
| const { connectionId, masterPassword } = inputData; | ||
| const { connectionId, masterPassword, userId } = inputData; | ||
|
|
||
| const foundConnection = await this._dbContext.connectionRepository.findAndDecryptConnection( | ||
| connectionId, | ||
|
|
@@ -35,6 +38,17 @@ export class FindAllDashboardsUseCase | |
| const dashboards = | ||
| await this._dbContext.dashboardRepository.findAllDashboardsWithWidgetsByConnectionId(connectionId); | ||
|
|
||
| return dashboards.map(buildFoundDashboardDto); | ||
| const accessChecks = await Promise.all( | ||
| dashboards.map((dashboard) => | ||
| this.cedarAuthService.validate({ | ||
| userId, | ||
| action: CedarAction.DashboardRead, | ||
| connectionId, | ||
| dashboardId: dashboard.id, | ||
| }), | ||
| ), | ||
| ); | ||
|
Comment on lines
+41
to
+50
|
||
|
|
||
| return dashboards.filter((_, index) => accessChecks[index]).map(buildFoundDashboardDto); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findAllDashboardsWithWidgetsByConnectionIdloads widgets for every dashboard before authorization filtering. With per-dashboard Cedar checks added below, this can fetch potentially large widget payloads for dashboards the caller is not allowed to see, increasing DB load and response time. Consider fetching only dashboard metadata/IDs first, filter by permissions, then load widgets only for the allowed dashboards.