#178: Feature request to encrypt session data stored in cookies #182
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.
This references issue: #178.
When session data is stored in the cookie, it isn't cryptographically encrypted, and is therefore unsecure. The existing
encode
anddecode
functions simply pass the JSON object through to be stringified and converted to base64, and back again.This pull request adds functionality to use crypto-supported algorithms to encrypt their session data, to safely store in a cookie.
The IV length and key length checks are handled by
crypto
, while validation exists within the feature to verify correctly formatted encryption options, encrypted string, and data.A user can extend the
session.opts
object and define what algorithm they want to use, the initialization vector length, and the key, and set the flaguseCrypto
to true, and the library will handle the rest.eg.
A user can also use these same settings when initialising the
session
instance inApp
:Output:
I have also updated
index.js
to include default values for the accepted options. This ensures that values are always set, and that it provides a degree of information to the developer about what options there are.TODO
Add the following test cases
encode
anddecode
functionsencrypt
fileAlso: