Skip to content

Commit 6879548

Browse files
committed
chore(policy): add auth guard injection for list operations in PolicyProxyHandler and PolicyUtil
1 parent 1ccc6ac commit 6879548

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/runtime/src/enhancements/node/policy/handler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
140140
return handleRejection();
141141
}
142142

143+
if (isList && !this.policyUtils.injectForList(this.prisma, this.model, _args)) {
144+
if (this.shouldLogQuery) {
145+
this.logger.info(`[policy] \`${actionName}\` ${this.model}: unconditionally denied`);
146+
}
147+
148+
return handleRejection();
149+
}
150+
143151
this.policyUtils.injectReadCheckSelect(this.model, _args);
144152

145153
if (this.shouldLogQuery) {

packages/runtime/src/enhancements/node/policy/policy-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,14 @@ export class PolicyUtil extends QueryUtils {
652652
return true;
653653
}
654654

655+
/**
656+
* Injects auth guard for read operations.
657+
*/
658+
injectForList(_db: CrudContract, _model: string, _args: any) {
659+
// make select and include visible to the injection
660+
return true;
661+
}
662+
655663
//#endregion
656664

657665
//#region Checker

0 commit comments

Comments
 (0)