@holo-js/security 0.3.20 → 0.3.22
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/{chunk-CTRTL4CO.mjs → chunk-F32JK536.mjs} +1 -1
- package/dist/{chunk-FUOZWKHK.mjs → chunk-PC2YCWDH.mjs} +23 -10
- package/dist/client.d.ts +1 -0
- package/dist/client.mjs +3 -2
- package/dist/next/server.mjs +2 -2
- package/dist/nuxt/server.mjs +2 -2
- package/dist/sveltekit/server.mjs +2 -2
- package/package.json +3 -3
|
@@ -38,15 +38,15 @@ function createSecurityClientConfig(config) {
|
|
|
38
38
|
return Object.freeze({
|
|
39
39
|
csrf: Object.freeze({
|
|
40
40
|
field: config.csrf.field,
|
|
41
|
-
cookie: config.csrf.cookie
|
|
41
|
+
cookie: config.csrf.cookie,
|
|
42
|
+
header: config.csrf.header
|
|
42
43
|
})
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
function serializeSecurityClientConfig(config) {
|
|
46
47
|
return JSON.stringify(config);
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
const raw = parseCookieHeader(cookieHeader)[SECURITY_CLIENT_CONFIG_COOKIE];
|
|
49
|
+
function parseSecurityClientConfig(raw) {
|
|
50
50
|
if (!raw) {
|
|
51
51
|
return void 0;
|
|
52
52
|
}
|
|
@@ -55,18 +55,31 @@ function readSecurityClientConfigFromCookies(cookieHeader) {
|
|
|
55
55
|
if (!isSecurityClientConfig(parsed)) {
|
|
56
56
|
return void 0;
|
|
57
57
|
}
|
|
58
|
-
return
|
|
59
|
-
csrf: Object.freeze({
|
|
60
|
-
field: parsed.csrf.field,
|
|
61
|
-
cookie: parsed.csrf.cookie
|
|
62
|
-
})
|
|
63
|
-
});
|
|
58
|
+
return parsed;
|
|
64
59
|
} catch {
|
|
65
60
|
return void 0;
|
|
66
61
|
}
|
|
67
62
|
}
|
|
63
|
+
function readSecurityClientConfigFromCookies(cookieHeader) {
|
|
64
|
+
const parsed = parseSecurityClientConfig(parseCookieHeader(cookieHeader)[SECURITY_CLIENT_CONFIG_COOKIE]);
|
|
65
|
+
return parsed ? Object.freeze({
|
|
66
|
+
csrf: Object.freeze({
|
|
67
|
+
field: parsed.csrf.field,
|
|
68
|
+
cookie: parsed.csrf.cookie,
|
|
69
|
+
..."header" in parsed.csrf && typeof parsed.csrf.header === "string" ? { header: parsed.csrf.header } : {}
|
|
70
|
+
})
|
|
71
|
+
}) : void 0;
|
|
72
|
+
}
|
|
73
|
+
function getCsrfRequestHeaders(cookieHeader) {
|
|
74
|
+
const cookies = parseCookieHeader(cookieHeader);
|
|
75
|
+
const config = parseSecurityClientConfig(cookies[SECURITY_CLIENT_CONFIG_COOKIE]) ?? DEFAULT_SECURITY_CLIENT_CONFIG;
|
|
76
|
+
const token = cookies[config.csrf.cookie];
|
|
77
|
+
const header = "header" in config.csrf && typeof config.csrf.header === "string" ? config.csrf.header : "X-CSRF-TOKEN";
|
|
78
|
+
return token ? { [header]: token } : {};
|
|
79
|
+
}
|
|
68
80
|
var securityClientConfigInternals = {
|
|
69
|
-
parseCookieHeader
|
|
81
|
+
parseCookieHeader,
|
|
82
|
+
getCsrfRequestHeaders
|
|
70
83
|
};
|
|
71
84
|
|
|
72
85
|
export {
|
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare function readSecurityClientConfigFromCookies(cookieHeader: string | null
|
|
|
8
8
|
declare function getSecurityClientConfig(): SecurityClientConfig;
|
|
9
9
|
declare const securityClientInternals: {
|
|
10
10
|
parseCookieHeader: (header: string | null | undefined) => Readonly<Record<string, string>>;
|
|
11
|
+
getCsrfRequestHeaders: (cookieHeader: string | undefined) => Readonly<Record<string, string>>;
|
|
11
12
|
getDefaultSecurityClientConfig: typeof getDefaultSecurityClientConfig;
|
|
12
13
|
readSecurityClientConfigFromCookies: typeof readSecurityClientConfigFromCookies;
|
|
13
14
|
};
|
package/dist/client.mjs
CHANGED
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
getDefaultSecurityClientConfig,
|
|
3
3
|
readSecurityClientConfigFromCookies,
|
|
4
4
|
securityClientConfigInternals
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PC2YCWDH.mjs";
|
|
6
6
|
|
|
7
7
|
// src/client.ts
|
|
8
8
|
function getSecurityClientConfig() {
|
|
9
9
|
const runtime = globalThis;
|
|
10
|
-
|
|
10
|
+
const config = readSecurityClientConfigFromCookies(runtime.document?.cookie) ?? getDefaultSecurityClientConfig();
|
|
11
|
+
return Object.freeze({ csrf: Object.freeze({ field: config.csrf.field, cookie: config.csrf.cookie }) });
|
|
11
12
|
}
|
|
12
13
|
var securityClientInternals = {
|
|
13
14
|
getDefaultSecurityClientConfig,
|
package/dist/next/server.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prepareCsrfCookies
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-F32JK536.mjs";
|
|
4
4
|
import {
|
|
5
5
|
cors,
|
|
6
6
|
getSecurityRuntime,
|
|
7
7
|
protect
|
|
8
8
|
} from "../chunk-5SCCUNBO.mjs";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-PC2YCWDH.mjs";
|
|
10
10
|
import {
|
|
11
11
|
SecurityCsrfError
|
|
12
12
|
} from "../chunk-FQ4X7X6L.mjs";
|
package/dist/nuxt/server.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prepareCsrfCookies
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-F32JK536.mjs";
|
|
4
4
|
import {
|
|
5
5
|
cors,
|
|
6
6
|
protect
|
|
7
7
|
} from "../chunk-5SCCUNBO.mjs";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-PC2YCWDH.mjs";
|
|
9
9
|
import {
|
|
10
10
|
SecurityCsrfError
|
|
11
11
|
} from "../chunk-FQ4X7X6L.mjs";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
prepareCsrfCookies
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-F32JK536.mjs";
|
|
4
4
|
import {
|
|
5
5
|
cors,
|
|
6
6
|
protect
|
|
7
7
|
} from "../chunk-5SCCUNBO.mjs";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-PC2YCWDH.mjs";
|
|
9
9
|
import {
|
|
10
10
|
SecurityCsrfError
|
|
11
11
|
} from "../chunk-FQ4X7X6L.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/security",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
4
4
|
"description": "Holo-JS Framework - CSRF and rate-limit contracts, config, and runtime seams",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"test": "vitest --run --coverage"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@holo-js/config": "^0.3.
|
|
62
|
-
"@holo-js/kernel": "^0.3.
|
|
61
|
+
"@holo-js/config": "^0.3.22",
|
|
62
|
+
"@holo-js/kernel": "^0.3.22"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"h3": "^1.15.11",
|