@holo-js/security 0.4.0 → 0.4.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
6a69c91a7956903d7fa9f7964081444dd1c5af67194c62e15bf118c6567eaf76
|
|
@@ -41,26 +41,6 @@ async function prepareCsrfCookies(request, getCookie) {
|
|
|
41
41
|
}
|
|
42
42
|
return { token, cookies, sessionCookies };
|
|
43
43
|
}
|
|
44
|
-
function appendSetCookies(response, setCookies) {
|
|
45
|
-
if (setCookies.length === 0) {
|
|
46
|
-
return response;
|
|
47
|
-
}
|
|
48
|
-
const headers = new Headers();
|
|
49
|
-
for (const setCookie of setCookies) {
|
|
50
|
-
headers.append("Set-Cookie", setCookie);
|
|
51
|
-
}
|
|
52
|
-
response.headers.forEach((value, name) => {
|
|
53
|
-
if (name !== "set-cookie") headers.append(name, value);
|
|
54
|
-
});
|
|
55
|
-
for (const setCookie of response.headers.getSetCookie()) {
|
|
56
|
-
headers.append("Set-Cookie", setCookie);
|
|
57
|
-
}
|
|
58
|
-
return new Response(response.body, {
|
|
59
|
-
status: response.status,
|
|
60
|
-
statusText: response.statusText,
|
|
61
|
-
headers
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
44
|
|
|
65
45
|
// src/rejection-response.ts
|
|
66
46
|
import { HoloRequestBodyTooLargeError, HoloRequestUrlError } from "@holo-js/kernel";
|
|
@@ -78,7 +58,6 @@ function createSecurityRejectionResponse(error) {
|
|
|
78
58
|
|
|
79
59
|
export {
|
|
80
60
|
prepareCsrfCookies,
|
|
81
|
-
appendSetCookies,
|
|
82
61
|
isSecurityRejection,
|
|
83
62
|
createSecurityRejectionResponse
|
|
84
63
|
};
|
package/dist/next/server.mjs
CHANGED
package/dist/nuxt/server.mjs
CHANGED
|
@@ -28,7 +28,7 @@ type SvelteKitCsrfHandleInput<TEvent extends SvelteKitCsrfEvent = SvelteKitCsrfE
|
|
|
28
28
|
readonly resolve: (event: TEvent, options?: SvelteKitResolveOptions) => Response | Promise<Response>;
|
|
29
29
|
};
|
|
30
30
|
type SvelteKitCsrfHandle = <TEvent extends SvelteKitCsrfEvent>(input: SvelteKitCsrfHandleInput<TEvent>) => Response | Promise<Response>;
|
|
31
|
-
declare function issueCsrfCookie(event: SvelteKitCsrfEvent): Promise<
|
|
31
|
+
declare function issueCsrfCookie(event: SvelteKitCsrfEvent): Promise<void>;
|
|
32
32
|
declare function csrfProtection(): SvelteKitCsrfHandle;
|
|
33
33
|
declare const svelteKitSecurityInternals: {
|
|
34
34
|
issueCsrfCookie: typeof issueCsrfCookie;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
appendSetCookies,
|
|
3
2
|
createSecurityRejectionResponse,
|
|
4
3
|
isSecurityRejection,
|
|
5
4
|
prepareCsrfCookies
|
|
6
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-EN2H3TN3.mjs";
|
|
7
6
|
import {
|
|
8
7
|
cors,
|
|
9
8
|
protect
|
|
@@ -13,12 +12,17 @@ import "../chunk-U25HSHLJ.mjs";
|
|
|
13
12
|
import "../chunk-D3ZN5MLJ.mjs";
|
|
14
13
|
|
|
15
14
|
// src/sveltekit/server.ts
|
|
15
|
+
import { responseCookieInternals } from "@holo-js/kernel";
|
|
16
16
|
async function issueCsrfCookie(event) {
|
|
17
17
|
const { cookies, sessionCookies } = await prepareCsrfCookies(event.request, (name) => event.cookies.get(name));
|
|
18
18
|
for (const cookie of cookies) {
|
|
19
19
|
event.cookies.set(cookie.name, cookie.value, cookie.options);
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
for (const sessionCookie of sessionCookies) {
|
|
22
|
+
const parsed = responseCookieInternals.parseResponseCookie(sessionCookie);
|
|
23
|
+
if (!parsed) throw new Error("[@holo-js/security] The CSRF session cookie could not be parsed.");
|
|
24
|
+
event.cookies.set(parsed.name, parsed.value, parsed.options);
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
27
|
function csrfProtection() {
|
|
24
28
|
return async ({ event, resolve }) => {
|
|
@@ -30,17 +34,16 @@ function csrfProtection() {
|
|
|
30
34
|
headers: { Allow: "GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE" }
|
|
31
35
|
});
|
|
32
36
|
}
|
|
33
|
-
let sessionCookies;
|
|
34
37
|
try {
|
|
35
38
|
await protect(event.request);
|
|
36
|
-
|
|
39
|
+
await issueCsrfCookie(event);
|
|
37
40
|
} catch (error) {
|
|
38
41
|
if (isSecurityRejection(error)) {
|
|
39
42
|
return cors.apply(event.request, createSecurityRejectionResponse(error));
|
|
40
43
|
}
|
|
41
44
|
throw error;
|
|
42
45
|
}
|
|
43
|
-
return
|
|
46
|
+
return cors.apply(event.request, await resolve(event));
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
var svelteKitSecurityInternals = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/security",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Holo-JS Framework - CSRF and rate-limit contracts, config, and runtime seams",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"test": "vitest --run --coverage"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@holo-js/config": "^0.4.
|
|
68
|
-
"@holo-js/kernel": "^0.4.
|
|
67
|
+
"@holo-js/config": "^0.4.1",
|
|
68
|
+
"@holo-js/kernel": "^0.4.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"h3": "^1.15.11",
|