Skip to content

Commit

Permalink
refactor: prevent decryption and encryption of null, undefined, or em…
Browse files Browse the repository at this point in the history
…pty string values in EncryptedHandler
  • Loading branch information
genu committed Dec 24, 2024
1 parent a7169ef commit acb2ee2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/runtime/src/enhancements/node/encrypted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {

const shouldDecrypt = fieldInfo.attributes?.find((attr) => attr.name === '@encrypted');
if (shouldDecrypt) {
// Don't decrypt null, undefined or empty string values
if (!entityData[field]) return;

entityData[field] = await this.decrypt(fieldInfo, entityData[field]);
}
}
Expand All @@ -151,7 +154,7 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
field: async (field, _action, data, context) => {
// Don't encrypt null, undefined or empty string values
if (!data) return;

const encAttr = field.attributes?.find((attr) => attr.name === '@encrypted');
if (encAttr && field.type === 'String') {
context.parent[field.name] = await this.encrypt(field, data);
Expand Down

0 comments on commit acb2ee2

Please sign in to comment.