@jskit-ai/auth-core 0.1.244 → 0.1.245
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/auth-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.245",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -135,6 +135,6 @@
|
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
"peerDependencies": {
|
|
138
|
-
"@jskit-ai/kernel": "0.1.
|
|
138
|
+
"@jskit-ai/kernel": "0.1.247"
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -13,6 +13,7 @@ function defaultHasPermission({ permission, permissions = [] } = {}) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function createPolicy({ authService, extensions, env }) {
|
|
16
|
+
const unsafeMethods = parseList(env.AUTH_CSRF_UNSAFE_METHODS);
|
|
16
17
|
return Object.freeze({
|
|
17
18
|
async resolveActor(request) {
|
|
18
19
|
if (authService && typeof authService.authenticateRequest === "function") {
|
|
@@ -27,7 +28,8 @@ function createPolicy({ authService, extensions, env }) {
|
|
|
27
28
|
options: Object.freeze({
|
|
28
29
|
nodeEnv: String(env.NODE_ENV || "development").trim() || "development",
|
|
29
30
|
apiPrefix: String(env.AUTH_API_PREFIX || "/api/").trim() || "/api/",
|
|
30
|
-
|
|
31
|
+
// Unset AUTH_CSRF_UNSAFE_METHODS keeps the plugin default (POST, PUT, PATCH, DELETE).
|
|
32
|
+
unsafeMethods: unsafeMethods.length > 0 ? Object.freeze(unsafeMethods) : undefined,
|
|
31
33
|
// Unset AUTH_CSRF_COOKIE_SECURE follows NODE_ENV (Secure in production).
|
|
32
34
|
csrfCookieOpts: Object.freeze(
|
|
33
35
|
String(env.AUTH_CSRF_COOKIE_SECURE ?? "").trim()
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
+
import Fastify from "fastify";
|
|
3
4
|
import { createActionProvider } from "@jskit-ai/kernel/server/actions";
|
|
4
5
|
import { createCapabilityRuntime, defineProvider } from "@jskit-ai/kernel/shared/capabilities";
|
|
5
6
|
import { HttpProvider } from "@jskit-ai/kernel/server/http";
|
|
@@ -126,3 +127,23 @@ test("auth policy denies protected routes when no auth service is installed", as
|
|
|
126
127
|
routeOptions: { config: { authPolicy: "required" } }
|
|
127
128
|
}, {}), /Authentication required/);
|
|
128
129
|
});
|
|
130
|
+
|
|
131
|
+
test("AuthPolicyProvider checks CSRF on unsafe methods when AUTH_CSRF_UNSAFE_METHODS is unset", async (t) => {
|
|
132
|
+
const app = Fastify();
|
|
133
|
+
t.after(() => app.close());
|
|
134
|
+
const runtime = createCapabilityRuntime({
|
|
135
|
+
inputs: runtimeInputs(app),
|
|
136
|
+
providers: [
|
|
137
|
+
createActionProvider(),
|
|
138
|
+
HttpProvider,
|
|
139
|
+
AuthExtensionsProvider,
|
|
140
|
+
AuthFeature,
|
|
141
|
+
AuthPolicyProvider
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
await runtime.start();
|
|
145
|
+
app.post("/api/write", { config: { authPolicy: "public" } }, () => ({ accepted: true }));
|
|
146
|
+
|
|
147
|
+
const missingToken = await app.inject({ method: "POST", url: "/api/write" });
|
|
148
|
+
assert.equal(missingToken.statusCode, 403);
|
|
149
|
+
});
|