authlet 0.1.0-beta.8 → 0.1.0-beta.9
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 +4 -1
- package/dist/seal.d.ts +5 -2
- package/dist/seal.js +19 -8
- package/dist/types.d.ts +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,7 +157,10 @@ authlet can't check these, because they happen in the app:
|
|
|
157
157
|
3. On the login page, only follow a `returnTo` that starts with a single `/`.
|
|
158
158
|
4. Use a session cookie with `SameSite=Lax` or stricter.
|
|
159
159
|
5. Use a random secret of at least 32 bytes, or a generated `CryptoKey`, and keep it out of source
|
|
160
|
-
control. Anyone with it can forge client IDs and consents
|
|
160
|
+
control. Anyone with it can forge client IDs and consents. To rotate, pass
|
|
161
|
+
`secret: [newSecret, oldSecret]` and drop the old one later. Refresh tokens move to the new
|
|
162
|
+
secret on their next refresh. Registered client IDs never do, so dropping the old secret makes
|
|
163
|
+
those clients register again. After a leak, drop it right away.
|
|
161
164
|
6. Derive a function-valued `resource` or `issuer` from trusted configuration only, never from
|
|
162
165
|
`Host` or `X-Forwarded-*` headers without an allowlist.
|
|
163
166
|
7. When `tokens.refresh` gets a `scope` array, mint the access token with exactly that scope and
|
package/dist/seal.d.ts
CHANGED
|
@@ -62,10 +62,13 @@ interface Sealer {
|
|
|
62
62
|
/** The sealed data, or `undefined` when the value is malformed, tampered, of another type or issuer, or expired. */
|
|
63
63
|
unseal: <K extends SealType>(args: UnsealArgs<K>) => Promise<SealedValues[K] | undefined>;
|
|
64
64
|
}
|
|
65
|
+
type Secret = string | CryptoKey;
|
|
65
66
|
/**
|
|
66
67
|
* Creates a sealer from a secret string (at least 32 characters, stretched with HKDF) or a
|
|
67
|
-
* 256-bit AES-GCM `CryptoKey` with the `encrypt` and `decrypt` usages.
|
|
68
|
+
* 256-bit AES-GCM `CryptoKey` with the `encrypt` and `decrypt` usages. A list seals with its
|
|
69
|
+
* first secret and unseals with any of them, so a new secret can be rolled out before the old
|
|
70
|
+
* one is dropped.
|
|
68
71
|
*/
|
|
69
|
-
declare const createSealer: (secret:
|
|
72
|
+
declare const createSealer: (secret: Secret | readonly Secret[]) => Sealer;
|
|
70
73
|
export { createSealer };
|
|
71
74
|
export type { Sealer, SealedValues };
|
package/dist/seal.js
CHANGED
|
@@ -25,11 +25,7 @@ const isSealingKey = (key) => key.algorithm.name === "AES-GCM" &&
|
|
|
25
25
|
key.algorithm.length === 256 &&
|
|
26
26
|
key.usages.includes("encrypt") &&
|
|
27
27
|
key.usages.includes("decrypt");
|
|
28
|
-
|
|
29
|
-
* Creates a sealer from a secret string (at least 32 characters, stretched with HKDF) or a
|
|
30
|
-
* 256-bit AES-GCM `CryptoKey` with the `encrypt` and `decrypt` usages.
|
|
31
|
-
*/
|
|
32
|
-
const createSealer = (secret) => {
|
|
28
|
+
const toKey = (secret) => {
|
|
33
29
|
// Checked here, not in deriveKey, so a bad secret fails at setup instead of as an unhandled rejection.
|
|
34
30
|
if (typeof secret === "string" && secret.length < MIN_SECRET_LENGTH) {
|
|
35
31
|
throw new Error(`The authlet secret must be at least ${String(MIN_SECRET_LENGTH)} characters long.`);
|
|
@@ -37,7 +33,22 @@ const createSealer = (secret) => {
|
|
|
37
33
|
if (typeof secret !== "string" && !isSealingKey(secret)) {
|
|
38
34
|
throw new Error("The authlet key must be a 256-bit AES-GCM CryptoKey with the encrypt and decrypt usages.");
|
|
39
35
|
}
|
|
40
|
-
|
|
36
|
+
return typeof secret === "string"
|
|
37
|
+
? deriveKey(secret)
|
|
38
|
+
: Promise.resolve(secret);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Creates a sealer from a secret string (at least 32 characters, stretched with HKDF) or a
|
|
42
|
+
* 256-bit AES-GCM `CryptoKey` with the `encrypt` and `decrypt` usages. A list seals with its
|
|
43
|
+
* first secret and unseals with any of them, so a new secret can be rolled out before the old
|
|
44
|
+
* one is dropped.
|
|
45
|
+
*/
|
|
46
|
+
const createSealer = (secret) => {
|
|
47
|
+
const keys = [secret].flat().map(toKey);
|
|
48
|
+
const [key] = keys;
|
|
49
|
+
if (!key) {
|
|
50
|
+
throw new Error("The authlet secret list must not be empty.");
|
|
51
|
+
}
|
|
41
52
|
return {
|
|
42
53
|
seal: async ({ issuer, type, data }) => {
|
|
43
54
|
const jwt = new EncryptJWT({ data })
|
|
@@ -59,13 +70,13 @@ const createSealer = (secret) => {
|
|
|
59
70
|
return undefined;
|
|
60
71
|
}
|
|
61
72
|
try {
|
|
62
|
-
const { payload } = await jwtDecrypt(value, await
|
|
73
|
+
const { payload } = await Promise.any(keys.map(async (candidate) => await jwtDecrypt(value, await candidate, {
|
|
63
74
|
issuer,
|
|
64
75
|
typ: typHeader(type),
|
|
65
76
|
clockTolerance: CLOCK_TOLERANCE,
|
|
66
77
|
keyManagementAlgorithms: ["dir"],
|
|
67
78
|
contentEncryptionAlgorithms: ["A256GCM"],
|
|
68
|
-
});
|
|
79
|
+
})));
|
|
69
80
|
return payload.data;
|
|
70
81
|
}
|
|
71
82
|
catch {
|
package/dist/types.d.ts
CHANGED
|
@@ -136,8 +136,13 @@ export interface AuthletOptions<TAuthorization = unknown, TUser extends AuthletU
|
|
|
136
136
|
* A relative URL stays relative in the `Location` header, so a proxy can't leak its own host.
|
|
137
137
|
*/
|
|
138
138
|
consentPage: Resolvable<string>;
|
|
139
|
-
/**
|
|
140
|
-
|
|
139
|
+
/**
|
|
140
|
+
* For the built-in AES-GCM sealer: at least 32 characters, or an AES-GCM `CryptoKey`. To
|
|
141
|
+
* rotate, pass `[newSecret, oldSecret]`: new values are sealed with the first, and any of
|
|
142
|
+
* them unseals. Refresh tokens move to the new secret on their next refresh, but registered
|
|
143
|
+
* client IDs never do, so dropping the old secret makes those clients register again.
|
|
144
|
+
*/
|
|
145
|
+
secret: string | CryptoKey | readonly (string | CryptoKey)[];
|
|
141
146
|
tokens: TokenHooks<TAuthorization, TUser>;
|
|
142
147
|
/**
|
|
143
148
|
* Enables Client ID Metadata Documents: an https `client_id` names a JSON document describing
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "authlet",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.9",
|
|
5
5
|
"description": "Stateless, runtime-agnostic OAuth 2.1 authorization server built on Web Request and Response.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"oauth",
|