47ng / 47ng/prisma-field-encryption
Plaintext values with mode=strict do not throw errors
- Lingua principale
- TypeScript
- Stelle
- 306
- Fork
- 40
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Given this schema:
```prisma
model EncryptionTest {
id String @id
data String? /// @encrypted?mode=strict
}
```
and this test:
```ts
await prisma.$queryRawUnsafe(
`INSERT INTO encryption_test (id, data) VALUES ('id', 'plaintextdata')`,
);
const encryptionTest = await prisma.encryptionTest.findFirst({
where: { id: 'id' },
});
```
I would expect this test case to throw an exception. Is my understanding incorrect?
It's a simple fix if indeed it's unexpected behaviour. https://github.com/47ng/prisma-field-encryption/blob/next/src/encryption.ts#L179 is currently
```ts
if (!cloakedStringRegex.test(cipherText)) {
return
}
```
so if a field is in the database as plaintext (which doesn't match the cloakedStringRegex) then strict mode is not taken into account. Proposed fix:
```ts
if (!cloakedStringRegex.test(cipherText)) {
if (fieldConfig.strictDecryption) {
throw new Error('Value is not encrypted and mode=strict')
}
return
}
```
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.