Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm proposing support for encrypted cookies in Express. I followed an approach similar to the cookie signing code. I created the package symmetric-cipher.js which has the encrypt and decrypt functionality. It uses symmetric encryption ('AES-256-CBC') and creates a sha256 hash of the key if the key length is not 32 bytes (256 bits). Encrypted cookies are also signed, to prevent wasting computing resources on a decryption attempt if the cookie has been tampered with. Encryption happens on top of JSON serialisation for JSON cookies so they should decrypt back to
j:
. I have opened a PR to add encrypted cookie support to the main express library.I have also added the secretEncosing option so secrets can be used for encryption in encoding schemes like 'base64' and 'hex'. Since [email protected] only accepts UTF8 strings, the signing and unsigning is done using the secret as a UTF string, and then encryption and decryption use the specified encoding.