Skip to content

Commit

Permalink
chore(policy): add auth guard injection for list operations in Policy…
Browse files Browse the repository at this point in the history
…ProxyHandler and PolicyUtil
  • Loading branch information
genu committed Jan 7, 2025
1 parent 1ccc6ac commit 6879548
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/runtime/src/enhancements/node/policy/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
return handleRejection();
}

if (isList && !this.policyUtils.injectForList(this.prisma, this.model, _args)) {
if (this.shouldLogQuery) {
this.logger.info(`[policy] \`${actionName}\` ${this.model}: unconditionally denied`);
}

return handleRejection();
}

this.policyUtils.injectReadCheckSelect(this.model, _args);

if (this.shouldLogQuery) {
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime/src/enhancements/node/policy/policy-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,14 @@ export class PolicyUtil extends QueryUtils {
return true;
}

/**
* Injects auth guard for read operations.
*/
injectForList(_db: CrudContract, _model: string, _args: any) {
// make select and include visible to the injection
return true;
}

//#endregion

//#region Checker
Expand Down

0 comments on commit 6879548

Please sign in to comment.