cookie-parser icon indicating copy to clipboard operation
cookie-parser copied to clipboard

Support CipherKey type for secret

Open SnowMarble opened this issue 1 year ago • 0 comments

Currently, only string or string array types can be used as secret values.

https://github.com/expressjs/cookie-parser/blob/429cfd4bcfa66f6578af890d83d5c88be1144245/index.js#L33

But cookie-signature allows not only string, but also ArrayBufferView(TypedArray, DataView), and crypto.KeyObject.

The secret is for an HMAC key, so technically we can allow string, ArrayBuffer, Buffer, TypedArray, DataView, KeyObject, and CryptoKey, which is described in the nodejs docs. And these types are represented as crypto.CipherKey type.

This is also related to security concerns. See Using strings as inputs to cryptographic APIs

SnowMarble avatar Jul 29 '24 08:07 SnowMarble