-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encryptedField value does not change when decrypting #77
base: master
Are you sure you want to change the base?
Conversation
Hi @Yeh35 Thank you very much for taking the time to make this change! I am curious about this use case - if the field is empty then it really should not encrypt anything. How do you manage to encrypt the field and then put data into it? Would you be able to provide some code of your use case? Thanks! |
Hi @wheresvic import Mongoose from "mongoose";
import { fieldEncryption } from "mongoose-field-encryption"
const host = "<Yser MongoDB URL>"
Mongoose.connect(host); //
/**
* This is for test code
*/
const testSchema = new Mongoose.Schema({
user_mobile: { type: String, required: false, default : "" },
});
testSchema.plugin(fieldEncryption, {
fields: ["user_mobile"],
secret: "Yq3t6w9z$C&F)J@McQfTjWnZr4u7x!A%", // testting key
useAes256Ctr : true,
});
const testModel = Mongoose.model("testDocument", testSchema);
const newTest = new testModel({user_mobile : ""}); // If you store the first value empty
await newTest.save();
var findedModel = await testModel.findById(newTest.id);
// From then on, it is stored in the DB as plaintext
findedModel.user_mobile = "010-1234-5678";
await findedModel.save(); |
Hi @Yeh35 I see the issue but I think that this is a very convoluted use case. If you want to make a dummy marker I would actually recommend that you use some constant like |
Hi @Yeh35 I added a test to encrypt an empty value, change it and it is recording the change correctly: mongoose-field-encryption/test/test-db.js Line 688 in 99d9499
So I do not see how the existing code is broken in this case either. It would be helpful if you could add a test to document the incorrect behavior. Thanks! |
Version |
hello.
First of all, I am not good at English.
If you don't understand, please tell me again.
While using the plugin, I found an issue where field values were not encrypted and stored when empty.
After that, even if I add a value to the field and store it, there is no encryption and the plaintext is stored.
During encryption, encryptField was changed to true value even if the value was empty, but in decryption, even if the value was empty, it did not change to false.
The code I modified is to change encryptedField to false even if the value is empty when decrypting.
then have a nice day