Skip to content

Commit acb2ee2

Browse files
committed
refactor: prevent decryption and encryption of null, undefined, or empty string values in EncryptedHandler
1 parent a7169ef commit acb2ee2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/runtime/src/enhancements/node/encrypted.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
141141

142142
const shouldDecrypt = fieldInfo.attributes?.find((attr) => attr.name === '@encrypted');
143143
if (shouldDecrypt) {
144+
// Don't decrypt null, undefined or empty string values
145+
if (!entityData[field]) return;
146+
144147
entityData[field] = await this.decrypt(fieldInfo, entityData[field]);
145148
}
146149
}
@@ -151,7 +154,7 @@ class EncryptedHandler extends DefaultPrismaProxyHandler {
151154
field: async (field, _action, data, context) => {
152155
// Don't encrypt null, undefined or empty string values
153156
if (!data) return;
154-
157+
155158
const encAttr = field.attributes?.find((attr) => attr.name === '@encrypted');
156159
if (encAttr && field.type === 'String') {
157160
context.parent[field.name] = await this.encrypt(field, data);

0 commit comments

Comments
 (0)