diff --git a/packages/core/package.json b/packages/core/package.json index 219604c66a..082a4ba0f1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -68,7 +68,6 @@ "license": "ISC", "dependencies": { "@panva/hkdf": "^1.2.1", - "cookie": "1.0.1", "jose": "^5.9.6", "oauth4webapi": "^3.1.1", "preact": "10.24.3", diff --git a/packages/core/src/jwt.ts b/packages/core/src/jwt.ts index 22b9bbd11a..fe93e12668 100644 --- a/packages/core/src/jwt.ts +++ b/packages/core/src/jwt.ts @@ -42,7 +42,7 @@ import { defaultCookies, SessionStore } from "./lib/utils/cookie.js" import { Awaitable } from "./types.js" import type { LoggerInstance } from "./lib/utils/logger.js" import { MissingSecret } from "./errors.js" -import * as cookie from "cookie" +import * as cookie from "./lib/vendored/cookie.js" const { parse: parseCookie } = cookie const DEFAULT_MAX_AGE = 30 * 24 * 60 * 60 // 30 days diff --git a/packages/core/src/lib/utils/cookie.ts b/packages/core/src/lib/utils/cookie.ts index f129a00c45..7932b37a09 100644 --- a/packages/core/src/lib/utils/cookie.ts +++ b/packages/core/src/lib/utils/cookie.ts @@ -7,7 +7,7 @@ import type { // Uncomment to recalculate the estimated size // of an empty session cookie -// import * as cookie from "cookie" +// import * as cookie from "../vendored/cookie.js" // const { serialize } = cookie // console.log( // "Cookie estimated to be ", diff --git a/packages/core/src/lib/utils/web.ts b/packages/core/src/lib/utils/web.ts index 047749016b..9e782978bb 100644 --- a/packages/core/src/lib/utils/web.ts +++ b/packages/core/src/lib/utils/web.ts @@ -1,4 +1,4 @@ -import * as cookie from "cookie" +import * as cookie from "../vendored/cookie.js" import { UnknownAction } from "../../errors.js" import { setLogger } from "./logger.js" diff --git a/packages/core/src/lib/vendored/cookie.ts b/packages/core/src/lib/vendored/cookie.ts new file mode 100644 index 0000000000..2e796e9ace --- /dev/null +++ b/packages/core/src/lib/vendored/cookie.ts @@ -0,0 +1,383 @@ +/** + * @source https://github.com/jshttp/cookie + * @author blakeembrey + * @license MIT + */ + +/** + * This is a workaround to support ESM-only environments, until `cookie` ships ESM builds. + * @see https://github.com/jshttp/cookie/issues/211 + */ + +/** + * RegExp to match cookie-name in RFC 6265 sec 4.1.1 + * This refers out to the obsoleted definition of token in RFC 2616 sec 2.2 + * which has been replaced by the token definition in RFC 7230 appendix B. + * + * cookie-name = token + * token = 1*tchar + * tchar = "!" / "#" / "$" / "%" / "&" / "'" / + * "*" / "+" / "-" / "." / "^" / "_" / + * "`" / "|" / "~" / DIGIT / ALPHA + */ +const cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/ + +/** + * RegExp to match cookie-value in RFC 6265 sec 4.1.1 + * + * cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE ) + * cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E + * ; US-ASCII characters excluding CTLs, + * ; whitespace DQUOTE, comma, semicolon, + * ; and backslash + */ +const cookieValueRegExp = + /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/ + +/** + * RegExp to match domain-value in RFC 6265 sec 4.1.1 + * + * domain-value = + * ; defined in [RFC1034], Section 3.5, as + * ; enhanced by [RFC1123], Section 2.1 + * =