#178: Feature request to encrypt session data stored in cookies#182
Open
jmitchell38488 wants to merge 3 commits intokoajs:masterfrom
Open
#178: Feature request to encrypt session data stored in cookies#182jmitchell38488 wants to merge 3 commits intokoajs:masterfrom
jmitchell38488 wants to merge 3 commits intokoajs:masterfrom
Conversation
…ession data stored in the cookie. The encrypted data, along with the IV and AuthTag (where applicable) are encoded as a base64 string in the cookie data. A RangeError is thrown if the base64 encoded string exceeds the cookie max length of 4093 bytes, while the module exposes the 'encryptData' and 'decryptData' functions.
…object. This is used to pass the user defined options through to the crypto encode/decode functions
…are used as per the initialisation steps. Updated the 'formatOpts' function to use the defaults values, and added 'useCrypt' as an option, to cryptographically encode/decode the session data stored in the cookie. This uses the existing session storage in the cookie functionality, and only encodes the data when session store is set to cookie.
1 similar comment
Member
|
I'd recommend https://github.com/nicokaiser/koa-encrypted-session for now, or you can write your own wrapper to use specific encrypt/decrypt methods. |
Contributor
Author
|
@dead-horse that one prescribes the algo, rather than letting you set it. I've set this one up with more flex around the algo you can pick, and whether you want to enable it. |
Contributor
Author
|
@dead-horse is this something that would be merged into the code base? |
|
It looks like this would be one way to resolve #181, which may otherwise be a critical security vulnerability. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
encodeanddecodefunctions 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.optsobject and define what algorithm they want to use, the initialization vector length, and the key, and set the flaguseCryptoto true, and the library will handle the rest.eg.
A user can also use these same settings when initialising the
sessioninstance inApp:Output:
I have also updated
index.jsto 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
encodeanddecodefunctionsencryptfileAlso: