From 189f1226aa355467954789584fe2aa4d29620610 Mon Sep 17 00:00:00 2001 From: "Ismail H. Ayaz" Date: Tue, 21 Sep 2021 23:01:28 +0300 Subject: [PATCH] chore: release v0.0.7 --- CHANGELOG.md | 7 +++++++ dist/index.cjs | 4 ++-- dist/index.cjs.map | 2 +- dist/index.esm.js | 4 ++-- dist/index.esm.js.map | 2 +- dist/index.js | 4 ++-- dist/index.js.map | 2 +- dist/index.mjs | 4 ++-- dist/index.mjs.map | 2 +- docs/README.md | 6 +++--- docs/classes/Cookies.md | 34 +++++++++++++++++----------------- package-lock.json | 2 +- package.json | 2 +- 13 files changed, 41 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8444f88..bc4934b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.0.7](https://github.com/ayZagen/secure-cookie/compare/v0.0.6...v0.0.7) (2021-09-21) + + +### Bug Fixes + +* koa middleware fails with async ([e57275f](https://github.com/ayZagen/secure-cookie/commit/e57275fe2bff66c853a6ba146e10341059715916)) + ## [0.0.6](https://github.com/ayZagen/secure-cookie/compare/v0.0.5...v0.0.6) (2021-09-21) ## [0.0.5](https://github.com/ayZagen/secure-cookie/compare/v0.0.4...v0.0.5) (2021-09-21) diff --git a/dist/index.cjs b/dist/index.cjs index 4e58db9..d69defb 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -1,5 +1,5 @@ /*! - * secure-cookie v0.0.6 + * secure-cookie v0.0.7 * (c) Ismail H. Ayaz * Released under the MIT License. */ @@ -413,7 +413,7 @@ var Cookies = /** @class */ (function () { = ctx.res.cookies = ctx.request.cookies = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options); - next(); + return next(); }; }; return Cookies; }()); diff --git a/dist/index.cjs.map b/dist/index.cjs.map index bab5935..fef0b28 100644 --- a/dist/index.cjs.map +++ b/dist/index.cjs.map @@ -1 +1 @@ -{"version":3,"file":"index.cjs","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options)\n next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":["crypto","compare","http"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QACX,aAAQ,GAA6B,KAAK,CAAC;QAC3C,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ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MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;;;"} \ No newline at end of file +{"version":3,"file":"index.cjs","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options);\n return next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":["crypto","compare","http"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QACX,aAAQ,GAA6B,KAAK,CAAC;QAC3C,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,IAAI,CAAC;QAChB,cAAS,GAAG,KAAK,CAAC;QAKhB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAClC,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;SACjD;QAED,IAAI,KAAK,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC5C,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAEzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpD,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAC;SAC/C;QAED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G,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClE,OAAO,IAAI,EAAE,CAAA;KACd,GAAA,CAAA;IACH,cAAC;CAxJD,IAwJC;AAGD,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,OAAO,KAAK,CAAC,IAAI,CAAW,CAAC;KAC9B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,MAAM,CAC7B,cAAY,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;;;"} \ No newline at end of file diff --git a/dist/index.esm.js b/dist/index.esm.js index af5f641..3009e60 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -1,5 +1,5 @@ /*! - * secure-cookie v0.0.6 + * secure-cookie v0.0.7 * (c) Ismail H. Ayaz * Released under the MIT License. */ @@ -403,7 +403,7 @@ var Cookies = /** @class */ (function () { = ctx.res.cookies = ctx.request.cookies = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options); - next(); + return next(); }; }; return Cookies; }()); diff --git a/dist/index.esm.js.map b/dist/index.esm.js.map index e436adb..24b65a2 100644 --- a/dist/index.esm.js.map +++ b/dist/index.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"index.esm.js","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options)\n next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QAC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,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;"} \ No newline at end of file +{"version":3,"file":"index.esm.js","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options);\n return next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QACX,aAAQ,GAA6B,KAAK,CAAC;QAC3C,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,IAAI,CAAC;QAChB,cAAS,GAAG,KAAK,CAAC;QAKhB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAClC,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;SACjD;QAED,IAAI,KAAK,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC5C,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAEzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpD,MAAM,IAAI,SAAS,CAAC,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,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClE,OAAO,IAAI,EAAE,CAAA;KACd,GAAA,CAAA;IACH,cAAC;CAxJD,IAwJC;AAGD,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,OAAO,KAAK,CAAC,IAAI,CAAW,CAAC;KAC9B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,MAAM,CAC7B,cAAY,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index bd8e221..34eb97f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ /*! - * secure-cookie v0.0.6 + * secure-cookie v0.0.7 * (c) Ismail H. Ayaz * Released under the MIT License. */ @@ -413,7 +413,7 @@ var Cookies = /** @class */ (function () { = ctx.res.cookies = ctx.request.cookies = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options); - next(); + return next(); }; }; return Cookies; }()); diff --git a/dist/index.js.map b/dist/index.js.map index 01812e8..ad86388 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options)\n next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":["crypto","compare","http"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,C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AAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;;;"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options);\n return next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":["crypto","compare","http"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QACX,aAAQ,GAA6B,KAAK,CAAC;QAC3C,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,IAAI,CAAC;QAChB,cAAS,GAAG,KAAK,CAAC;QAKhB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAClC,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;SACjD;QAED,IAAI,KAAK,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC5C,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAEzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI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f,GAAG,CAAC,OAAO,CAAC,OAAO;0BACnB,GAAG,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClE,OAAO,IAAI,EAAE,CAAA;KACd,GAAA,CAAA;IACH,cAAC;CAxJD,IAwJC;AAGD,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,OAAO,KAAK,CAAC,IAAI,CAAW,CAAC;KAC9B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,MAAM,CAC7B,cAAY,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;;;"} \ No newline at end of file diff --git a/dist/index.mjs b/dist/index.mjs index 24e1abd..f170adf 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1,5 +1,5 @@ /*! - * secure-cookie v0.0.6 + * secure-cookie v0.0.7 * (c) Ismail H. Ayaz * Released under the MIT License. */ @@ -403,7 +403,7 @@ var Cookies = /** @class */ (function () { = ctx.res.cookies = ctx.request.cookies = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options); - next(); + return next(); }; }; return Cookies; }()); diff --git a/dist/index.mjs.map b/dist/index.mjs.map index 6dc00fc..99fccdf 100644 --- a/dist/index.mjs.map +++ b/dist/index.mjs.map @@ -1 +1 @@ -{"version":3,"file":"index.mjs","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options)\n next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gB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B,cAAY,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../src/cookie.ts","../src/ciphers.ts","../src/keystore.ts","../src/cookies.ts"],"sourcesContent":["// eslint-disable-next-line no-control-regex\nconst fieldContentRegExp = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+$/;\nconst SAME_SITE_REGEXP = /^(?:lax|none|strict)$/i;\n\nexport interface CookieAttrs {\n /**\n * a `Date` object indicating the cookie's expiration date (expires at the end of session by default).\n */\n expires?: Date;\n /**\n * a number representing the milliseconds from `Date.now()` for expiry\n */\n maxAge?: number | null;\n /**\n * a boolean or string indicating whether the cookie is a \"same site\" cookie (`false` by default). This can be set to `'strict'`, `'lax'`, `'none'`, or `true` (which maps to `'strict'`).\n */\n sameSite?: 'lax' | 'none' | 'strict' | boolean;\n /**\n * a string indicating the path of the cookie (`/` by default).\n */\n path?: string;\n /**\n * a string indicating the domain of the cookie (no default).\n */\n domain?: string;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).\n */\n secure?: boolean;\n /**\n * a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).\n */\n httpOnly?: boolean;\n /**\n * a boolean indicating whether to overwrite previously set cookies of the same name (`false` by default). If this is true, all cookies set during the same request with the same name (regardless of path or domain) are filtered out of the Set-Cookie header when setting this cookie.\n */\n overwrite?: boolean;\n}\n\nexport class Cookie implements CookieAttrs {\n name: string;\n value: string;\n domain?: string;\n path = '/';\n sameSite?: CookieAttrs['sameSite'] = false;\n secure = false;\n httpOnly = true;\n overwrite = false;\n expires?: Date;\n maxAge?: number | null;\n\n constructor(name: string, value?: string | null, attrs?: CookieAttrs) {\n if (!fieldContentRegExp.test(name)) {\n throw new TypeError('argument name is invalid');\n }\n\n if (value && !fieldContentRegExp.test(value)) {\n throw new TypeError('argument value is invalid');\n }\n\n this.name = name;\n this.value = value || '';\n\n Object.assign(this, attrs)\n\n if (!this.value) {\n this.expires = new Date(0);\n this.maxAge = null;\n }\n\n if (this.path && !fieldContentRegExp.test(this.path)) {\n throw new TypeError('option path is invalid');\n }\n\n if (this.domain && !fieldContentRegExp.test(this.domain)) {\n throw new TypeError('option domain is invalid');\n }\n\n if (this.sameSite && this.sameSite !== true && !SAME_SITE_REGEXP.test(this.sameSite)) {\n throw new TypeError('option sameSite is invalid');\n }\n }\n\n toString() {\n return `${this.name}=${this.value}`;\n }\n\n get header() {\n let header = this.toString();\n\n if (this.maxAge) {\n this.expires = new Date(Date.now() + this.maxAge);\n }\n\n if (this.path) {\n header += `; path=${this.path}`;\n }\n if (this.expires) {\n header += `; expires=${this.expires.toUTCString()}`;\n }\n if (this.domain) {\n header += `; domain=${this.domain}`;\n }\n if (this.sameSite) {\n header += `; samesite=${this.sameSite === true ? 'strict' : this.sameSite.toLowerCase()}`;\n }\n if (this.secure) {\n header += '; secure';\n }\n if (this.httpOnly) {\n header += '; httponly';\n }\n\n return header;\n }\n\n}\n","export const CIPHER_INFO = {\n 'aes-128-cbc': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cbc-hmac-sha256': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb1': { ivLength: 16, keyLength: 16 },\n 'aes-128-cfb8': { ivLength: 16, keyLength: 16 },\n 'aes-128-ctr': { ivLength: 16, keyLength: 16 },\n 'aes-128-ecb': { ivLength: undefined, keyLength: 16 },\n 'aes-128-ocb': { ivLength: 12, keyLength: 16 },\n 'aes-128-ofb': { ivLength: 16, keyLength: 16 },\n 'aes-128-xts': { ivLength: 16, keyLength: 32 },\n 'aes-192-cbc': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb1': { ivLength: 16, keyLength: 24 },\n 'aes-192-cfb8': { ivLength: 16, keyLength: 24 },\n 'aes-192-ctr': { ivLength: 16, keyLength: 24 },\n 'aes-192-ecb': { ivLength: undefined, keyLength: 24 },\n 'aes-192-ocb': { ivLength: 12, keyLength: 24 },\n 'aes-192-ofb': { ivLength: 16, keyLength: 24 },\n 'aes-256-cbc': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cbc-hmac-sha256': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb1': { ivLength: 16, keyLength: 32 },\n 'aes-256-cfb8': { ivLength: 16, keyLength: 32 },\n 'aes-256-ctr': { ivLength: 16, keyLength: 32 },\n 'aes-256-ecb': { ivLength: undefined, keyLength: 32 },\n 'aes-256-ocb': { ivLength: 12, keyLength: 32 },\n 'aes-256-ofb': { ivLength: 16, keyLength: 32 },\n 'aes-256-xts': { ivLength: 16, keyLength: 64 },\n 'aes-128-ccm': { ivLength: 12, keyLength: 16 },\n 'aes-128-gcm': { ivLength: 12, keyLength: 16 },\n 'aes-192-ccm': { ivLength: 12, keyLength: 24 },\n 'aes-192-gcm': { ivLength: 12, keyLength: 24 },\n 'aes-256-ccm': { ivLength: 12, keyLength: 32 },\n 'aes-256-gcm': { ivLength: 12, keyLength: 32 },\n 'id-aes128-ccm': { ivLength: 12, keyLength: 16 },\n 'id-aes128-gcm': { ivLength: 12, keyLength: 16 },\n 'id-aes192-ccm': { ivLength: 12, keyLength: 24 },\n 'id-aes192-gcm': { ivLength: 12, keyLength: 24 },\n 'id-aes256-ccm': { ivLength: 12, keyLength: 32 },\n 'id-aes256-gcm': { ivLength: 12, keyLength: 32 },\n} as const\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport compare from 'tsscmp'\n\nimport crypto, {BinaryToTextEncoding, CipherKey, Encoding} from \"crypto\";\nimport {CIPHER_INFO} from \"./ciphers\";\n\nconst AUTH_TAG_REQUIRED = /-(gcm|ccm)/\n\nexport interface KeyStoreOpts {\n signing?: {\n keys: string[],\n algorithm?: string | 'blake2b512' | 'blake2s256' | 'gost' | 'md4' | 'md5' | 'rmd160' | 'sha1' | 'sha224'\n | 'sha256' | 'sha3-224' | 'sha3-256' | 'sha3-384' | 'sha3-512' | 'sha384' | 'sha512' | 'sha512-224'\n | 'sha512-256' | 'shake128' | 'shake256' | 'sm3';\n encoding?: BinaryToTextEncoding\n },\n encryption?: {\n keys: string[] | CipherKey[],\n algorithm?: keyof typeof CIPHER_INFO | string,\n encoding?: Encoding\n authTagLength?: number\n }\n}\n\nexport type EncryptOptions = Required & { key?: string | undefined }\nexport type DecryptOptions = Required & {\n key?: string | CipherKey | undefined,\n iv?: string | Buffer | undefined,\n authTag?: string | Buffer | undefined\n}\n\nexport class KeyStore {\n encryption: Required>;\n signing: Required>;\n\n static cipherInfo = CIPHER_INFO as Record\n\n constructor(opts?: KeyStoreOpts) {\n opts = opts || {}\n if (opts.encryption) {\n if (!Array.isArray(opts.encryption.keys) || opts.encryption.keys.length === 0) {\n throw new Error(\"keys are required for encryption\")\n }\n }\n if (opts.signing) {\n if (!Array.isArray(opts.signing.keys) || opts.signing.keys.length === 0) {\n throw new Error(\"keys are required for signing\")\n }\n }\n this.encryption = Object.assign({\n algorithm: 'aes-192-ccm',\n authTagLength: 16,\n encoding: 'hex', keys: []\n }, opts.encryption || {} as any)\n\n this.signing = Object.assign({encoding: 'base64', algorithm: 'sha1', keys: []}, opts.signing || {} as any)\n\n }\n\n encrypt(data?: null, options?: Partial): null\n encrypt(data: string | Buffer, options?: Partial): string\n encrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n const {\n keys,\n algorithm,\n encoding,\n authTagLength,\n key\n }: EncryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const secret = key || keys[0]\n\n if (!secret) {\n throw new Error(\"no key found\")\n }\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n const iv = cipherInfo.ivLength ? crypto.randomBytes(cipherInfo.ivLength) : null;\n const dataBuff = typeof data === \"string\" ? Buffer.from(data, 'utf-8') : data\n\n const cipher = crypto.createCipheriv(algorithm as any, secret, iv, {authTagLength})\n\n const text = cipher.update(dataBuff);\n const pad = cipher.final();\n let authTag: Buffer | undefined;\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n authTag = cipher.getAuthTag();\n }\n\n return Buffer.concat([\n ...iv ? [iv] : [],\n ...authTag ? [authTag] : [],\n text,\n pad\n ]).toString(encoding)\n }\n\n decrypt(data?: null, options?: Partial): null\n decrypt(data: string | Buffer, options?: Partial): string\n decrypt(data?: string | Buffer | null, options?: Partial): string | null {\n if (!data) {\n return null\n }\n\n const finalOptions: DecryptOptions = options ? Object.assign({}, this.encryption, options) : this.encryption\n\n const {\n encoding,\n key,\n keys: defaultKeys,\n algorithm,\n authTagLength,\n } = finalOptions\n\n const keys = key ? [key] : defaultKeys\n if (keys.length === 0) {\n throw new Error(\"keys required for encrypted cookies\")\n }\n\n let {\n iv,\n authTag\n } = finalOptions\n\n let dataBuff = typeof data === \"string\" ? Buffer.from(data, encoding) : data\n\n const cipherInfo = KeyStore.cipherInfo[algorithm]\n if (!cipherInfo) {\n throw new Error(\"unsupported cipher\")\n }\n\n if (typeof iv === \"string\") {\n iv = Buffer.from(iv, encoding)\n }\n\n if (typeof authTag === \"string\") {\n authTag = Buffer.from(authTag, encoding)\n }\n\n if (cipherInfo.ivLength !== undefined) {\n if (!iv) {\n iv = dataBuff.slice(0, cipherInfo.ivLength)\n }\n dataBuff = dataBuff.slice(cipherInfo.ivLength, dataBuff.length)\n }\n\n\n if (AUTH_TAG_REQUIRED.test(algorithm)) {\n if (!authTag) {\n authTag = dataBuff.slice(0, authTagLength)\n }\n dataBuff = dataBuff.slice(authTagLength, dataBuff.length)\n }\n\n for (let i = 0; i < keys.length; i++) {\n const message = KeyStore.doDecrypt(dataBuff, {...finalOptions, key: keys[i], iv, authTag,});\n if (message !== null) return message\n }\n return null\n }\n\n private static doDecrypt(data: Buffer, options: DecryptOptions): string | null {\n const {algorithm, key, iv, authTagLength, authTag} = options\n const decipher = crypto.createDecipheriv(algorithm as any, key!, iv as Buffer || null, {authTagLength});\n\n if (authTag) {\n decipher.setAuthTag(authTag as Buffer)\n }\n\n const plainText = decipher.update(data)\n let final: Buffer\n try {\n final = decipher.final()\n } catch(e:any) {\n // authentication failed\n return null\n }\n return Buffer.concat([plainText, final]).toString('utf-8')\n }\n\n //region: signing\n\n sign(data?: null, key?: string | CipherKey): null\n sign(data: string, key?: string | CipherKey): string\n sign(data?: string | null, key?: string | CipherKey): string | null {\n if (!data) {\n return null\n }\n const {algorithm, encoding, keys} = this.signing\n key = key || keys[0] as CipherKey\n return crypto\n .createHmac(algorithm, key)\n .update(data).digest(encoding)\n .replace(/\\/|\\+|=/g, function (x) {\n return ({\"/\": \"_\", \"+\": \"-\", \"=\": \"\"})[x] as string\n })\n }\n\n verify(data: string, digest: string): boolean {\n return this.indexOf(data, digest) > -1\n }\n\n indexOf(data: string, digest: string): number {\n const {keys} = this.signing\n\n if (keys.length === 0) {\n throw new Error(\"keys required for signed cookies\")\n }\n\n for (let i = 0; i < keys.length; i++) {\n if (compare(digest, this.sign(data, keys[i] as string))) return i\n }\n return -1\n }\n\n //end-region: signing\n\n}\n\n","import http, {IncomingMessage, ServerResponse} from 'http';\nimport {Cookie, CookieAttrs} from './cookie';\nimport {KeyStore} from \"./keystore\";\nimport type {Http2ServerRequest, Http2ServerResponse} from \"http2\";\n\nconst cache: { [key: string]: RegExp } = {} as any;\ntype SignIdentifier = string | ((name: string) => string)\nexport type CookiesOptions = {\n\n /**\n * KeyStore to be used for signing and encrypting\n */\n keyStore?: KeyStore;\n /**\n * a boolean indicating whether the cookie is to be signed (`false` by default). If this is true, another cookie of the same name with the `signIdentifier` will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [KeyStore](keystore) key. This signature key is used to detect tampering the next time a cookie is received.\n * @default false\n */\n signed?: boolean;\n /**\n * Encrypt cookies by default and assume received cookies are encrypted.\n * @default false\n */\n encrypted?: boolean;\n /**\n * Mark cookies as secure by default.\n * @default `req.protocol`\n */\n secure?: boolean;\n /**\n * If string, provided value will be appended cookie name with dot. For example with given value `mysig`\n * signature cookie name will be `cookiename.mysig`\n *\n * @default `sig`\n */\n signIdentifier?: SignIdentifier\n}\n\nexport type SetCookieOptions = CookiesOptions & CookieAttrs\nexport type GetCookieOptions = CookiesOptions\n\nexport class Cookies {\n\n secure: CookiesOptions[\"secure\"];\n\n encrypted: boolean;\n\n signed: boolean;\n\n keyStore: KeyStore;\n\n signIdentifier?: SignIdentifier\n\n readonly request: IncomingMessage | Http2ServerRequest;\n readonly response: ServerResponse | Http2ServerResponse;\n\n constructor(request: IncomingMessage | Http2ServerRequest, response: ServerResponse | Http2ServerResponse, options: CookiesOptions = {}) {\n this.request = request;\n this.response = response;\n\n this.keyStore = options.keyStore || new KeyStore();\n this.secure = options.secure;\n this.signed = options.signed !== undefined ? options.signed : false;\n this.encrypted = options.encrypted !== undefined ? options.encrypted : false;\n this.signIdentifier = options.signIdentifier || 'sig';\n }\n\n /**\n * This extracts the cookie with the given name from the Set-Cookie header in the request. If such a cookie exists, its value is returned. Otherwise, nothing is returned.\n *\n * `{ signed: true }` can optionally be passed as the second parameter options. In this case, a signature cookie (a cookie of same name ending with the .sig suffix appended) is fetched. If no such cookie exists, nothing is returned.\n *\n * If the signature cookie does exist, the provided KeyStore is used to check whether the hash of cookie-name=cookie-value matches that of any registered key/s:\n *\n * - If the signature cookie hash matches the first key, the original cookie value is returned.\n * - If the signature cookie hash matches any other key, the original cookie value is returned AND an outbound header is set to update the signature cookie's value to the hash of the first key. This enables automatic freshening of signature cookies that have become stale due to key rotation.\n * - If the signature cookie hash does not match any key, nothing is returned, and an outbound header with an expired date is used to delete the cookie.\n *\n * `{ encrypted: true }` can optionally be passed as the second parameter options. In this case, the provided KeyStore will try to decrypt the cookie value with registered key/s.\n *\n * - If the decryption fails nothing is returned, and the cookie stays intact.\n * - If decryption succeeds, decrypted cookie value is returned.\n *\n * If both `signed` and `encrypted` options are provided, signature check will be applied with encrypted value. Than the decryption will be applied.\n * @param name\n * @param opts\n */\n get(name: string, opts?: GetCookieOptions): string | undefined {\n const sigId = opts?.signIdentifier || this.signIdentifier;\n\n const sigName = typeof sigId === 'function' ? sigId.call(null, name)\n : `${name + '.' + sigId}`;\n\n const signed = opts && opts.signed !== undefined ? opts.signed : this.keyStore.signing.keys.length > 0;\n\n const encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n const header = this.request.headers['cookie'];\n if (!header) {\n return undefined;\n }\n\n const match = header.match(getPattern(name));\n if (!match) {\n return undefined;\n }\n\n const value = match[1];\n if (!opts || !signed) {\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n\n const remote = this.get(sigName, {encrypted: false, signed: false});\n if (!remote) {\n return undefined;\n }\n\n const data = `${name}=${value}`;\n const index = this.keyStore.indexOf(data, remote);\n\n if (index < 0) {\n this.set(sigName, null, {path: '/', signed: false});\n return undefined\n } else {\n index && this.set(sigName, this.keyStore.sign(data), {signed: false});\n return encrypted ? this.keyStore.decrypt(value as string) : value;\n }\n }\n\n /**\n * This sets the given cookie in the response and returns the current context to allow chaining.\n *\n * @param name Cookie name\n * @param value Cookie value. If this is omitted, an outbound header with an expired date is used to delete the cookie.\n * @param opts Overridden options\n */\n set(name: string, value?: string | null, opts?: SetCookieOptions): Cookies {\n const res = this.response,\n req = this.request,\n secure = this.secure !== undefined ? !!this.secure : (req).protocol === 'https' || (req).connection['encrypted'],\n encrypted = opts && opts.encrypted !== undefined ? opts.encrypted : this.encrypted;\n\n let headers = (res.getHeader('Set-Cookie') || []) as string[];\n\n const cookie = new Cookie(name, encrypted ? this.keyStore.encrypt(value as string): value, opts);\n const signed = opts && opts.signed !== undefined ? opts.signed : this.signed;\n\n /* istanbul ignore next */\n if (typeof headers == 'string') {\n headers = [headers];\n }\n\n if (!secure && opts && opts.secure) {\n throw new Error('Cannot send secure cookie over unencrypted connection');\n }\n\n cookie.secure = opts && opts.secure !== undefined ? opts.secure : secure;\n\n pushCookie(headers, cookie);\n\n if (opts && signed) {\n cookie.value = this.keyStore.sign(cookie.toString());\n\n const sigId = opts.signIdentifier || this.signIdentifier;\n\n if (typeof sigId === 'function') {\n cookie.name = sigId.call(null, cookie.name);\n } else {\n cookie.name = `${cookie.name + '.' + sigId}`;\n }\n pushCookie(headers, cookie);\n }\n\n const setHeader = (res)[\"set\"] ? http.OutgoingMessage.prototype.setHeader : res.setHeader;\n setHeader.call(res, 'Set-Cookie', headers);\n return this;\n }\n\n static middleware = (options?: CookiesOptions) => (req: any, res: any, next: any) => {\n req.cookies = res.cookies = new Cookies(req, res, options);\n next();\n }\n\n static connect = Cookies.middleware\n static express = Cookies.middleware\n static koa = (options?: CookiesOptions) => (ctx: any, next: any) => {\n ctx.cookies\n = ctx.req.cookies\n = ctx.res.cookies\n = ctx.request.cookies\n = ctx.response.cookies = new Cookies(ctx.req, ctx.res, options);\n return next()\n }\n}\n\n\nfunction getPattern(name: string): RegExp {\n if (cache[name]) {\n return cache[name] as RegExp;\n }\n\n return cache[name] = new RegExp(\n `(?:^|;) *${name.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')}=([^;]*)`\n );\n}\n\nfunction pushCookie(headers: string[], cookie: Cookie) {\n if (cookie.overwrite) {\n for (let i = headers.length - 1; i >= 0; i--) {\n if (headers[i]!.indexOf(`${cookie.name}=`) === 0) {\n headers.splice(i, 1);\n }\n }\n }\n\n headers.push(cookie.header);\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA,IAAM,kBAAkB,GAAG,uCAAuC,CAAC;AACnE,IAAM,gBAAgB,GAAG,wBAAwB,CAAC;;IAiDhD,gBAAY,IAAY,EAAE,KAAqB,EAAE,KAAmB;QARpE,SAAI,GAAG,GAAG,CAAC;QACX,aAAQ,GAA6B,KAAK,CAAC;QAC3C,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,IAAI,CAAC;QAChB,cAAS,GAAG,KAAK,CAAC;QAKhB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAClC,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;SACjD;QAED,IAAI,KAAK,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC5C,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,EAAE,CAAC;QAEzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,IAA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,OAAO;sBACf,GAAG,CAAC,OAAO,CAAC,OAAO;0BACnB,GAAG,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClE,OAAO,IAAI,EAAE,CAAA;KACd,GAAA,CAAA;IACH,cAAC;CAxJD,IAwJC;AAGD,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,OAAO,KAAK,CAAC,IAAI,CAAW,CAAC;KAC9B;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,MAAM,CAC7B,cAAY,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAU,CACvE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,OAAiB,EAAE,MAAc;IACnD,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,KAAK,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YAC5C,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,OAAO,CAAI,MAAM,CAAC,IAAI,MAAG,CAAC,KAAK,CAAC,EAAE;gBAChD,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACtB;SACF;KACF;IAED,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;;;;"} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 9c2d879..7c50403 100644 --- a/docs/README.md +++ b/docs/README.md @@ -32,7 +32,7 @@ secure-cookie #### Defined in -[cookies.ts:8](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L8) +[cookies.ts:8](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L8) ___ @@ -42,7 +42,7 @@ ___ #### Defined in -[cookies.ts:39](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L39) +[cookies.ts:39](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L39) ___ @@ -52,4 +52,4 @@ ___ #### Defined in -[cookies.ts:38](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L38) +[cookies.ts:38](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L38) diff --git a/docs/classes/Cookies.md b/docs/classes/Cookies.md index 7f5a028..ecc55c7 100644 --- a/docs/classes/Cookies.md +++ b/docs/classes/Cookies.md @@ -43,7 +43,7 @@ #### Defined in -[cookies.ts:56](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L56) +[cookies.ts:56](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L56) ## Properties @@ -53,7 +53,7 @@ #### Defined in -[cookies.ts:45](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L45) +[cookies.ts:45](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L45) ___ @@ -63,7 +63,7 @@ ___ #### Defined in -[cookies.ts:49](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L49) +[cookies.ts:49](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L49) ___ @@ -73,7 +73,7 @@ ___ #### Defined in -[cookies.ts:53](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L53) +[cookies.ts:53](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L53) ___ @@ -83,7 +83,7 @@ ___ #### Defined in -[cookies.ts:54](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L54) +[cookies.ts:54](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L54) ___ @@ -93,7 +93,7 @@ ___ #### Defined in -[cookies.ts:43](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L43) +[cookies.ts:43](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L43) ___ @@ -103,7 +103,7 @@ ___ #### Defined in -[cookies.ts:51](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L51) +[cookies.ts:51](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L51) ___ @@ -113,7 +113,7 @@ ___ #### Defined in -[cookies.ts:47](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L47) +[cookies.ts:47](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L47) ___ @@ -151,7 +151,7 @@ ___ #### Defined in -[cookies.ts:183](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L183) +[cookies.ts:183](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L183) ___ @@ -189,7 +189,7 @@ ___ #### Defined in -[cookies.ts:184](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L184) +[cookies.ts:184](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L184) ## Methods @@ -227,7 +227,7 @@ If both `signed` and `encrypted` options are provided, signature check will be a #### Defined in -[cookies.ts:87](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L87) +[cookies.ts:87](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L87) ___ @@ -251,13 +251,13 @@ This sets the given cookie in the response and returns the current context to al #### Defined in -[cookies.ts:136](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L136) +[cookies.ts:136](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L136) ___ ### koa -▸ `Static` **koa**(`options?`): (`ctx`: `any`, `next`: `any`) => `void` +▸ `Static` **koa**(`options?`): (`ctx`: `any`, `next`: `any`) => `any` #### Parameters @@ -269,7 +269,7 @@ ___ `fn` -▸ (`ctx`, `next`): `void` +▸ (`ctx`, `next`): `any` ##### Parameters @@ -280,11 +280,11 @@ ___ ##### Returns -`void` +`any` #### Defined in -[cookies.ts:185](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L185) +[cookies.ts:185](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L185) ___ @@ -318,4 +318,4 @@ ___ #### Defined in -[cookies.ts:178](https://github.com/ayZagen/secure-cookie/blob/1fa5a27/src/cookies.ts#L178) +[cookies.ts:178](https://github.com/ayZagen/secure-cookie/blob/e57275f/src/cookies.ts#L178) diff --git a/package-lock.json b/package-lock.json index ffe8ac5..432b801 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "secure-cookie", - "version": "0.0.6", + "version": "0.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1280505..767dd13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "secure-cookie", - "version": "0.0.6", + "version": "0.0.7", "description": "Cookie library/middleware with signing and encryption support", "main": "dist/index.js", "types": "types/index.d.ts",