@jskit-ai/auth-provider-local-core 0.1.145 → 0.1.147
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-provider-local-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.147",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@jskit-ai/auth-core": "0.1.
|
|
61
|
-
"@jskit-ai/kernel": "0.1.
|
|
60
|
+
"@jskit-ai/auth-core": "0.1.244",
|
|
61
|
+
"@jskit-ai/kernel": "0.1.246"
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
ensureDevAuthRuntimeAvailable,
|
|
13
13
|
resolveDevAuthPolicy
|
|
14
14
|
} from "@jskit-ai/auth-core/server/devAuth";
|
|
15
|
-
import { normalizeEmail } from "@jskit-ai/auth-core/server/utils";
|
|
15
|
+
import { hostOnlyCookieName, normalizeEmail } from "@jskit-ai/auth-core/server/utils";
|
|
16
16
|
import { throwUnsupportedAuthOperation } from "@jskit-ai/auth-core/server/unsupportedOperation";
|
|
17
17
|
import { normalizePasswordStrategy } from "./passwords.js";
|
|
18
18
|
import { randomToken, sha256Base64url, signToken, verifySignedToken } from "./tokens.js";
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const ACCESS_TOKEN_COOKIE_NAME = "jskit_local_access_token";
|
|
21
|
+
const REFRESH_TOKEN_COOKIE_NAME = "jskit_local_refresh_token";
|
|
22
|
+
const RECOVERY_TOKEN_COOKIE_NAME = "jskit_local_recovery_token";
|
|
23
23
|
const PROVIDER_ID = "local";
|
|
24
24
|
const DEV_AUTH_SESSION_PURPOSE = "dev-auth";
|
|
25
25
|
const ACCESS_TTL_SECONDS = 15 * 60;
|
|
@@ -278,6 +278,10 @@ function createLocalAuthService({
|
|
|
278
278
|
|
|
279
279
|
const passwords = normalizePasswordStrategy(passwordStrategy);
|
|
280
280
|
const isProduction = config.nodeEnv === "production";
|
|
281
|
+
// Production cookies are Secure, so they are also host-only __Host- cookies.
|
|
282
|
+
const ACCESS_TOKEN_COOKIE = hostOnlyCookieName(ACCESS_TOKEN_COOKIE_NAME, isProduction);
|
|
283
|
+
const REFRESH_TOKEN_COOKIE = hostOnlyCookieName(REFRESH_TOKEN_COOKIE_NAME, isProduction);
|
|
284
|
+
const RECOVERY_TOKEN_COOKIE = hostOnlyCookieName(RECOVERY_TOKEN_COOKIE_NAME, isProduction);
|
|
281
285
|
const devAuth = config.devAuth || resolveDevAuthPolicy({
|
|
282
286
|
nodeEnv: config.nodeEnv
|
|
283
287
|
});
|
|
@@ -571,9 +575,12 @@ function createLocalAuthService({
|
|
|
571
575
|
return;
|
|
572
576
|
}
|
|
573
577
|
for (const options of clearCookieOptions(isProduction)) {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
578
|
+
// A __Host- cookie only exists at Path=/.
|
|
579
|
+
if (options.path === "/" || !isProduction) {
|
|
580
|
+
reply.clearCookie(ACCESS_TOKEN_COOKIE, options);
|
|
581
|
+
reply.clearCookie(REFRESH_TOKEN_COOKIE, options);
|
|
582
|
+
reply.clearCookie(RECOVERY_TOKEN_COOKIE, options);
|
|
583
|
+
}
|
|
577
584
|
}
|
|
578
585
|
}
|
|
579
586
|
|
|
@@ -1150,6 +1150,28 @@ test("local file backend replays a pending multi-file transaction journal before
|
|
|
1150
1150
|
await assert.rejects(() => fs.stat(path.join(storeDir, "transaction.journal")), { code: "ENOENT" });
|
|
1151
1151
|
});
|
|
1152
1152
|
|
|
1153
|
+
test("production sessions use host-only __Host- cookies and ignore the old names", async (t) => {
|
|
1154
|
+
const app = await createStartedApp({
|
|
1155
|
+
env: { NODE_ENV: "production", AUTH_LOCAL_SESSION_SECRET: "fixture-session-secret" }
|
|
1156
|
+
});
|
|
1157
|
+
t.after(() => fs.rm(app.storeDir, { recursive: true, force: true }));
|
|
1158
|
+
const registered = await app.authService.register({ email: "host@example.com", password: "correct horse battery staple" });
|
|
1159
|
+
const reply = createReplyFixture();
|
|
1160
|
+
app.authService.writeSessionCookies(reply, registered.session);
|
|
1161
|
+
assert.deepEqual(Object.keys(reply.cookies).sort(), ["__Host-jskit_local_access_token", "__Host-jskit_local_refresh_token"]);
|
|
1162
|
+
for (const options of Object.values(reply.cookieOptions)) {
|
|
1163
|
+
assert.equal(options.secure, true);
|
|
1164
|
+
assert.equal(options.path, "/");
|
|
1165
|
+
assert.equal(options.domain, undefined);
|
|
1166
|
+
}
|
|
1167
|
+
assert.equal((await app.authService.authenticateRequest({ cookies: reply.cookies })).authenticated, true);
|
|
1168
|
+
const oldNames = {
|
|
1169
|
+
jskit_local_access_token: reply.cookies["__Host-jskit_local_access_token"],
|
|
1170
|
+
jskit_local_refresh_token: reply.cookies["__Host-jskit_local_refresh_token"]
|
|
1171
|
+
};
|
|
1172
|
+
assert.equal((await app.authService.authenticateRequest({ cookies: oldNames })).authenticated, false);
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1153
1175
|
test("local recovery uses the application sender without returning or logging its token", async (t) => {
|
|
1154
1176
|
const messages = [];
|
|
1155
1177
|
const logs = [];
|