elysia 2.0.0-beta.2 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/cookie/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
|
-
const require_constants = require('../constants.js');
|
|
4
3
|
const require_utils = require('../utils.js');
|
|
4
|
+
const require_cookie_error = require('./error.js');
|
|
5
5
|
const require_cookie_lib = require('./lib.js');
|
|
6
6
|
const require_cookie_crypto = require('./crypto.js');
|
|
7
7
|
const require_cookie_cookie = require('./cookie.js');
|
|
@@ -10,16 +10,11 @@ let deuri = require("deuri");
|
|
|
10
10
|
deuri = require_runtime.__toESM(deuri);
|
|
11
11
|
|
|
12
12
|
//#region src/cookie/utils.ts
|
|
13
|
-
async function parseCookie(set, cookieString, options) {
|
|
14
|
-
const config = require_cookie_config.compileCookieConfig(void 0, options);
|
|
15
|
-
return buildCookieJar(set, await parseCookieRaw(cookieString, config), config);
|
|
16
|
-
}
|
|
17
13
|
function parseCookieRawSync(cookieString, _config) {
|
|
18
|
-
|
|
19
|
-
if (!cookieString) return out;
|
|
14
|
+
if (!cookieString) return require_utils.nullObject();
|
|
20
15
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
16
|
+
const out = cookies;
|
|
21
17
|
for (const name in cookies) {
|
|
22
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
23
18
|
const v = cookies[name];
|
|
24
19
|
if (v === void 0) continue;
|
|
25
20
|
out[name] = require_cookie_crypto.maybeJsonDecode((0, deuri.default)(v) ?? v);
|
|
@@ -33,23 +28,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
33
28
|
* the raw record before the handler touches a name.
|
|
34
29
|
*/
|
|
35
30
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
36
|
-
|
|
37
|
-
if (!cookieString) return out;
|
|
38
|
-
const cookies = require_cookie_lib.parse(cookieString);
|
|
39
|
-
for (const name in cookies) {
|
|
40
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
41
|
-
const v = cookies[name];
|
|
42
|
-
if (v === void 0) continue;
|
|
43
|
-
out[name] = v;
|
|
44
|
-
}
|
|
45
|
-
return out;
|
|
31
|
+
return cookieString ? require_cookie_lib.parse(cookieString) : require_utils.nullObject();
|
|
46
32
|
}
|
|
47
33
|
function parseCookieRawLazy(cookieString, config) {
|
|
48
|
-
|
|
49
|
-
if (!cookieString) return out;
|
|
34
|
+
if (!cookieString) return require_utils.nullObject();
|
|
50
35
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
36
|
+
const out = cookies;
|
|
51
37
|
for (const name in cookies) {
|
|
52
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
53
38
|
const v = cookies[name];
|
|
54
39
|
if (v === void 0) continue;
|
|
55
40
|
const decoded = (0, deuri.default)(v) ?? v;
|
|
@@ -57,35 +42,57 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
57
42
|
}
|
|
58
43
|
return out;
|
|
59
44
|
}
|
|
60
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Raw-record value of a signed cookie that failed verification on a lane that
|
|
47
|
+
* can't verify on access (asynchronous HMAC, AOT); the jar rejects its first
|
|
48
|
+
* read. A string key, not a module identity, so a second Elysia copy agrees.
|
|
49
|
+
* Null-prototype, which `JSON.parse` never yields, so no cookie value a client
|
|
50
|
+
* sends (unsigned, or accepted by a `null` rotation secret) can take its shape
|
|
51
|
+
*/
|
|
52
|
+
const invalidSignature = () => {
|
|
53
|
+
const marker = require_utils.nullObject();
|
|
54
|
+
marker["~invalid"] = 1;
|
|
55
|
+
return marker;
|
|
56
|
+
};
|
|
57
|
+
async function parseCookieRaw(cookieString, config, lazy) {
|
|
61
58
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
62
|
-
if (require_cookie_crypto.hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
63
|
-
|
|
64
|
-
if (!cookieString) return out;
|
|
59
|
+
if (require_cookie_crypto.hasSyncHmac) return parseCookieRawSigned(cookieString, config, lazy);
|
|
60
|
+
if (!cookieString) return require_utils.nullObject();
|
|
65
61
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
62
|
+
const out = cookies;
|
|
66
63
|
for (const name in cookies) {
|
|
67
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
68
64
|
const v = cookies[name];
|
|
69
65
|
if (v === void 0) continue;
|
|
70
66
|
let value = (0, deuri.default)(v) ?? v;
|
|
71
67
|
const signCheck = require_cookie_config.resolveSignSecrets(name, config);
|
|
72
|
-
if (signCheck !== void 0)
|
|
68
|
+
if (signCheck !== void 0) try {
|
|
69
|
+
value = await require_cookie_crypto.unsignWithSecrets(name, value, signCheck, require_cookie_config.legacySignatureOf(name, config));
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!lazy || !(error instanceof require_cookie_error.InvalidCookie)) throw error;
|
|
72
|
+
out[name] = invalidSignature();
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
73
75
|
out[name] = require_cookie_crypto.maybeJsonDecode(value);
|
|
74
76
|
}
|
|
75
77
|
return out;
|
|
76
78
|
}
|
|
77
|
-
function parseCookieRawSigned(cookieString, config) {
|
|
79
|
+
function parseCookieRawSigned(cookieString, config, lazy) {
|
|
78
80
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
79
|
-
|
|
80
|
-
if (!cookieString) return out;
|
|
81
|
+
if (!cookieString) return require_utils.nullObject();
|
|
81
82
|
const cookies = require_cookie_lib.parse(cookieString);
|
|
83
|
+
const out = cookies;
|
|
82
84
|
for (const name in cookies) {
|
|
83
|
-
if (require_constants.dangerousKeys.has(name)) continue;
|
|
84
85
|
const v = cookies[name];
|
|
85
86
|
if (v === void 0) continue;
|
|
86
87
|
let value = (0, deuri.default)(v) ?? v;
|
|
87
88
|
const signCheck = require_cookie_config.resolveSignSecrets(name, config);
|
|
88
|
-
if (signCheck !== void 0)
|
|
89
|
+
if (signCheck !== void 0) try {
|
|
90
|
+
value = require_cookie_crypto.unsignWithSecretsSync(name, value, signCheck, require_cookie_config.legacySignatureOf(name, config));
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (!lazy || !(error instanceof require_cookie_error.InvalidCookie)) throw error;
|
|
93
|
+
out[name] = invalidSignature();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
89
96
|
out[name] = require_cookie_crypto.maybeJsonDecode(value);
|
|
90
97
|
}
|
|
91
98
|
return out;
|
|
@@ -99,9 +106,13 @@ function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
|
99
106
|
const fieldDefaults = config.fields[name]?.defaults;
|
|
100
107
|
const entry = Object.assign(require_utils.nullObject(), config.defaults, fieldDefaults, { value: deferDecode ? require_cookie_crypto.maybeJsonDecode((0, deuri.default)(rawValue) ?? rawValue) : rawValue });
|
|
101
108
|
if (entry.expires instanceof Date) entry.expires = new Date(entry.expires.getTime());
|
|
102
|
-
if (
|
|
109
|
+
if (rawValue?.["~invalid"] === 1 && Object.getPrototypeOf(rawValue) === null) entry["~unsign"] = 1;
|
|
110
|
+
else if (lazySign && typeof entry.value === "string") {
|
|
103
111
|
const secrets = require_cookie_config.resolveSignSecrets(name, config);
|
|
104
|
-
if (secrets !== void 0)
|
|
112
|
+
if (secrets !== void 0) {
|
|
113
|
+
entry["~unsign"] = secrets;
|
|
114
|
+
if (!require_cookie_config.legacySignatureOf(name, config)) entry["~strict"] = 1;
|
|
115
|
+
}
|
|
105
116
|
} else {
|
|
106
117
|
const value = entry.value;
|
|
107
118
|
if (value !== null && typeof value === "object") {
|
|
@@ -114,16 +125,27 @@ function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
|
114
125
|
return entry;
|
|
115
126
|
}
|
|
116
127
|
const cache = require_utils.nullObject();
|
|
128
|
+
function settle(key) {
|
|
129
|
+
if (!(key in store)) return;
|
|
130
|
+
const entry = materializeEntry(key);
|
|
131
|
+
if ("~unsign" in entry) require_cookie_crypto.resolvePendingCookie(entry, key);
|
|
132
|
+
}
|
|
117
133
|
return new Proxy(store, {
|
|
118
134
|
get(_, key) {
|
|
119
135
|
return cache[key] ??= new require_cookie_cookie.Cookie(key, set, key in store ? materializeEntry(key) : Object.assign(require_utils.nullObject(), config.defaults, config.fields[key]?.defaults));
|
|
120
136
|
},
|
|
137
|
+
has(target, key) {
|
|
138
|
+
if (typeof key === "string") settle(key);
|
|
139
|
+
return Reflect.has(target, key);
|
|
140
|
+
},
|
|
141
|
+
ownKeys(target) {
|
|
142
|
+
const keys = Reflect.ownKeys(target);
|
|
143
|
+
for (let i = 0; i < keys.length; i++) settle(keys[i]);
|
|
144
|
+
return keys;
|
|
145
|
+
},
|
|
121
146
|
getOwnPropertyDescriptor(target, key) {
|
|
122
|
-
if (typeof key === "string"
|
|
123
|
-
|
|
124
|
-
const entry = descriptor?.value;
|
|
125
|
-
if (entry && typeof entry === "object" && "~unsign" in entry) require_cookie_crypto.resolvePendingCookie(entry, String(key));
|
|
126
|
-
return descriptor;
|
|
147
|
+
if (typeof key === "string") settle(key);
|
|
148
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
127
149
|
}
|
|
128
150
|
});
|
|
129
151
|
}
|
|
@@ -137,43 +159,55 @@ function collectSignPending(cookies, config) {
|
|
|
137
159
|
if (!r.signed) continue;
|
|
138
160
|
let value = property.value;
|
|
139
161
|
if (value === void 0 || value === null) continue;
|
|
162
|
+
if (property["~signed"] === value) continue;
|
|
140
163
|
if (typeof value === "object") {
|
|
141
164
|
value = JSON.stringify(value);
|
|
142
165
|
if (property["~raw"] === value) continue;
|
|
143
166
|
} else if (typeof value !== "string") value = value + "";
|
|
144
167
|
const secret = Array.isArray(r.secrets) ? r.secrets[0] ?? null : r.secrets;
|
|
145
|
-
if (secret
|
|
168
|
+
if (!secret?.trim()) throw new TypeError(`Cookie field "${key}" is signed but no \`secrets\` is provided.`);
|
|
146
169
|
(pending ??= []).push([
|
|
147
170
|
property,
|
|
148
171
|
value,
|
|
149
|
-
secret
|
|
172
|
+
require_cookie_crypto.deriveSignKey(secret, key)
|
|
150
173
|
]);
|
|
151
174
|
}
|
|
152
175
|
return pending;
|
|
153
176
|
}
|
|
177
|
+
function dropSigned(cookies, config) {
|
|
178
|
+
for (const name in cookies) if (config.fields[name]?.sign || config.globalSign === true || config.globalSignSet?.has(name)) delete cookies[name];
|
|
179
|
+
}
|
|
154
180
|
function signCookieValues(cookies, config) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
181
|
+
let pending;
|
|
182
|
+
try {
|
|
183
|
+
pending = collectSignPending(cookies, config);
|
|
184
|
+
if (!pending) return;
|
|
185
|
+
if (require_cookie_crypto.hasSyncHmac) {
|
|
186
|
+
for (let i = 0; i < pending.length; i++) {
|
|
187
|
+
const [property, value, key] = pending[i];
|
|
188
|
+
property["~signed"] = property.value = require_cookie_crypto.signCookieSyncImpl(value, key);
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
161
191
|
}
|
|
162
|
-
|
|
192
|
+
} catch (error) {
|
|
193
|
+
dropSigned(cookies, config);
|
|
194
|
+
throw error;
|
|
163
195
|
}
|
|
164
|
-
return signPending(pending)
|
|
196
|
+
return signPending(pending).catch((error) => {
|
|
197
|
+
dropSigned(cookies, config);
|
|
198
|
+
throw error;
|
|
199
|
+
});
|
|
165
200
|
}
|
|
166
201
|
async function signPending(pending) {
|
|
167
202
|
for (let i = 0; i < pending.length; i++) {
|
|
168
|
-
const [property, value,
|
|
169
|
-
property.value = await require_cookie_crypto.signCookie(value,
|
|
203
|
+
const [property, value, key] = pending[i];
|
|
204
|
+
property["~signed"] = property.value = await require_cookie_crypto.signCookie(value, key);
|
|
170
205
|
}
|
|
171
206
|
}
|
|
172
207
|
|
|
173
208
|
//#endregion
|
|
174
209
|
exports.buildCookieJar = buildCookieJar;
|
|
175
210
|
exports.hasSyncHmac = require_cookie_crypto.hasSyncHmac;
|
|
176
|
-
exports.parseCookie = parseCookie;
|
|
177
211
|
exports.parseCookieRaw = parseCookieRaw;
|
|
178
212
|
exports.parseCookieRawDeferred = parseCookieRawDeferred;
|
|
179
213
|
exports.parseCookieRawLazy = parseCookieRawLazy;
|
package/dist/cookie/utils.mjs
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { dangerousKeys } from "../constants.mjs";
|
|
2
1
|
import { nullObject } from "../utils.mjs";
|
|
2
|
+
import { InvalidCookie } from "./error.mjs";
|
|
3
3
|
import { parse } from "./lib.mjs";
|
|
4
|
-
import { hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieSyncImpl, unsignWithSecrets, unsignWithSecretsSync } from "./crypto.mjs";
|
|
4
|
+
import { deriveSignKey, hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieSyncImpl, unsignWithSecrets, unsignWithSecretsSync } from "./crypto.mjs";
|
|
5
5
|
import { Cookie } from "./cookie.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { isCookieSigned, legacySignatureOf, resolveSignSecrets } from "./config.mjs";
|
|
7
7
|
import decodeComponent from "deuri";
|
|
8
8
|
|
|
9
9
|
//#region src/cookie/utils.ts
|
|
10
|
-
async function parseCookie(set, cookieString, options) {
|
|
11
|
-
const config = compileCookieConfig(void 0, options);
|
|
12
|
-
return buildCookieJar(set, await parseCookieRaw(cookieString, config), config);
|
|
13
|
-
}
|
|
14
10
|
function parseCookieRawSync(cookieString, _config) {
|
|
15
|
-
|
|
16
|
-
if (!cookieString) return out;
|
|
11
|
+
if (!cookieString) return nullObject();
|
|
17
12
|
const cookies = parse(cookieString);
|
|
13
|
+
const out = cookies;
|
|
18
14
|
for (const name in cookies) {
|
|
19
|
-
if (dangerousKeys.has(name)) continue;
|
|
20
15
|
const v = cookies[name];
|
|
21
16
|
if (v === void 0) continue;
|
|
22
17
|
out[name] = maybeJsonDecode(decodeComponent(v) ?? v);
|
|
@@ -30,23 +25,13 @@ function parseCookieRawSync(cookieString, _config) {
|
|
|
30
25
|
* the raw record before the handler touches a name.
|
|
31
26
|
*/
|
|
32
27
|
function parseCookieRawDeferred(cookieString, _config) {
|
|
33
|
-
|
|
34
|
-
if (!cookieString) return out;
|
|
35
|
-
const cookies = parse(cookieString);
|
|
36
|
-
for (const name in cookies) {
|
|
37
|
-
if (dangerousKeys.has(name)) continue;
|
|
38
|
-
const v = cookies[name];
|
|
39
|
-
if (v === void 0) continue;
|
|
40
|
-
out[name] = v;
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
28
|
+
return cookieString ? parse(cookieString) : nullObject();
|
|
43
29
|
}
|
|
44
30
|
function parseCookieRawLazy(cookieString, config) {
|
|
45
|
-
|
|
46
|
-
if (!cookieString) return out;
|
|
31
|
+
if (!cookieString) return nullObject();
|
|
47
32
|
const cookies = parse(cookieString);
|
|
33
|
+
const out = cookies;
|
|
48
34
|
for (const name in cookies) {
|
|
49
|
-
if (dangerousKeys.has(name)) continue;
|
|
50
35
|
const v = cookies[name];
|
|
51
36
|
if (v === void 0) continue;
|
|
52
37
|
const decoded = decodeComponent(v) ?? v;
|
|
@@ -54,35 +39,57 @@ function parseCookieRawLazy(cookieString, config) {
|
|
|
54
39
|
}
|
|
55
40
|
return out;
|
|
56
41
|
}
|
|
57
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Raw-record value of a signed cookie that failed verification on a lane that
|
|
44
|
+
* can't verify on access (asynchronous HMAC, AOT); the jar rejects its first
|
|
45
|
+
* read. A string key, not a module identity, so a second Elysia copy agrees.
|
|
46
|
+
* Null-prototype, which `JSON.parse` never yields, so no cookie value a client
|
|
47
|
+
* sends (unsigned, or accepted by a `null` rotation secret) can take its shape
|
|
48
|
+
*/
|
|
49
|
+
const invalidSignature = () => {
|
|
50
|
+
const marker = nullObject();
|
|
51
|
+
marker["~invalid"] = 1;
|
|
52
|
+
return marker;
|
|
53
|
+
};
|
|
54
|
+
async function parseCookieRaw(cookieString, config, lazy) {
|
|
58
55
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
59
|
-
if (hasSyncHmac) return parseCookieRawSigned(cookieString, config);
|
|
60
|
-
|
|
61
|
-
if (!cookieString) return out;
|
|
56
|
+
if (hasSyncHmac) return parseCookieRawSigned(cookieString, config, lazy);
|
|
57
|
+
if (!cookieString) return nullObject();
|
|
62
58
|
const cookies = parse(cookieString);
|
|
59
|
+
const out = cookies;
|
|
63
60
|
for (const name in cookies) {
|
|
64
|
-
if (dangerousKeys.has(name)) continue;
|
|
65
61
|
const v = cookies[name];
|
|
66
62
|
if (v === void 0) continue;
|
|
67
63
|
let value = decodeComponent(v) ?? v;
|
|
68
64
|
const signCheck = resolveSignSecrets(name, config);
|
|
69
|
-
if (signCheck !== void 0)
|
|
65
|
+
if (signCheck !== void 0) try {
|
|
66
|
+
value = await unsignWithSecrets(name, value, signCheck, legacySignatureOf(name, config));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (!lazy || !(error instanceof InvalidCookie)) throw error;
|
|
69
|
+
out[name] = invalidSignature();
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
70
72
|
out[name] = maybeJsonDecode(value);
|
|
71
73
|
}
|
|
72
74
|
return out;
|
|
73
75
|
}
|
|
74
|
-
function parseCookieRawSigned(cookieString, config) {
|
|
76
|
+
function parseCookieRawSigned(cookieString, config, lazy) {
|
|
75
77
|
if (!config.hasSign) return parseCookieRawSync(cookieString, config);
|
|
76
|
-
|
|
77
|
-
if (!cookieString) return out;
|
|
78
|
+
if (!cookieString) return nullObject();
|
|
78
79
|
const cookies = parse(cookieString);
|
|
80
|
+
const out = cookies;
|
|
79
81
|
for (const name in cookies) {
|
|
80
|
-
if (dangerousKeys.has(name)) continue;
|
|
81
82
|
const v = cookies[name];
|
|
82
83
|
if (v === void 0) continue;
|
|
83
84
|
let value = decodeComponent(v) ?? v;
|
|
84
85
|
const signCheck = resolveSignSecrets(name, config);
|
|
85
|
-
if (signCheck !== void 0)
|
|
86
|
+
if (signCheck !== void 0) try {
|
|
87
|
+
value = unsignWithSecretsSync(name, value, signCheck, legacySignatureOf(name, config));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (!lazy || !(error instanceof InvalidCookie)) throw error;
|
|
90
|
+
out[name] = invalidSignature();
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
86
93
|
out[name] = maybeJsonDecode(value);
|
|
87
94
|
}
|
|
88
95
|
return out;
|
|
@@ -96,9 +103,13 @@ function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
|
96
103
|
const fieldDefaults = config.fields[name]?.defaults;
|
|
97
104
|
const entry = Object.assign(nullObject(), config.defaults, fieldDefaults, { value: deferDecode ? maybeJsonDecode(decodeComponent(rawValue) ?? rawValue) : rawValue });
|
|
98
105
|
if (entry.expires instanceof Date) entry.expires = new Date(entry.expires.getTime());
|
|
99
|
-
if (
|
|
106
|
+
if (rawValue?.["~invalid"] === 1 && Object.getPrototypeOf(rawValue) === null) entry["~unsign"] = 1;
|
|
107
|
+
else if (lazySign && typeof entry.value === "string") {
|
|
100
108
|
const secrets = resolveSignSecrets(name, config);
|
|
101
|
-
if (secrets !== void 0)
|
|
109
|
+
if (secrets !== void 0) {
|
|
110
|
+
entry["~unsign"] = secrets;
|
|
111
|
+
if (!legacySignatureOf(name, config)) entry["~strict"] = 1;
|
|
112
|
+
}
|
|
102
113
|
} else {
|
|
103
114
|
const value = entry.value;
|
|
104
115
|
if (value !== null && typeof value === "object") {
|
|
@@ -111,16 +122,27 @@ function buildCookieJar(set, raw, config, lazySign, deferDecode) {
|
|
|
111
122
|
return entry;
|
|
112
123
|
}
|
|
113
124
|
const cache = nullObject();
|
|
125
|
+
function settle(key) {
|
|
126
|
+
if (!(key in store)) return;
|
|
127
|
+
const entry = materializeEntry(key);
|
|
128
|
+
if ("~unsign" in entry) resolvePendingCookie(entry, key);
|
|
129
|
+
}
|
|
114
130
|
return new Proxy(store, {
|
|
115
131
|
get(_, key) {
|
|
116
132
|
return cache[key] ??= new Cookie(key, set, key in store ? materializeEntry(key) : Object.assign(nullObject(), config.defaults, config.fields[key]?.defaults));
|
|
117
133
|
},
|
|
134
|
+
has(target, key) {
|
|
135
|
+
if (typeof key === "string") settle(key);
|
|
136
|
+
return Reflect.has(target, key);
|
|
137
|
+
},
|
|
138
|
+
ownKeys(target) {
|
|
139
|
+
const keys = Reflect.ownKeys(target);
|
|
140
|
+
for (let i = 0; i < keys.length; i++) settle(keys[i]);
|
|
141
|
+
return keys;
|
|
142
|
+
},
|
|
118
143
|
getOwnPropertyDescriptor(target, key) {
|
|
119
|
-
if (typeof key === "string"
|
|
120
|
-
|
|
121
|
-
const entry = descriptor?.value;
|
|
122
|
-
if (entry && typeof entry === "object" && "~unsign" in entry) resolvePendingCookie(entry, String(key));
|
|
123
|
-
return descriptor;
|
|
144
|
+
if (typeof key === "string") settle(key);
|
|
145
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
124
146
|
}
|
|
125
147
|
});
|
|
126
148
|
}
|
|
@@ -134,38 +156,51 @@ function collectSignPending(cookies, config) {
|
|
|
134
156
|
if (!r.signed) continue;
|
|
135
157
|
let value = property.value;
|
|
136
158
|
if (value === void 0 || value === null) continue;
|
|
159
|
+
if (property["~signed"] === value) continue;
|
|
137
160
|
if (typeof value === "object") {
|
|
138
161
|
value = JSON.stringify(value);
|
|
139
162
|
if (property["~raw"] === value) continue;
|
|
140
163
|
} else if (typeof value !== "string") value = value + "";
|
|
141
164
|
const secret = Array.isArray(r.secrets) ? r.secrets[0] ?? null : r.secrets;
|
|
142
|
-
if (secret
|
|
165
|
+
if (!secret?.trim()) throw new TypeError(`Cookie field "${key}" is signed but no \`secrets\` is provided.`);
|
|
143
166
|
(pending ??= []).push([
|
|
144
167
|
property,
|
|
145
168
|
value,
|
|
146
|
-
secret
|
|
169
|
+
deriveSignKey(secret, key)
|
|
147
170
|
]);
|
|
148
171
|
}
|
|
149
172
|
return pending;
|
|
150
173
|
}
|
|
174
|
+
function dropSigned(cookies, config) {
|
|
175
|
+
for (const name in cookies) if (config.fields[name]?.sign || config.globalSign === true || config.globalSignSet?.has(name)) delete cookies[name];
|
|
176
|
+
}
|
|
151
177
|
function signCookieValues(cookies, config) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
let pending;
|
|
179
|
+
try {
|
|
180
|
+
pending = collectSignPending(cookies, config);
|
|
181
|
+
if (!pending) return;
|
|
182
|
+
if (hasSyncHmac) {
|
|
183
|
+
for (let i = 0; i < pending.length; i++) {
|
|
184
|
+
const [property, value, key] = pending[i];
|
|
185
|
+
property["~signed"] = property.value = signCookieSyncImpl(value, key);
|
|
186
|
+
}
|
|
187
|
+
return;
|
|
158
188
|
}
|
|
159
|
-
|
|
189
|
+
} catch (error) {
|
|
190
|
+
dropSigned(cookies, config);
|
|
191
|
+
throw error;
|
|
160
192
|
}
|
|
161
|
-
return signPending(pending)
|
|
193
|
+
return signPending(pending).catch((error) => {
|
|
194
|
+
dropSigned(cookies, config);
|
|
195
|
+
throw error;
|
|
196
|
+
});
|
|
162
197
|
}
|
|
163
198
|
async function signPending(pending) {
|
|
164
199
|
for (let i = 0; i < pending.length; i++) {
|
|
165
|
-
const [property, value,
|
|
166
|
-
property.value = await signCookie(value,
|
|
200
|
+
const [property, value, key] = pending[i];
|
|
201
|
+
property["~signed"] = property.value = await signCookie(value, key);
|
|
167
202
|
}
|
|
168
203
|
}
|
|
169
204
|
|
|
170
205
|
//#endregion
|
|
171
|
-
export { buildCookieJar, hasSyncHmac,
|
|
206
|
+
export { buildCookieJar, hasSyncHmac, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|