
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@hmcts/cookie-encrypter
Advanced tools
Transparently encrypt/decrypt your cookie using an express middleware to set after the cookie-parser.
Support all type of cookie (including http-only and signed) with string content or JSON.
Use aes256
as the default encryption algorithm (internally use the nodejs crypto module).
$ npm install cookie-encrypter
Easy to use:
const express = require('express')
const cookieParser = require('cookie-parser')
const cookieEncrypter = require('cookie-encrypter')
// we use a 32bits long secret key (with aes256)
const secretKey = 'foobarbaz1234567foobarbaz1234567'
const cookieParams = {
httpOnly: true,
signed: true,
maxAge: 300000
}
const app = express()
app.use(cookieParser(secretKey))
// use it as a simple middleware
app.use(cookieEncrypter(secretKey))
app.get('/setcookies', (req, res) => {
// Set encrypted cookies
res.cookie('supercookie', 'my text is encrypted', cookieParams)
res.cookie('supercookie2', { myData: 'is encrypted' }, cookieParams)
// You can still set plain cookies
res.cookie('plaincookie', 'my text is plain', { plain: true })
res.cookie('plaincookie2', { myData: 'is plain' }, { plain: true })
res.json({ status: 'updated' })
})
app.get('/getcookies', (req, res) => {
console.log('Decrypted cookies: ', req.signedCookies)
console.log('Plain cookies: ', req.cookies)
res.json({ status: 'ok' })
})
app.listen(8080)
You can find a ready-to-use example here
Think about the npm install
before running it ;)
secret
a string or array used for encrypting cookies.options
an optional object to set options for encryption.options.algorithm
algorithm used to encrypt cookie data (any algorithm supported by OpenSSL). aes256
used as the default one.Encrypt a cookie value and return it. An options.algorithm
can optionaly be passed to specify an algorithm to use for the encryption.
Decrypt a cookie value and return it. An options.algorithm
can optionaly be passed to specify an algorithm to use for the decryption.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.