Skip to content

Commit

Permalink
fix: correct permission check on attachment uploads (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Sep 4, 2024
1 parent 4d8619f commit fe8d6a7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/restricted-endpoints/document/document.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ export class DocumentController {
@Query() queryParams?: any,
): Promise<DatabaseDocument> {
const userAbility = this.permissionService.getAbilityFor(user);
const document = await firstValueFrom(

let documentToReturn: DatabaseDocument = await firstValueFrom(
this.couchdbService.get(db, docId, queryParams),
);
if (userAbility.can('read', document)) {
return document;

let documentForPermissionCheck: DatabaseDocument = documentToReturn;

if (db === 'app-attachments') {
documentForPermissionCheck = await firstValueFrom(
this.couchdbService.get('app', docId, queryParams),
);
}

if (userAbility.can('read', documentForPermissionCheck)) {
return documentToReturn;
} else {
throw new UnauthorizedException('unauthorized', 'User is not permitted');
}
Expand Down

0 comments on commit fe8d6a7

Please sign in to comment.