@c9up/warden 0.2.4 → 0.2.6
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/README.md +70 -3
- package/dist/AccessToken.d.ts +257 -0
- package/dist/AccessToken.d.ts.map +1 -0
- package/dist/AccessToken.js +370 -0
- package/dist/AccessToken.js.map +1 -0
- package/dist/AttemptStore.d.ts +16 -2
- package/dist/AttemptStore.d.ts.map +1 -1
- package/dist/AttemptStore.js +26 -12
- package/dist/AttemptStore.js.map +1 -1
- package/dist/AuthManager.d.ts +33 -2
- package/dist/AuthManager.d.ts.map +1 -1
- package/dist/AuthManager.js +23 -2
- package/dist/AuthManager.js.map +1 -1
- package/dist/Authenticator.d.ts +19 -1
- package/dist/Authenticator.d.ts.map +1 -1
- package/dist/Authenticator.js +37 -3
- package/dist/Authenticator.js.map +1 -1
- package/dist/Guard.d.ts.map +1 -1
- package/dist/Guard.js +17 -5
- package/dist/Guard.js.map +1 -1
- package/dist/ResilientBlacklistDriver.d.ts +23 -6
- package/dist/ResilientBlacklistDriver.d.ts.map +1 -1
- package/dist/ResilientBlacklistDriver.js +24 -8
- package/dist/ResilientBlacklistDriver.js.map +1 -1
- package/dist/WardenProvider.d.ts +2 -0
- package/dist/WardenProvider.d.ts.map +1 -1
- package/dist/WardenProvider.js +4 -58
- package/dist/WardenProvider.js.map +1 -1
- package/dist/config.d.ts +8 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mfa/MfaManager.d.ts +16 -4
- package/dist/mfa/MfaManager.d.ts.map +1 -1
- package/dist/mfa/MfaManager.js +32 -6
- package/dist/mfa/MfaManager.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +27 -5
- package/dist/middleware.js.map +1 -1
- package/dist/native.d.ts +6 -2
- package/dist/native.d.ts.map +1 -1
- package/dist/native.js +19 -2
- package/dist/native.js.map +1 -1
- package/dist/quasar.d.ts.map +1 -1
- package/dist/quasar.js +8 -1
- package/dist/quasar.js.map +1 -1
- package/dist/standalone.d.ts +24 -3
- package/dist/standalone.d.ts.map +1 -1
- package/dist/standalone.js +21 -29
- package/dist/standalone.js.map +1 -1
- package/dist/strategies/ApiKeyStrategy.d.ts +45 -12
- package/dist/strategies/ApiKeyStrategy.d.ts.map +1 -1
- package/dist/strategies/ApiKeyStrategy.js +71 -37
- package/dist/strategies/ApiKeyStrategy.js.map +1 -1
- package/dist/strategies/JwtStrategy.d.ts.map +1 -1
- package/dist/strategies/JwtStrategy.js +3 -3
- package/dist/strategies/JwtStrategy.js.map +1 -1
- package/dist/strategies/SessionStrategy.d.ts +48 -1
- package/dist/strategies/SessionStrategy.d.ts.map +1 -1
- package/dist/strategies/SessionStrategy.js +70 -4
- package/dist/strategies/SessionStrategy.js.map +1 -1
- package/dist/templateTags.d.ts +42 -0
- package/dist/templateTags.d.ts.map +1 -0
- package/dist/templateTags.js +82 -0
- package/dist/templateTags.js.map +1 -0
- package/dist/vendor/nativeBinary.d.ts +26 -2
- package/dist/vendor/nativeBinary.d.ts.map +1 -1
- package/dist/vendor/nativeBinary.js +63 -6
- package/dist/vendor/nativeBinary.js.map +1 -1
- package/dist/vendor/quasarConnection.d.ts +26 -3
- package/dist/vendor/quasarConnection.d.ts.map +1 -1
- package/dist/vendor/quasarConnection.js +44 -23
- package/dist/vendor/quasarConnection.js.map +1 -1
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +8 -3
- package/src/AccessToken.ts +550 -0
- package/src/AttemptStore.ts +29 -13
- package/src/AuthManager.ts +40 -2
- package/src/Authenticator.ts +39 -3
- package/src/Guard.ts +18 -5
- package/src/ResilientBlacklistDriver.ts +28 -8
- package/src/WardenProvider.ts +6 -83
- package/src/config.ts +8 -4
- package/src/index.ts +18 -0
- package/src/mfa/MfaManager.ts +39 -6
- package/src/middleware.ts +36 -5
- package/src/native.ts +20 -4
- package/src/quasar.ts +13 -2
- package/src/standalone.ts +74 -33
- package/src/strategies/ApiKeyStrategy.ts +112 -42
- package/src/strategies/JwtStrategy.ts +3 -1
- package/src/strategies/SessionStrategy.ts +121 -4
- package/src/templateTags.ts +117 -0
- package/src/vendor/nativeBinary.ts +82 -6
- package/src/vendor/quasarConnection.ts +84 -22
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Access-tokens authentication strategy (opaque API tokens).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Reads the token from `Authorization: Bearer <token>` or the configured
|
|
5
|
+
* header (`x-api-key` by default), verifies it through an access-tokens
|
|
6
|
+
* provider — which stores only a hash, compares in constant time and checks
|
|
7
|
+
* expiry — then loads the user it belongs to.
|
|
8
|
+
*
|
|
9
|
+
* The token's abilities stay ON THE TOKEN: the user is handed to the request
|
|
10
|
+
* with `currentAccessToken`, and a handler asks it
|
|
11
|
+
* (`ctx.auth.user.currentAccessToken.allows('orders:write')`). They are never
|
|
12
|
+
* merged into `user.permissions`, which holds the user's own permissions: a
|
|
13
|
+
* token whose ability happened to share a permission's name would otherwise
|
|
14
|
+
* grant that permission to a user who does not hold it, and a token restricted
|
|
15
|
+
* to a few abilities would still carry every permission of its user. Warden's
|
|
16
|
+
* permission checks (`@Permission`, `hasPermission`) require both: the user's
|
|
17
|
+
* permission AND the token's ability (`tokenAllows`).
|
|
5
18
|
*
|
|
6
19
|
* @implements MISS-8
|
|
7
20
|
*/
|
|
21
|
+
import type { AccessToken, AccessTokensProviderContract, CreateAccessTokenOptions, TokenOwner } from "../AccessToken.js";
|
|
8
22
|
import type { AuthClientResponse, AuthResult, AuthStrategy, UserPayload } from "../AuthManager.js";
|
|
9
23
|
export interface ApiKeyConfig {
|
|
24
|
+
/** Header read beside `Authorization: Bearer`. Default `x-api-key`. */
|
|
10
25
|
headerName?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Verifies a presented token and mints new ones — an
|
|
28
|
+
* `AccessTokensProvider` over the application's token table, or the
|
|
29
|
+
* application's own implementation of the contract.
|
|
30
|
+
*/
|
|
31
|
+
tokens: AccessTokensProviderContract;
|
|
32
|
+
/**
|
|
33
|
+
* Load the user a verified token belongs to. Called on every request, so a
|
|
34
|
+
* token whose account was deleted or disabled stops working: answer `null`
|
|
35
|
+
* and the request is refused.
|
|
36
|
+
*/
|
|
37
|
+
findUser: (id: string | number) => Promise<UserPayload | null>;
|
|
15
38
|
}
|
|
16
39
|
export declare class ApiKeyStrategy implements AuthStrategy {
|
|
17
40
|
#private;
|
|
@@ -24,14 +47,24 @@ export declare class ApiKeyStrategy implements AuthStrategy {
|
|
|
24
47
|
password: string;
|
|
25
48
|
}): Promise<AuthResult>;
|
|
26
49
|
/**
|
|
27
|
-
*
|
|
28
|
-
* `
|
|
50
|
+
* Mint a token for `user` through the provider. The returned token carries
|
|
51
|
+
* `value` this once: hand it to the client now.
|
|
52
|
+
*/
|
|
53
|
+
createToken(user: TokenOwner, abilities?: string[], options?: CreateAccessTokenOptions): Promise<AccessToken>;
|
|
54
|
+
/**
|
|
55
|
+
* Revoke the token behind `value`. Answers whether it existed.
|
|
29
56
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
57
|
+
* NAMED DEVIATION — upstream's guard is built per request and revokes the
|
|
58
|
+
* token it authenticated with, so it takes no argument. A warden strategy
|
|
59
|
+
* is shared by every request and keeps none of them, so the value is passed
|
|
60
|
+
* in; a sign-out handler has it, it is the request's credential.
|
|
61
|
+
*/
|
|
62
|
+
invalidateToken(value: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* What a test client sends to be `user`: a real token, minted through the
|
|
65
|
+
* provider, so the test authenticates the way the application will.
|
|
33
66
|
*/
|
|
34
|
-
authenticateAsClient(
|
|
67
|
+
authenticateAsClient(user: TokenOwner, abilities?: string[], options?: CreateAccessTokenOptions): Promise<AuthClientResponse>;
|
|
35
68
|
verify(token: string): Promise<AuthResult>;
|
|
36
69
|
}
|
|
37
70
|
//# sourceMappingURL=ApiKeyStrategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyStrategy.d.ts","sourceRoot":"","sources":["../../src/strategies/ApiKeyStrategy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ApiKeyStrategy.d.ts","sourceRoot":"","sources":["../../src/strategies/ApiKeyStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACX,WAAW,EACX,4BAA4B,EAC5B,wBAAwB,EACxB,UAAU,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACX,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,MAAM,mBAAmB,CAAC;AAI3B,MAAM,WAAW,YAAY;IAC5B,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,MAAM,EAAE,4BAA4B,CAAC;IACrC;;;;OAIG;IACH,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CAC/D;AAED,qBAAa,cAAe,YAAW,YAAY;;IAIlD,IAAI,SAAmB;gBAIX,MAAM,EAAE,YAAY;IAuBhC,wDAAwD;IACxD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAEK,YAAY,CAAC,YAAY,EAAE;QAChC,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,CAAC;IAMvB;;;OAGG;IACH,WAAW,CACV,IAAI,EAAE,UAAU,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,OAAO,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,WAAW,CAAC;IAIvB;;;;;;;OAOG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIhD;;;OAGG;IACG,oBAAoB,CACzB,IAAI,EAAE,UAAU,EAChB,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,OAAO,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAYxB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAmBhD"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Access-tokens authentication strategy (opaque API tokens).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Reads the token from `Authorization: Bearer <token>` or the configured
|
|
5
|
+
* header (`x-api-key` by default), verifies it through an access-tokens
|
|
6
|
+
* provider — which stores only a hash, compares in constant time and checks
|
|
7
|
+
* expiry — then loads the user it belongs to.
|
|
8
|
+
*
|
|
9
|
+
* The token's abilities stay ON THE TOKEN: the user is handed to the request
|
|
10
|
+
* with `currentAccessToken`, and a handler asks it
|
|
11
|
+
* (`ctx.auth.user.currentAccessToken.allows('orders:write')`). They are never
|
|
12
|
+
* merged into `user.permissions`, which holds the user's own permissions: a
|
|
13
|
+
* token whose ability happened to share a permission's name would otherwise
|
|
14
|
+
* grant that permission to a user who does not hold it, and a token restricted
|
|
15
|
+
* to a few abilities would still carry every permission of its user. Warden's
|
|
16
|
+
* permission checks (`@Permission`, `hasPermission`) require both: the user's
|
|
17
|
+
* permission AND the token's ability (`tokenAllows`).
|
|
5
18
|
*
|
|
6
19
|
* @implements MISS-8
|
|
7
20
|
*/
|
|
21
|
+
import { WardenError } from "../errors.js";
|
|
22
|
+
import { Secret } from "../Secret.js";
|
|
8
23
|
export class ApiKeyStrategy {
|
|
9
24
|
// AdonisJS names this guard driver "access_tokens". The legacy "api-key"
|
|
10
25
|
// spelling is still accepted as a guard name / credential trigger by the
|
|
@@ -13,6 +28,17 @@ export class ApiKeyStrategy {
|
|
|
13
28
|
#config;
|
|
14
29
|
#headerName;
|
|
15
30
|
constructor(config) {
|
|
31
|
+
// A config written for the earlier `findByKey` shape has no provider:
|
|
32
|
+
// refused at boot rather than at the first request.
|
|
33
|
+
const tokens = Reflect.get(Object(config), "tokens");
|
|
34
|
+
if (typeof Reflect.get(Object(tokens), "verify") !== "function") {
|
|
35
|
+
throw new WardenError("INVALID_CONFIG", "The access-tokens guard needs `tokens`, a provider that verifies hashed tokens.", {
|
|
36
|
+
hint: "apiKeyGuard({ tokens: new AccessTokensProvider({ store }), findUser: (id) => User.find(id) })",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (typeof config.findUser !== "function") {
|
|
40
|
+
throw new WardenError("INVALID_CONFIG", "The access-tokens guard needs `findUser`, to load the user a token belongs to.");
|
|
41
|
+
}
|
|
16
42
|
this.#config = config;
|
|
17
43
|
this.#headerName = config.headerName ?? "x-api-key";
|
|
18
44
|
}
|
|
@@ -21,48 +47,56 @@ export class ApiKeyStrategy {
|
|
|
21
47
|
return this.#headerName;
|
|
22
48
|
}
|
|
23
49
|
async authenticate(_credentials) {
|
|
24
|
-
throw new Error("ApiKeyStrategy does not support credential-based auth. Use verify() with the
|
|
50
|
+
throw new Error("ApiKeyStrategy does not support credential-based auth. Use verify() with the access token.");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Mint a token for `user` through the provider. The returned token carries
|
|
54
|
+
* `value` this once: hand it to the client now.
|
|
55
|
+
*/
|
|
56
|
+
createToken(user, abilities, options) {
|
|
57
|
+
return this.#config.tokens.create(user, abilities, options);
|
|
25
58
|
}
|
|
26
59
|
/**
|
|
27
|
-
*
|
|
28
|
-
* `authenticateAsClient`).
|
|
60
|
+
* Revoke the token behind `value`. Answers whether it existed.
|
|
29
61
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
62
|
+
* NAMED DEVIATION — upstream's guard is built per request and revokes the
|
|
63
|
+
* token it authenticated with, so it takes no argument. A warden strategy
|
|
64
|
+
* is shared by every request and keeps none of them, so the value is passed
|
|
65
|
+
* in; a sign-out handler has it, it is the request's credential.
|
|
33
66
|
*/
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
invalidateToken(value) {
|
|
68
|
+
return this.#config.tokens.invalidate(new Secret(value));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* What a test client sends to be `user`: a real token, minted through the
|
|
72
|
+
* provider, so the test authenticates the way the application will.
|
|
73
|
+
*/
|
|
74
|
+
async authenticateAsClient(user, abilities, options) {
|
|
75
|
+
const token = await this.createToken(user, abilities, options);
|
|
76
|
+
const value = token.value?.release();
|
|
77
|
+
if (value === undefined) {
|
|
78
|
+
throw new WardenError("INVALID_CONFIG", "The token provider returned a token without its value from create().");
|
|
79
|
+
}
|
|
80
|
+
return { headers: { authorization: `Bearer ${value}` } };
|
|
41
81
|
}
|
|
42
82
|
async verify(token) {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
return { authenticated: false, error: "Invalid
|
|
46
|
-
const user = { ...result.user };
|
|
47
|
-
if (result.scopes && result.scopes.length > 0) {
|
|
48
|
-
// Expose the API key's scopes on `user.permissions` (without mutating
|
|
49
|
-
// the source object) so APP code can read them via
|
|
50
|
-
// `ctx.auth.user.permissions`.
|
|
51
|
-
//
|
|
52
|
-
// IMPORTANT — these scopes are a SEPARATE axis from the `@Permission`
|
|
53
|
-
// route gate, by design (Adonis Bouncer parity): the gate flows through
|
|
54
|
-
// RightsResolver, which resolves grants from the rights STORE and
|
|
55
|
-
// deliberately ignores payload-carried permissions (see RightsResolver
|
|
56
|
-
// D1). This mirrors AdonisJS, where token abilities are checked via
|
|
57
|
-
// `currentAccessToken.allows(scope)` and are NOT consulted by Bouncer
|
|
58
|
-
// ability/policy checks. So an API key carrying `orders.create` is NOT
|
|
59
|
-
// auto-granted by `@Permission('orders.create')` — that's intentional,
|
|
60
|
-
// not a bug. Gate API-key routes on scopes with an explicit app-level
|
|
61
|
-
// check against `ctx.auth.user.permissions`.
|
|
62
|
-
const merged = new Set([...(user.permissions ?? []), ...result.scopes]);
|
|
63
|
-
user.permissions = [...merged];
|
|
83
|
+
const accessToken = await this.#config.tokens.verify(new Secret(token));
|
|
84
|
+
if (accessToken === null) {
|
|
85
|
+
return { authenticated: false, error: "Invalid access token" };
|
|
64
86
|
}
|
|
65
|
-
|
|
87
|
+
const user = await this.#config.findUser(accessToken.tokenableId);
|
|
88
|
+
if (!user) {
|
|
89
|
+
return {
|
|
90
|
+
authenticated: false,
|
|
91
|
+
error: "The account behind this token is no longer available",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// A copy: the provider's object is the application's, and attaching the
|
|
95
|
+
// token to it would leak one request's token into the next.
|
|
96
|
+
return {
|
|
97
|
+
authenticated: true,
|
|
98
|
+
user: { ...user, currentAccessToken: accessToken },
|
|
99
|
+
};
|
|
66
100
|
}
|
|
67
101
|
}
|
|
68
102
|
//# sourceMappingURL=ApiKeyStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiKeyStrategy.js","sourceRoot":"","sources":["../../src/strategies/ApiKeyStrategy.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ApiKeyStrategy.js","sourceRoot":"","sources":["../../src/strategies/ApiKeyStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAcH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAmBtC,MAAM,OAAO,c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"}
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
6
6
|
import { resolveExpiresInSeconds } from "../duration.js";
|
|
7
|
-
import { nativeWarden } from "../native.js";
|
|
7
|
+
import { nativeWarden, nativeWardenLoadError } from "../native.js";
|
|
8
8
|
function sign(payload, secret) {
|
|
9
9
|
const rust = nativeWarden();
|
|
10
10
|
if (!rust) {
|
|
11
|
-
throw new Error("[E_WARDEN_NAPI_REQUIRED] The Rust warden-engine binary is required. Build it with `cd packages/warden && pnpm build:napi`.");
|
|
11
|
+
throw new Error("[E_WARDEN_NAPI_REQUIRED] The Rust warden-engine binary is required. Build it with `cd packages/warden && pnpm build:napi`.", { cause: nativeWardenLoadError() });
|
|
12
12
|
}
|
|
13
13
|
return rust.jwtSign(JSON.stringify(payload), secret);
|
|
14
14
|
}
|
|
15
15
|
function verify(token, secret) {
|
|
16
16
|
const rust = nativeWarden();
|
|
17
17
|
if (!rust) {
|
|
18
|
-
throw new Error("[E_WARDEN_NAPI_REQUIRED] The Rust warden-engine binary is required. Build it with `cd packages/warden && pnpm build:napi`.");
|
|
18
|
+
throw new Error("[E_WARDEN_NAPI_REQUIRED] The Rust warden-engine binary is required. Build it with `cd packages/warden && pnpm build:napi`.", { cause: nativeWardenLoadError() });
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
const payloadJson = rust.jwtVerify(token, secret);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtStrategy.js","sourceRoot":"","sources":["../../src/strategies/JwtStrategy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOtD,OAAO,EAAE,uBAAuB,EAAsB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"JwtStrategy.js","source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C,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9C,EACD,IAAI,CAAC,OAAO,CACZ,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH;;;;;;;OAOG;IACH,oBAAoB,CAAC,IAAiB;QACrC,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;IACzE,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACd,0HAA0H,CAC1H,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;QACjC,IAAI,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE;YAAE,OAAO,KAAK,CAAC;QACtC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,MAAM,UAAU,iBAAiB;IAChC,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { AuthClientResponse, AuthResult, AuthStrategy, UserPayload } from "../AuthManager.js";
|
|
10
10
|
import { type RememberMeTokenDriver } from "../RememberMeToken.js";
|
|
11
|
+
import type { TokenBlacklist } from "../TokenBlacklist.js";
|
|
11
12
|
export interface SessionStore {
|
|
12
13
|
get(key: string): unknown;
|
|
13
14
|
/**
|
|
@@ -26,6 +27,20 @@ export interface SessionStore {
|
|
|
26
27
|
* directly so this is wired automatically.
|
|
27
28
|
*/
|
|
28
29
|
regenerate(): void;
|
|
30
|
+
/**
|
|
31
|
+
* The session's lifetime in seconds, which a revocation has to outlast.
|
|
32
|
+
* Ream's `Session` carries it; another store may leave it out and set
|
|
33
|
+
* `sessionAge` instead.
|
|
34
|
+
*/
|
|
35
|
+
readonly config?: {
|
|
36
|
+
readonly ttl: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Whether ending the session on the server ends every copy of it. Ream's
|
|
40
|
+
* `Session` answers `false` under the cookie store; a store that leaves it
|
|
41
|
+
* out is taken to keep its sessions on the server.
|
|
42
|
+
*/
|
|
43
|
+
readonly revocable?: boolean;
|
|
29
44
|
}
|
|
30
45
|
export interface SessionStrategyConfig {
|
|
31
46
|
sessionKey?: string;
|
|
@@ -53,6 +68,32 @@ export interface SessionStrategyConfig {
|
|
|
53
68
|
* rides a cross-site POST unless the app says so here.
|
|
54
69
|
*/
|
|
55
70
|
rememberMeCookie?: RememberMeCookieAttributes;
|
|
71
|
+
/**
|
|
72
|
+
* Revoke each sign-in at logout, as `JwtStrategy`'s `blacklist` revokes a
|
|
73
|
+
* token: every login gets an id, logout lists it until every copy of the
|
|
74
|
+
* session has expired, and a session carrying a listed id is signed out.
|
|
75
|
+
*
|
|
76
|
+
* What makes a logout hold under the COOKIE session driver, where the
|
|
77
|
+
* session lives in the browser and nothing on the server can delete it — a
|
|
78
|
+
* copy taken before the logout, or a request that was running across it and
|
|
79
|
+
* re-sent the signed-in cookie after, would otherwise be signed in still.
|
|
80
|
+
* The server-side drivers do not need it: logout rotates the session id and
|
|
81
|
+
* a request still in flight cannot write the old entry back.
|
|
82
|
+
*
|
|
83
|
+
* NAMED DEVIATION: upstream's session guard has no revocation; its cookie
|
|
84
|
+
* store has both holes.
|
|
85
|
+
*/
|
|
86
|
+
blacklist?: TokenBlacklist;
|
|
87
|
+
/**
|
|
88
|
+
* Session lifetime in SECONDS, when the session does not carry it (Ream's
|
|
89
|
+
* does). A revocation is kept for twice this, so it outlives the cookie a
|
|
90
|
+
* request running across the logout re-issued: Ream's cookie store dates
|
|
91
|
+
* that cookie from when the request read the session, so it ends within one
|
|
92
|
+
* lifetime of the logout, however long the request ran. A store that dated
|
|
93
|
+
* it from the response would need a listing kept as long as its slowest
|
|
94
|
+
* request.
|
|
95
|
+
*/
|
|
96
|
+
sessionAge?: number;
|
|
56
97
|
}
|
|
57
98
|
/** What an app may set on the remember-me cookie. */
|
|
58
99
|
export interface RememberMeCookieAttributes {
|
|
@@ -170,7 +211,13 @@ export declare class SessionStrategy implements AuthStrategy {
|
|
|
170
211
|
*/
|
|
171
212
|
authenticateAsClient(user: UserPayload): AuthClientResponse;
|
|
172
213
|
/**
|
|
173
|
-
* Logout — remove the user id from the session.
|
|
214
|
+
* Logout — remove the user id from the session, and rotate its id.
|
|
215
|
+
*
|
|
216
|
+
* Rotating is the named deviation (upstream only forgets the key): the old
|
|
217
|
+
* id is what a request still running holds, and with the old entry gone it
|
|
218
|
+
* has nothing to write its signed-in copy back to. A copy of the old id
|
|
219
|
+
* points at nothing either. With a `blacklist`, the sign-in is also listed,
|
|
220
|
+
* which is what holds under the cookie driver.
|
|
174
221
|
*
|
|
175
222
|
* The remember-me token is revoked separately through
|
|
176
223
|
* {@link revokeRememberMeToken}, because only the caller holds the cookie.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionStrategy.d.ts","sourceRoot":"","sources":["../../src/strategies/SessionStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"SessionStrategy.d.ts","sourceRoot":"","sources":["../../src/strategies/SessionStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACX,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,WAAW,EACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAGN,KAAK,qBAAqB,EAE1B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CAAC,EAAE,YAAY,CAAA;KAAE,GACnC,OAAO,CAAC,UAAU,CAAC;IAgBtB,8DAA8D;IACxD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAQjD,2EAA2E;IACrE,iBAAiB,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,YAAY,CAAA;KAAE,GAClC,OAAO,CAAC,UAAU,CAAC;IAsBtB;;;;;;;;;OASG;IACH;;;;;;;OAOG;IACH,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAqB3D;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAkCtC,KAAK,CACV,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;OAMG;IACH,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB;IAS3D;;;;;;;;;;;OAWG;IACG,MAAM,CACX,OAAO,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC;CAiBhB"}
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @implements MISS-7
|
|
8
8
|
*/
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
9
10
|
import { WardenError } from "../errors.js";
|
|
10
11
|
import { decodeTokenValue, mintRememberMeToken, verifyAndRecycleRememberMeToken, } from "../RememberMeToken.js";
|
|
12
|
+
/** Ream's default session lifetime, two hours. */
|
|
13
|
+
const DEFAULT_SESSION_AGE_SECONDS = 7200;
|
|
11
14
|
/** Two years, Adonis' `rememberMeTokensAge` default. */
|
|
12
15
|
const DEFAULT_REMEMBER_AGE_SECONDS = 63_072_000;
|
|
13
16
|
/** A fresh set of per-request flags, all false. */
|
|
@@ -29,6 +32,11 @@ export class SessionStrategy {
|
|
|
29
32
|
if (age !== undefined && (!Number.isSafeInteger(age) || age <= 0)) {
|
|
30
33
|
throw new WardenError("INVALID_CONFIG", `rememberMeAge must be a positive whole number of seconds, got ${String(age)}`);
|
|
31
34
|
}
|
|
35
|
+
const sessionAge = config.sessionAge;
|
|
36
|
+
if (sessionAge !== undefined &&
|
|
37
|
+
(!Number.isSafeInteger(sessionAge) || sessionAge <= 0)) {
|
|
38
|
+
throw new WardenError("INVALID_CONFIG", `sessionAge must be a positive whole number of seconds, got ${String(sessionAge)}`);
|
|
39
|
+
}
|
|
32
40
|
this.#config = config;
|
|
33
41
|
this.#sessionKey = config.sessionKey ?? "auth_user_id";
|
|
34
42
|
}
|
|
@@ -136,6 +144,12 @@ export class SessionStrategy {
|
|
|
136
144
|
return { authenticated: false, error: "No session user" };
|
|
137
145
|
if (typeof userId !== "string" && typeof userId !== "number")
|
|
138
146
|
return { authenticated: false, error: "Invalid session data" };
|
|
147
|
+
if (await this.#revoked(context.session)) {
|
|
148
|
+
// Forgotten, not just refused: a cookie session re-sent as it came in
|
|
149
|
+
// would carry the revoked sign-in on, and outlive its listing.
|
|
150
|
+
this.#unseat(context.session);
|
|
151
|
+
return { authenticated: false, error: "Session revoked" };
|
|
152
|
+
}
|
|
139
153
|
const user = await this.#config.findUser(userId);
|
|
140
154
|
if (!user)
|
|
141
155
|
return { authenticated: false, error: "User not found" };
|
|
@@ -165,8 +179,18 @@ export class SessionStrategy {
|
|
|
165
179
|
* exists to report.
|
|
166
180
|
*/
|
|
167
181
|
seatSession(user, session) {
|
|
182
|
+
if (session.revocable === false && !this.#config.blacklist) {
|
|
183
|
+
// Refused rather than signed in: on this store a logout could never
|
|
184
|
+
// hold — a copy of the cookie, or one re-sent by a request running
|
|
185
|
+
// across the logout, would stay signed in until it expired.
|
|
186
|
+
throw new WardenError("INVALID_CONFIG", "This session store keeps the session in the browser and cannot revoke a sign-in. Give the session guard a `blacklist`, or use a server-side session store (database, redis).", {
|
|
187
|
+
hint: "new SessionStrategy({ findUser, blacklist: new TokenBlacklist(new RedisBlacklistDriver(client)) })",
|
|
188
|
+
});
|
|
189
|
+
}
|
|
168
190
|
session.regenerate();
|
|
169
191
|
session.put(this.#sessionKey, user.id);
|
|
192
|
+
// What a logout revokes: one sign-in, not the user's every device.
|
|
193
|
+
session.put(this.#signInKey(), randomUUID());
|
|
170
194
|
// A new sign-in has not stepped up yet, whatever the session held before.
|
|
171
195
|
session.forget(this.#mfaKey());
|
|
172
196
|
}
|
|
@@ -182,6 +206,30 @@ export class SessionStrategy {
|
|
|
182
206
|
#mfaKey() {
|
|
183
207
|
return `${this.#sessionKey}_mfa`;
|
|
184
208
|
}
|
|
209
|
+
/** The session key of this sign-in's id, which a logout revokes. */
|
|
210
|
+
#signInKey() {
|
|
211
|
+
return `${this.#sessionKey}_sid`;
|
|
212
|
+
}
|
|
213
|
+
/** Drop every key a sign-in wrote. */
|
|
214
|
+
#unseat(session) {
|
|
215
|
+
session.forget(this.#sessionKey);
|
|
216
|
+
session.forget(this.#mfaKey());
|
|
217
|
+
session.forget(this.#signInKey());
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Whether the blacklist refuses this session's sign-in. A session with no
|
|
221
|
+
* sign-in id is refused too, as `JwtStrategy` refuses a token with no `jti`:
|
|
222
|
+
* it could never be revoked, so letting it through would keep the hole open.
|
|
223
|
+
*/
|
|
224
|
+
async #revoked(session) {
|
|
225
|
+
const blacklist = this.#config.blacklist;
|
|
226
|
+
if (!blacklist)
|
|
227
|
+
return false;
|
|
228
|
+
const signIn = session.get(this.#signInKey());
|
|
229
|
+
if (typeof signIn !== "string" || signIn.length === 0)
|
|
230
|
+
return true;
|
|
231
|
+
return blacklist.isRevoked(signIn);
|
|
232
|
+
}
|
|
185
233
|
async login(user, session, state) {
|
|
186
234
|
this.seatSession(user, session);
|
|
187
235
|
if (state) {
|
|
@@ -201,17 +249,35 @@ export class SessionStrategy {
|
|
|
201
249
|
* the guard's own logic rather than by the test knowing where the id lives.
|
|
202
250
|
*/
|
|
203
251
|
authenticateAsClient(user) {
|
|
204
|
-
return {
|
|
252
|
+
return {
|
|
253
|
+
session: {
|
|
254
|
+
[this.#sessionKey]: user.id,
|
|
255
|
+
[this.#signInKey()]: randomUUID(),
|
|
256
|
+
},
|
|
257
|
+
};
|
|
205
258
|
}
|
|
206
259
|
/**
|
|
207
|
-
* Logout — remove the user id from the session.
|
|
260
|
+
* Logout — remove the user id from the session, and rotate its id.
|
|
261
|
+
*
|
|
262
|
+
* Rotating is the named deviation (upstream only forgets the key): the old
|
|
263
|
+
* id is what a request still running holds, and with the old entry gone it
|
|
264
|
+
* has nothing to write its signed-in copy back to. A copy of the old id
|
|
265
|
+
* points at nothing either. With a `blacklist`, the sign-in is also listed,
|
|
266
|
+
* which is what holds under the cookie driver.
|
|
208
267
|
*
|
|
209
268
|
* The remember-me token is revoked separately through
|
|
210
269
|
* {@link revokeRememberMeToken}, because only the caller holds the cookie.
|
|
211
270
|
*/
|
|
212
271
|
async logout(session, state) {
|
|
213
|
-
session.
|
|
214
|
-
|
|
272
|
+
const signIn = session.get(this.#signInKey());
|
|
273
|
+
if (this.#config.blacklist && typeof signIn === "string") {
|
|
274
|
+
const age = session.config?.ttl ??
|
|
275
|
+
this.#config.sessionAge ??
|
|
276
|
+
DEFAULT_SESSION_AGE_SECONDS;
|
|
277
|
+
await this.#config.blacklist.revoke(signIn, Date.now() + age * 2000);
|
|
278
|
+
}
|
|
279
|
+
this.#unseat(session);
|
|
280
|
+
session.regenerate();
|
|
215
281
|
if (state) {
|
|
216
282
|
state.viaRemember = false;
|
|
217
283
|
state.attemptedViaRemember = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SessionStrategy.js","sourceRoot":"","sources":["../../src/strategies/SessionStrategy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"SessionStrategy.js","sourceRoot":"","sources":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AC,OAAO,CAAC,UAAU;gBACvB,2BAA2B,CAAC;YAC7B,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,CAAC,UAAU,EAAE,CAAC;QACrB,IAAI,KAAK,EAAE,CAAC;YACX,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;YAC1B,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC;YACnC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** The only surface warden needs of a template engine. */
|
|
2
|
+
export interface TemplateEngineLike {
|
|
3
|
+
registerTag(tag: {
|
|
4
|
+
tagName: string;
|
|
5
|
+
block: boolean;
|
|
6
|
+
seekable: boolean;
|
|
7
|
+
compile(parser: unknown, buffer: {
|
|
8
|
+
writeRaw(text: string): void;
|
|
9
|
+
}, token: {
|
|
10
|
+
properties: {
|
|
11
|
+
jsArg: string;
|
|
12
|
+
};
|
|
13
|
+
renderBody(): string | Promise<string>;
|
|
14
|
+
evaluate(expression: string): unknown;
|
|
15
|
+
}): void | Promise<void>;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Register `@can` / `@cannot`, as AdonisJS's bouncer publishes them. A
|
|
20
|
+
* migrated template keeps `@can('PostPolicy.edit', post) … @endcan` unchanged.
|
|
21
|
+
*
|
|
22
|
+
* Both are BLOCK tags and both AWAIT — the check returns a promise — so they
|
|
23
|
+
* render on the async path and raise on a synchronous one, matching upstream
|
|
24
|
+
* (which emits `await bouncer.can(...)`). The checks themselves come from
|
|
25
|
+
* `ctx.bouncer.templateHelpers`, shared into the view per request.
|
|
26
|
+
*/
|
|
27
|
+
export declare function registerBouncerTemplateTags(engine: TemplateEngineLike): void;
|
|
28
|
+
/** Loads the template engine package. Swappable so a test needs no engine. */
|
|
29
|
+
export type EnginePackageLoader = () => Promise<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Publish the bouncer tags the way AdonisJS's bouncer does with Edge: through
|
|
32
|
+
* the engine package's MODULE SINGLETON (`inker.use(plugin)`), guarded by the
|
|
33
|
+
* host's `usingInker` flag — never by resolving a container binding. `use()`
|
|
34
|
+
* queues the plugin and the engine runs it before its next render, whenever
|
|
35
|
+
* the engine was built.
|
|
36
|
+
*
|
|
37
|
+
* Returns whether the tags were handed over. A registrar or an engine of the
|
|
38
|
+
* wrong shape is an error, not a skip: an unregistered `@can` would render as
|
|
39
|
+
* plain text and show the guarded body's markup to everyone.
|
|
40
|
+
*/
|
|
41
|
+
export declare function installBouncerTemplateTags(usingInker: boolean, load?: EnginePackageLoader): Promise<boolean>;
|
|
42
|
+
//# sourceMappingURL=templateTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateTags.d.ts","sourceRoot":"","sources":["../src/templateTags.ts"],"names":[],"mappings":"AAEA,0DAA0D;AAC1D,MAAM,WAAW,kBAAkB;IAClC,WAAW,CAAC,GAAG,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,CACN,MAAM,EAAE,OAAO,EACf,MAAM,EAAE;YAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,EACxC,KAAK,EAAE;YACN,UAAU,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAA;aAAE,CAAC;YAC9B,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;YACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;SACtC,GACC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACxB,GAAG,IAAI,CAAC;CACT;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CA0B5E;AAED,8EAA8E;AAC9E,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAqBzD;;;;;;;;;;GAUG;AACH,wBAAsB,0BAA0B,CAC/C,UAAU,EAAE,OAAO,EACnB,IAAI,GAAE,mBAA+B,GACnC,OAAO,CAAC,OAAO,CAAC,CAuBlB"}
|