Closed itishermann closed 1 year ago
Hi, it is an intended behaviour for the method encryptObject to only encrypt keys that have a string value as described in the comment of the function encryptObject.
Since it's not a bug I will remove the bug
tag from this issue and replace it with enhancement
, but encrypting boolean might not be useful since there is only two values true or false making it easy to guess and test, as for the numbers maybe it might be useful in some cases but I can't see which ones right now, but an easy work around is simply to make it a string and do a parseInt in your application for now.
Since there is an easy work around and no real use case for now it's not a priority for us to change this behaviour right now, but feel free to make a Pull Request 🙂
@itishermann I'm not convinced about having the type in the string (e.g. true+boolean
) because then it will became complicated to handle string with+
inside.
The Vault is meant to be used to encrypt secrets like authentication credentials and those secrets are mainly strings. You can have numbers as secrets (e.g. RSA keys are big prime numbers) but usually those numbers are represented as a base 64 string.
If you really want to encrypt something different than a string then you could add the type in the encrypted string;
<encrypted-data>.<initialization-vector>
<encrypted-data>.<initialization-vector>.<type>
For example: f700cac98100f1266536553f3181ada6.65dfa691071a81f3214be3836bbb9fa1.integer
To avoid breaking change, encrypted string with only two part (actual representation) should be considered as string
Expected Behavior
All the properties of all types of objects to be encrypted should be encrypted.
Current Behavior
If a property of the object to be encrypted is not a string, the property doest not get encrypted and it's not added to the encrypted object.
Possible Solution
In the function encryptObject, the function should check if the property is something else than a string. if it is, cast the property to string and add the type at the end of the string. This way, the property will be encrypted as a string and when decrypting, the type can be restored.
For example:
So the encryptObject would look like this:
ant the decyptString would look like this:
Steps to Reproduce
kourou vault:encrypt secrets.json --vault-key password
Context (Environment)
Kuzzle version: 2.18.1 Node.js version: 16.14.2 SDK version: - Kourous version: 0.22.0