Skip to content

Commit fe8d6a7

Browse files
authored
fix: correct permission check on attachment uploads (#156)
fixes Aam-Digital/ndb-core#2558
1 parent 4d8619f commit fe8d6a7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/restricted-endpoints/document/document.controller.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,21 @@ export class DocumentController {
102102
@Query() queryParams?: any,
103103
): Promise<DatabaseDocument> {
104104
const userAbility = this.permissionService.getAbilityFor(user);
105-
const document = await firstValueFrom(
105+
106+
let documentToReturn: DatabaseDocument = await firstValueFrom(
106107
this.couchdbService.get(db, docId, queryParams),
107108
);
108-
if (userAbility.can('read', document)) {
109-
return document;
109+
110+
let documentForPermissionCheck: DatabaseDocument = documentToReturn;
111+
112+
if (db === 'app-attachments') {
113+
documentForPermissionCheck = await firstValueFrom(
114+
this.couchdbService.get('app', docId, queryParams),
115+
);
116+
}
117+
118+
if (userAbility.can('read', documentForPermissionCheck)) {
119+
return documentToReturn;
110120
} else {
111121
throw new UnauthorizedException('unauthorized', 'User is not permitted');
112122
}

0 commit comments

Comments
 (0)