@softure-ai/auth 0.1.7 → 0.1.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/CHANGELOG.md +17 -0
- package/README.md +71 -4
- package/dist/index.js +1 -1
- package/dist/next/actions.d.ts +9 -2
- package/dist/next/actions.d.ts.map +1 -1
- package/dist/next/actions.js +15 -3
- package/dist/next/actions.js.map +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/next/logout-button.d.ts +3 -1
- package/dist/next/logout-button.d.ts.map +1 -1
- package/dist/next/logout-button.js +4 -4
- package/dist/next/logout-button.js.map +1 -1
- package/dist/proxy/index.d.ts +6 -0
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +35 -2
- package/dist/proxy/index.js.map +1 -1
- package/dist/scripts/temporary-password.d.ts +5 -1
- package/dist/scripts/temporary-password.d.ts.map +1 -1
- package/dist/scripts/temporary-password.js +30 -18
- package/dist/scripts/temporary-password.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +2 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/password.d.ts +2 -0
- package/dist/server/password.d.ts.map +1 -1
- package/dist/server/password.js +13 -5
- package/dist/server/password.js.map +1 -1
- package/dist/server/temporary-password.d.ts +14 -0
- package/dist/server/temporary-password.d.ts.map +1 -0
- package/dist/server/temporary-password.js +26 -0
- package/dist/server/temporary-password.js.map +1 -0
- package/module.json +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/next/actions.ts +21 -3
- package/src/next/index.ts +1 -0
- package/src/next/logout-button.tsx +5 -2
- package/src/proxy/index.ts +43 -2
- package/src/scripts/temporary-password.ts +37 -19
- package/src/server/index.ts +2 -1
- package/src/server/password.ts +15 -5
- package/src/server/temporary-password.ts +36 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ Newest first. Each version lists what changed for an app that uses `@softure-ai/
|
|
|
4
4
|
production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
|
|
5
5
|
"Definition of done"). Versions before the first one below are described in their GitHub Releases (`auth@x.y.z`).
|
|
6
6
|
|
|
7
|
+
## 0.1.9
|
|
8
|
+
|
|
9
|
+
- `set-temporary-password` takes `--password-hash=<hash>` (or `--password-hash-file=-` from stdin): the script stores a
|
|
10
|
+
hash computed elsewhere instead of drawing a password, so the plain password never reaches the server. The report
|
|
11
|
+
then says `passwordFrom: "hash"`; a value that is not a module hash is a usage error and is never printed.
|
|
12
|
+
- `createSetTemporaryPasswordScript(config, { alphabet })` chooses the characters of a drawn password.
|
|
13
|
+
- `createTemporaryPassword({ alphabet, length })`, `READABLE_PASSWORD_ALPHABET` (no `0/O`, `1/l/I`, `-`, `_`) and
|
|
14
|
+
`isPasswordHash(value)` are exported from `@softure-ai/auth/server` for the operator's local half.
|
|
15
|
+
|
|
16
|
+
## 0.1.8
|
|
17
|
+
|
|
18
|
+
- `logoutAction({ next })`, a `next` form field and `<LogoutButton next>` choose where logout goes; the path is
|
|
19
|
+
checked like login's `next` and falls back to `routes.afterLogout`.
|
|
20
|
+
- `createAuthGuard({ trustedOrigins })` keeps the login redirect on the request's public origin when it is listed;
|
|
21
|
+
without the option the redirect stays on `appOrigin`.
|
|
22
|
+
- README: when to set `cookie.secure` explicitly, and the Vitest `server.deps.inline` setting the `/next` entry needs.
|
|
23
|
+
|
|
7
24
|
## 0.1.7
|
|
8
25
|
|
|
9
26
|
- `module.json` names `mailing` and `ops` as optional dependencies.
|
package/README.md
CHANGED
|
@@ -30,6 +30,20 @@ Peer dependencies: `next` 16, `react` 19, `drizzle-orm`; optional: `@softure-ai/
|
|
|
30
30
|
`@softure-ai/auth/mailing`, `@softure-ai/ops` for `@softure-ai/auth/scripts`. No other entry
|
|
31
31
|
imports them.
|
|
32
32
|
|
|
33
|
+
**Unit tests with Vitest.** `@softure-ai/auth/next` imports `next/headers`, `next/navigation` and
|
|
34
|
+
`next/server` without a file extension. Next's bundler resolves only those bare specifiers (the `.js`
|
|
35
|
+
form bypasses its per-runtime aliases and breaks `next build`), but Next has no `exports` map, so plain
|
|
36
|
+
Node ESM cannot resolve them: a Vitest test that imports the entry fails with
|
|
37
|
+
`Cannot find module '…/node_modules/next/headers'`. Let Vitest process the package instead of Node:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// vitest.config.mts
|
|
41
|
+
export default defineConfig({ test: { server: { deps: { inline: [/@softure-ai\//] } } } });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The pattern covers every `@softure-ai/*` package; the other modules' `/next` entries import Next the
|
|
45
|
+
same way.
|
|
46
|
+
|
|
33
47
|
## 3. Configuration
|
|
34
48
|
|
|
35
49
|
```ts
|
|
@@ -67,7 +81,7 @@ export default config;
|
|
|
67
81
|
| `session.ttlDays` | `number` (1-365) | `30` | Session lifetime from login. It is not extended by use. |
|
|
68
82
|
| `cookie.name` | `string` | `"softure_session"` | Base name of the session cookie (see below). |
|
|
69
83
|
| `cookie.domain` | `string` | none (host-only) | Share the session with subdomains, e.g. `example.com` for the apex and `app.example.com`. |
|
|
70
|
-
| `cookie.secure` | `boolean` | `appOrigin` is https | Send the cookie over HTTPS only. |
|
|
84
|
+
| `cookie.secure` | `boolean` | `appOrigin` is https | Send the cookie over HTTPS only. Set it explicitly when one build serves both HTTPS and plain HTTP (see below). |
|
|
71
85
|
| `requireConsent` | `boolean` | `true` | Registration needs the consent checkbox. |
|
|
72
86
|
| `registrationFields` | `string[]` | `[]` | Extra register form fields handed to `onRegistered` as `event.fields` (section 10). Names: `a-z` first, then letters, digits or `_`, at most 32; not `email`, `password`, `next` or `consent`. |
|
|
73
87
|
| `legacySession` | `{ cookieName, tokenPattern }` | none | Sessions of the system the app took over (section 5, "Adopting existing sessions"). |
|
|
@@ -83,7 +97,12 @@ export default config;
|
|
|
83
97
|
|
|
84
98
|
**Cookie.** Always `HttpOnly`, `SameSite=Lax`, `Path=/`, `Max-Age` = the TTL. A secure cookie gets
|
|
85
99
|
the prefix browsers enforce: `__Host-softure_session` when it is host-only, `__Secure-softure_session`
|
|
86
|
-
with `cookie.domain`. Over plain HTTP (local development) it keeps the bare name.
|
|
100
|
+
with `cookie.domain`. Over plain HTTP (local development) it keeps the bare name. Without
|
|
101
|
+
`cookie.secure` the choice follows `appOrigin`'s scheme, read once from the config: an image built
|
|
102
|
+
with an `https:` origin and run over plain HTTP (a test stack on the production image) sets a
|
|
103
|
+
`__Host-` cookie the browser refuses, so no login sticks. Set `cookie.secure` from the deploy instead,
|
|
104
|
+
e.g. `cookie: { secure: process.env.ALLOW_INSECURE_COOKIES !== "true" }` with the variable set on
|
|
105
|
+
that stack only.
|
|
87
106
|
|
|
88
107
|
**Rate limits** (`AUTH_RATE_LIMIT_BUCKETS`, configured in `security`): `register` 5 and `login` 50
|
|
89
108
|
per client address, `login-account` 10 per email, `change-password` 10 per user,
|
|
@@ -156,6 +175,11 @@ export default async function AccountPage() {
|
|
|
156
175
|
}
|
|
157
176
|
```
|
|
158
177
|
|
|
178
|
+
`<LogoutButton next="/login?next=…" />` (or `logoutAction({ next })` from the app's own action)
|
|
179
|
+
ends the session and goes to that path instead of `afterLogout`, e.g. a consent screen's "sign in as
|
|
180
|
+
someone else" returning to the same authorization request after the new login. The path is checked
|
|
181
|
+
like login's `next`: anything but a path on this app falls back to `afterLogout`.
|
|
182
|
+
|
|
159
183
|
`requireUser({ next: "/account" })` brings the user back after login; `getCurrentUser()` returns
|
|
160
184
|
the user or `null`. Both read the session once per request. The redirect to login goes through the
|
|
161
185
|
app's `rewriteRedirect` (options table); a page outside the proxy's guard passes its own search
|
|
@@ -198,7 +222,22 @@ export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)
|
|
|
198
222
|
Next's `config`.)
|
|
199
223
|
|
|
200
224
|
A protected prefix matches whole path segments (`/account` covers `/account/password`, not
|
|
201
|
-
`/accounting`). The change-password route is always protected. Redirects are built on `appOrigin
|
|
225
|
+
`/accounting`). The change-password route is always protected. Redirects are built on `appOrigin`,
|
|
226
|
+
because behind a reverse proxy the request URL carries the server's internal host.
|
|
227
|
+
|
|
228
|
+
An app served on several hosts from one build (the product on `app.example.com`, pages on
|
|
229
|
+
`example.com`) lists the others in `trustedOrigins`, so a visitor is sent to the login page on the
|
|
230
|
+
host they used:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
const guard = createAuthGuard(softureConfig, { protect: ["/account"], trustedOrigins: ["https://example.com"] });
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The guard reads the request's public origin from `X-Forwarded-Proto` and `X-Forwarded-Host` (first
|
|
237
|
+
values), else from `Host` and the URL's scheme, and uses it only when it equals a listed origin
|
|
238
|
+
(scheme, host and port); any other request goes to `appOrigin`. Headers alone can therefore never
|
|
239
|
+
send a visitor to a host the app did not list. An entry that is not an `http(s)` origin throws when
|
|
240
|
+
the guard is created. A session cookie shared by the hosts needs `cookie.domain`.
|
|
202
241
|
|
|
203
242
|
An app that is private by default protects `"/"` and lists its public paths in `exclude`, which is
|
|
204
243
|
checked first:
|
|
@@ -280,7 +319,35 @@ process.exitCode = await runOpsScript({ script: createSetTemporaryPasswordScript
|
|
|
280
319
|
`node set-temporary-password.mjs --email=owner@example.com` shows what it would end and rolls back
|
|
281
320
|
(the printed password is not stored); `--commit` writes and prints the password to hand over. Send
|
|
282
321
|
it only to the account's own address, and ask the owner to change it after logging in: the module
|
|
283
|
-
does not force a change.
|
|
322
|
+
does not force a change. `createSetTemporaryPasswordScript(config, { alphabet: READABLE_PASSWORD_ALPHABET })`
|
|
323
|
+
draws the password from 57 letters and digits without `0/O`, `1/l/I`, `-` and `_`, for a password
|
|
324
|
+
someone dictates or types from a mail.
|
|
325
|
+
|
|
326
|
+
To keep the plain password off the server, make it and its hash on your own machine and give the
|
|
327
|
+
script only the hash. `createTemporaryPassword({ alphabet, length })`, `hashPassword` and
|
|
328
|
+
`getAuthOptions` come from `@softure-ai/auth/server`; with a given hash the length rule is yours, so
|
|
329
|
+
use at least `password.minLength` and 20:
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
// scripts/temporary-password-hash.ts, run locally
|
|
333
|
+
import { createTemporaryPassword, getAuthOptions, hashPassword, READABLE_PASSWORD_ALPHABET } from "@softure-ai/auth/server";
|
|
334
|
+
import config from "../softure.config";
|
|
335
|
+
|
|
336
|
+
const { password } = getAuthOptions(config);
|
|
337
|
+
const plain = createTemporaryPassword({ alphabet: READABLE_PASSWORD_ALPHABET, length: Math.max(password.minLength, 20) });
|
|
338
|
+
console.error(`password to hand over: ${plain}`);
|
|
339
|
+
console.log(await hashPassword(plain, password.scrypt));
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
```sh
|
|
343
|
+
node temporary-password-hash.mjs | ssh app-host docker exec -i app node set-temporary-password.mjs --email=owner@example.com --password-hash-file=- --commit
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`--password-hash-file=-` reads the hash from stdin (`--password-hash=<hash>` works too, but lands in
|
|
347
|
+
shell history). The script refuses a value that is not a `hashPassword` hash without printing it,
|
|
348
|
+
stores the hash, ends the sessions and the reset link as before, and reports `passwordFrom: "hash"`
|
|
349
|
+
instead of a password. A hash made with other scrypt parameters than the config's is rehashed at
|
|
350
|
+
the first login. `isPasswordHash(value)` checks the format locally.
|
|
284
351
|
|
|
285
352
|
**Password reset.** Pass a sender, and the login form links to the request page. With
|
|
286
353
|
`@softure-ai/mailing` enabled, `mailingResetSender()` is that sender:
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
|
|
|
36
36
|
export const auth = defineModule({
|
|
37
37
|
manifest: {
|
|
38
38
|
id: MODULE_ID,
|
|
39
|
-
version: "0.1.
|
|
39
|
+
version: "0.1.9",
|
|
40
40
|
dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
|
|
41
41
|
dbSchema: "auth",
|
|
42
42
|
tables: ["users", "sessions", "user_roles", "password_resets"],
|
package/dist/next/actions.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export declare function forgotPasswordAction(_previous: AuthFormState, formData:
|
|
|
14
14
|
* and its token is used by then.
|
|
15
15
|
*/
|
|
16
16
|
export declare function resetPasswordAction(_previous: AuthFormState, formData: FormData): Promise<AuthFormState>;
|
|
17
|
-
/**
|
|
18
|
-
export
|
|
17
|
+
/** Where to go after logout: a path on this app, checked like login's `next`. */
|
|
18
|
+
export interface LogoutInput {
|
|
19
|
+
readonly next?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Ends the request's sessions and goes to `next` (a form field or `{ next }`, e.g. `/login?next=…` to
|
|
23
|
+
* sign in as someone else), else to `afterLogout`. The cookies are cleared even if the delete fails.
|
|
24
|
+
*/
|
|
25
|
+
export declare function logoutAction(input?: FormData | LogoutInput): Promise<void>;
|
|
19
26
|
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAoC,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA8EtF,wBAAsB,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAiBtG;AAED,wBAAsB,cAAc,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAwBzG;AAED,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAgB/G;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAuB/G;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAkB9G;AAmBD
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAoC,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA8EtF,wBAAsB,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAiBtG;AAED,wBAAsB,cAAc,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAwBzG;AAED,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAgB/G;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAuB/G;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,CAkB9G;AAmBD,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhF"}
|
package/dist/next/actions.js
CHANGED
|
@@ -214,9 +214,21 @@ async function endPreviousSession(config) {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
// Any client can call the action with any serializable value: only a `next` string counts.
|
|
218
|
+
const logoutInput = z.object({ next: nextPath }).catch({ next: "" });
|
|
219
|
+
/** The `next` of a posted form or of an object; anything else is no target. */
|
|
220
|
+
function readLogoutNext(input) {
|
|
221
|
+
if (input instanceof FormData)
|
|
222
|
+
return logoutInput.parse({ next: input.get("next") }).next;
|
|
223
|
+
return logoutInput.parse(input).next;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Ends the request's sessions and goes to `next` (a form field or `{ next }`, e.g. `/login?next=…` to
|
|
227
|
+
* sign in as someone else), else to `afterLogout`. The cookies are cleared even if the delete fails.
|
|
228
|
+
*/
|
|
229
|
+
export async function logoutAction(input) {
|
|
219
230
|
const config = getSoftureConfig();
|
|
231
|
+
const target = toSafeNextPath(readLogoutNext(input), getAuthRoutes(config).afterLogout);
|
|
220
232
|
for (const token of await readHeldTokens(config)) {
|
|
221
233
|
try {
|
|
222
234
|
await logoutSession(await getAuthContext(config), token);
|
|
@@ -226,6 +238,6 @@ export async function logoutAction() {
|
|
|
226
238
|
}
|
|
227
239
|
}
|
|
228
240
|
await clearSessionCookie(config);
|
|
229
|
-
redirect(await resolveRedirectTarget(config,
|
|
241
|
+
redirect(await resolveRedirectTarget(config, target));
|
|
230
242
|
}
|
|
231
243
|
//# sourceMappingURL=actions.js.map
|
package/dist/next/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/next/actions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,6FAA6F;AAC7F,gGAAgG;AAChG,uFAAuF;AACvF,iGAAiG;AACjG,sEAAsE;AACtE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAsB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAA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Y,QAAQ;QAAE,OAAO,WAAW,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;IAC1F,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAA8B;IAC/D,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC;IACxF,KAAK,MAAM,KAAK,IAAI,MAAM,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,aAAa,CAAC,MAAM,cAAc,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACjC,QAAQ,CAAC,MAAM,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { changePasswordAction, forgotPasswordAction, loginAction, logoutAction, registerAction, resetPasswordAction, } from "./actions.js";
|
|
1
|
+
export { changePasswordAction, forgotPasswordAction, loginAction, logoutAction, type LogoutInput, registerAction, resetPasswordAction, } from "./actions.js";
|
|
2
2
|
export { authorizeRole, getCurrentUser, getCurrentUserRoles, hasRole, requireRole, requireUser, type RequireUserOptions, } from "./current-user.js";
|
|
3
3
|
export { LogoutButton, type LogoutButtonProps } from "./logout-button.js";
|
|
4
4
|
export { getAuthMessages } from "./messages.js";
|
package/dist/next/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,WAAW,EACX,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,KAAK,WAAW,EAChB,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,WAAW,EACX,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,KAAK,aAAa,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,KAAK,mBAAmB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/next/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,8GAA8G;AAC9G,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,8GAA8G;AAC9G,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EAEZ,cAAc,EACd,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAA0B,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,YAAY,EAEZ,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -2,6 +2,8 @@ import { type ButtonVariant } from "@softure-ai/ui";
|
|
|
2
2
|
export interface LogoutButtonProps {
|
|
3
3
|
readonly variant?: ButtonVariant;
|
|
4
4
|
readonly className?: string;
|
|
5
|
+
/** Where to go after logout (a path on this app), e.g. `/login?next=…`; default `afterLogout`. */
|
|
6
|
+
readonly next?: string;
|
|
5
7
|
}
|
|
6
|
-
export declare function LogoutButton({ variant, className }: LogoutButtonProps): import("react").JSX.Element;
|
|
8
|
+
export declare function LogoutButton({ variant, className, next }: LogoutButtonProps): import("react").JSX.Element;
|
|
7
9
|
//# sourceMappingURL=logout-button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout-button.d.ts","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI5D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"logout-button.d.ts","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAI5D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,kGAAkG;IAClG,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,EAAE,OAAqB,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,iBAAiB,+BAUzF"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// A logout button for the app's own pages: a plain form posting to `logoutAction`, so it works
|
|
3
|
-
// without JavaScript. Server component.
|
|
3
|
+
// without JavaScript. Server component. `next` rides along as a hidden field.
|
|
4
4
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
5
5
|
import { Button } from "@softure-ai/ui";
|
|
6
6
|
import { logoutAction } from "./actions.js";
|
|
7
7
|
import { getAuthMessages } from "./messages.js";
|
|
8
|
-
export function LogoutButton({ variant = "secondary", className }) {
|
|
8
|
+
export function LogoutButton({ variant = "secondary", className, next }) {
|
|
9
9
|
const messages = getAuthMessages(getSoftureConfig());
|
|
10
|
-
return (
|
|
10
|
+
return (_jsxs("form", { action: logoutAction, className: className, children: [next === undefined ? null : _jsx("input", { type: "hidden", name: "next", value: next }), _jsx(Button, { type: "submit", variant: variant, children: messages.logout.submit })] }));
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=logout-button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logout-button.js","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"logout-button.js","sourceRoot":"","sources":["../../src/next/logout-button.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,8EAA8E;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAShD,MAAM,UAAU,YAAY,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,SAAS,EAAE,IAAI,EAAqB;IACxF,MAAM,QAAQ,GAAG,eAAe,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACrD,OAAO,CACL,gBAAM,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,aAC7C,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,MAAM,EAAC,KAAK,EAAE,IAAI,GAAI,EAC7E,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,YACnC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAChB,IACJ,CACR,CAAC;AACJ,CAAC"}
|
package/dist/proxy/index.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface AuthGuardOptions {
|
|
|
7
7
|
* public pages here). `"/"` here is the home page only. The change-password route stays guarded.
|
|
8
8
|
*/
|
|
9
9
|
readonly exclude?: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* Origins besides `appOrigin` that the login redirect may stay on (`https://example.com`), for an app
|
|
12
|
+
* served on several hosts. The request's public origin (`X-Forwarded-Proto` / `X-Forwarded-Host`,
|
|
13
|
+
* else `Host` and the URL's scheme) is used only when it is listed; any other goes to `appOrigin`.
|
|
14
|
+
*/
|
|
15
|
+
readonly trustedOrigins?: readonly string[];
|
|
10
16
|
}
|
|
11
17
|
export type AuthGuard = (request: Request) => Response | null;
|
|
12
18
|
/** A guard that redirects to the login page (with `?next=`) for protected paths without a session cookie. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItD,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAItD,MAAM,WAAW,gBAAgB;IAC/B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAKD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;AAE9D,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAiC3F"}
|
package/dist/proxy/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export function createAuthGuard(config, options) {
|
|
|
11
11
|
// Auth's own public pages: guarding them would send a visitor from the login page to itself.
|
|
12
12
|
const publicPaths = [routes.login, routes.register, routes.forgotPassword, routes.resetPassword, SESSION_ROUTE].map((path) => normalizePrefix(path, "excluded"));
|
|
13
13
|
const excluded = (options.exclude ?? []).map((prefix) => normalizePrefix(prefix, "excluded"));
|
|
14
|
+
const trustedOrigins = new Set((options.trustedOrigins ?? []).map(normalizeOrigin));
|
|
14
15
|
const isGuarded = (path) => {
|
|
15
16
|
if (isUnder(path, changePassword))
|
|
16
17
|
return true;
|
|
@@ -28,8 +29,10 @@ export function createAuthGuard(config, options) {
|
|
|
28
29
|
const cookieHeader = request.headers.get("cookie");
|
|
29
30
|
if (cookieNames.some((name) => readSessionToken(cookieHeader, name) !== null))
|
|
30
31
|
return null;
|
|
31
|
-
// Built on appOrigin
|
|
32
|
-
|
|
32
|
+
// Built on appOrigin, or on the request's public origin when the app trusts it: behind a proxy
|
|
33
|
+
// the request URL carries an internal host, and request headers alone are never trusted.
|
|
34
|
+
const origin = findPublicOrigin(request, url);
|
|
35
|
+
const login = new URL(routes.login, origin !== null && trustedOrigins.has(origin) ? origin : config.appOrigin);
|
|
33
36
|
login.searchParams.set("next", `${url.pathname}${url.search}`);
|
|
34
37
|
return Response.redirect(login, 307);
|
|
35
38
|
};
|
|
@@ -41,6 +44,36 @@ function normalizePrefix(prefix, kind) {
|
|
|
41
44
|
const trimmed = prefix.length > 1 && prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
42
45
|
return trimmed.toLowerCase();
|
|
43
46
|
}
|
|
47
|
+
/** `entry` as an origin (`https://example.com`, a trailing `/` dropped); anything else is a config error. */
|
|
48
|
+
function normalizeOrigin(entry) {
|
|
49
|
+
const parsed = parseOrigin(entry.endsWith("/") ? entry.slice(0, -1) : entry);
|
|
50
|
+
if (parsed === null) {
|
|
51
|
+
throw new Error(`createAuthGuard: trusted origin "${entry}" must be an http(s) origin such as https://example.com`);
|
|
52
|
+
}
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
/** The origin the browser used: the front proxy's forwarded scheme and host, else `Host` and the URL's scheme. */
|
|
56
|
+
function findPublicOrigin(request, url) {
|
|
57
|
+
const host = firstValue(request.headers.get("x-forwarded-host")) ?? firstValue(request.headers.get("host")) ?? url.host;
|
|
58
|
+
const scheme = firstValue(request.headers.get("x-forwarded-proto")) ?? url.protocol.slice(0, -1);
|
|
59
|
+
return parseOrigin(`${scheme}://${host}`);
|
|
60
|
+
}
|
|
61
|
+
function firstValue(header) {
|
|
62
|
+
const value = header?.split(",")[0]?.trim();
|
|
63
|
+
return value === undefined || value === "" ? null : value;
|
|
64
|
+
}
|
|
65
|
+
/** The normalized origin of `candidate` when it is exactly `http(s)://host[:port]`, else null. */
|
|
66
|
+
function parseOrigin(candidate) {
|
|
67
|
+
// Checked on the raw text, so a path, query, fragment or credentials make it no origin.
|
|
68
|
+
if (!/^https?:\/\/[^/\\?#@\s]+$/i.test(candidate))
|
|
69
|
+
return null;
|
|
70
|
+
try {
|
|
71
|
+
return new URL(candidate).origin;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
44
77
|
function decodePath(pathname) {
|
|
45
78
|
try {
|
|
46
79
|
return decodeURIComponent(pathname).toLowerCase();
|
package/dist/proxy/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proxy/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAkB1E,+GAA+G;AAC/G,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAI1C,6GAA6G;AAC7G,MAAM,UAAU,eAAe,CAAC,MAAqB,EAAE,OAAyB;IAC9E,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC3I,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACvF,MAAM,cAAc,GAAG,eAAe,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3E,6FAA6F;IAC7F,MAAM,WAAW,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC3H,eA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;AAED,SAAS,UAAU,CAAC,QAAgB;IAClC,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,6FAA6F;AAC7F,SAAS,YAAY,CAAC,QAAgB,EAAE,MAAc;IACpD,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,OAAO,CAAC,QAAgB,EAAE,MAAc;IAC/C,OAAO,MAAM,KAAK,GAAG,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -2,11 +2,15 @@ import { type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
|
2
2
|
import { type OpsScript } from "@softure-ai/ops/scripts";
|
|
3
3
|
export interface TemporaryPasswordScriptArgs {
|
|
4
4
|
readonly email: string;
|
|
5
|
+
/** A hash from `hashPassword`, computed where the password was made; the script then draws none. */
|
|
6
|
+
readonly "password-hash"?: string;
|
|
5
7
|
}
|
|
6
8
|
export interface TemporaryPasswordScriptOptions {
|
|
7
9
|
/** The time stored as `password_changed_at`; the system clock by default. */
|
|
8
10
|
readonly clock?: Clock;
|
|
11
|
+
/** The characters a drawn password uses (e.g. `READABLE_PASSWORD_ALPHABET`); base64url by default. */
|
|
12
|
+
readonly alphabet?: string;
|
|
9
13
|
}
|
|
10
|
-
/** `set-temporary-password --email
|
|
14
|
+
/** `set-temporary-password --email=… [--password-hash=…]`: a new password, every session and reset link ended. */
|
|
11
15
|
export declare function createSetTemporaryPasswordScript(config: SoftureConfig, options?: TemporaryPasswordScriptOptions): OpsScript<TemporaryPasswordScriptArgs>;
|
|
12
16
|
//# sourceMappingURL=temporary-password.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAc3F,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,oGAAoG;IACpG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,8BAA8B;IAC7C,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB,sGAAsG;IACtG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAQD,kHAAkH;AAClH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,8BAAmC,GAC3C,SAAS,CAAC,2BAA2B,CAAC,CAwBxC"}
|
|
@@ -1,47 +1,59 @@
|
|
|
1
1
|
// The operator's account recovery: a safe ops script (`@softure-ai/ops/scripts`), dry run by
|
|
2
|
-
// default, `--commit` writes. It sets a
|
|
3
|
-
// pending reset link
|
|
4
|
-
// that proves the owner (a reply to the account's own address)
|
|
5
|
-
|
|
2
|
+
// default, `--commit` writes. It sets a new password, ends every session of the account and its
|
|
3
|
+
// pending reset link. Either the script draws a random password and prints it once for the operator
|
|
4
|
+
// to hand over through a channel that proves the owner (a reply to the account's own address), or
|
|
5
|
+
// the operator computes the password and its hash locally and passes only the hash
|
|
6
|
+
// (`--password-hash`, best through `--password-hash-file=-`), so the plain password never reaches
|
|
7
|
+
// the server. Reports carry the user id, never the email or the hash.
|
|
6
8
|
import { ok, systemClock } from "@softure-ai/core";
|
|
7
9
|
import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
|
|
8
10
|
import { eq } from "drizzle-orm";
|
|
9
11
|
import { z } from "zod";
|
|
10
12
|
import { passwordResets, sessions, users } from "../schema.js";
|
|
11
13
|
import { getAuthOptions } from "../server/options.js";
|
|
12
|
-
import { hashPassword } from "../server/password.js";
|
|
14
|
+
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
13
15
|
import { revokeUserSessions } from "../server/sessions.js";
|
|
16
|
+
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
14
17
|
import { normalizeEmail } from "../server/validation.js";
|
|
15
18
|
/** Long enough to be out of guessing range in any rate limit window. */
|
|
16
19
|
const MIN_TEMPORARY_LENGTH = 20;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const PASSWORD_HASH_KEY = "password-hash";
|
|
21
|
+
const scriptArgs = z.strictObject({
|
|
22
|
+
email: z.string().min(1, "--email=<account email> is required"),
|
|
23
|
+
// A constant message: the value is secret-derived and must not be echoed.
|
|
24
|
+
[PASSWORD_HASH_KEY]: z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional(),
|
|
25
|
+
});
|
|
26
|
+
/** `set-temporary-password --email=… [--password-hash=…]`: a new password, every session and reset link ended. */
|
|
23
27
|
export function createSetTemporaryPasswordScript(config, options = {}) {
|
|
24
28
|
const clock = options.clock ?? systemClock;
|
|
25
29
|
return defineOpsScript({
|
|
26
30
|
name: "set-temporary-password",
|
|
27
|
-
description: "Sets a
|
|
28
|
-
usage: ["--email=<account email>"],
|
|
31
|
+
description: "Sets a new password for the account with the given email (a random one, or the given hash) and ends its sessions and reset link.",
|
|
32
|
+
usage: ["--email=<account email>", `--${PASSWORD_HASH_KEY}=<hash> store this hashPassword() hash instead of drawing a password`],
|
|
29
33
|
args: scriptArgs,
|
|
34
|
+
secrets: [PASSWORD_HASH_KEY],
|
|
30
35
|
run: async (tx, args) => {
|
|
31
36
|
const ctx = { db: tx, clock, config };
|
|
32
37
|
const [account] = await tx.select({ id: users.id }).from(users).where(eq(users.email, normalizeEmail(args.email))).limit(1);
|
|
33
38
|
if (account === undefined)
|
|
34
39
|
return refuseOpsScript("no account has this email");
|
|
35
40
|
const before = { userId: account.id, sessions: (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length };
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const passwordHash = await hashPassword(temporaryPassword, authOptions.password.scrypt);
|
|
39
|
-
await tx.update(users).set({ passwordHash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
|
|
41
|
+
const password = await choosePassword(args[PASSWORD_HASH_KEY], config, options.alphabet);
|
|
42
|
+
await tx.update(users).set({ passwordHash: password.hash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
|
|
40
43
|
await revokeUserSessions(ctx, account.id);
|
|
41
44
|
await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
|
|
42
45
|
const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
|
|
43
|
-
|
|
46
|
+
const after = password.from === "hash" ? { passwordFrom: "hash" } : { temporaryPassword: password.plain };
|
|
47
|
+
return ok({ before, after: { userId: account.id, sessions: remaining, ...after } });
|
|
44
48
|
},
|
|
45
49
|
});
|
|
46
50
|
}
|
|
51
|
+
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
52
|
+
async function choosePassword(givenHash, config, alphabet) {
|
|
53
|
+
if (givenHash !== undefined)
|
|
54
|
+
return { from: "hash", hash: givenHash };
|
|
55
|
+
const { password } = getAuthOptions(config);
|
|
56
|
+
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
57
|
+
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
58
|
+
}
|
|
47
59
|
//# sourceMappingURL=temporary-password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporary-password.js","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,
|
|
1
|
+
{"version":3,"file":"temporary-password.js","sourceRoot":"","sources":["../../src/scripts/temporary-password.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,gGAAgG;AAChG,oGAAoG;AACpG,kGAAkG;AAClG,mFAAmF;AACnF,kGAAkG;AAClG,sEAAsE;AACtE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAkC,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAoB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,wEAAwE;AACxE,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAe1C,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qCAAqC,CAAC;IAC/D,0EAA0E;IAC1E,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC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,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACtE,MAAM,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,uBAAuB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAChH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;AACpF,CAAC"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
|
|
2
2
|
export { loginUser, type LoginInput, type LoginResult } from "./login.js";
|
|
3
3
|
export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
|
|
4
|
-
export { hashPassword, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
|
|
4
|
+
export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
|
|
5
5
|
export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, type PasswordResetRequestInput, type PasswordResetRequestResult, type ResetPasswordErrorCode, type ResetPasswordInput, type ResetPasswordResult, } from "./password-reset.js";
|
|
6
6
|
export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, type RoleChange, type RoleErrorCode, } from "./roles.js";
|
|
7
7
|
export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData, type AuthUserData } from "./privacy.js";
|
|
@@ -9,4 +9,5 @@ export { isCurrentPassword } from "./reauthenticate.js";
|
|
|
9
9
|
export { registerUser, type RegisterErrorCode, type RegisterInput, type RegisterResult } from "./register.js";
|
|
10
10
|
export { createSession, findSessionUser, logoutSession, pruneSessions, revokeUserSessions, type AuthContext, type RevokeUserSessionsOptions, } from "./sessions.js";
|
|
11
11
|
export { isRegistrationClosed } from "./switches.js";
|
|
12
|
+
export { createTemporaryPassword, READABLE_PASSWORD_ALPHABET, type TemporaryPasswordOptions } from "./temporary-password.js";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,KAAK,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { changePassword } from "./change-password.js";
|
|
4
4
|
export { loginUser } from "./login.js";
|
|
5
5
|
export { getAuthOptions, getAuthRoutes } from "./options.js";
|
|
6
|
-
export { hashPassword, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
|
|
6
|
+
export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
|
|
7
7
|
export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, } from "./password-reset.js";
|
|
8
8
|
export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, } from "./roles.js";
|
|
9
9
|
export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData } from "./privacy.js";
|
|
@@ -11,4 +11,5 @@ export { isCurrentPassword } from "./reauthenticate.js";
|
|
|
11
11
|
export { registerUser } from "./register.js";
|
|
12
12
|
export { createSession, findSessionUser, logoutSession, pruneSessions, revokeUserSessions, } from "./sessions.js";
|
|
13
13
|
export { isRegistrationClosed } from "./switches.js";
|
|
14
|
+
export { createTemporaryPassword, READABLE_PASSWORD_ALPHABET } from "./temporary-password.js";
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAsB,MAAM,eAAe,CAAC;AAClJ,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAmE,MAAM,eAAe,CAAC;AAC9G,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,GAGnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAiC,MAAM,yBAAyB,CAAC"}
|
|
@@ -22,4 +22,6 @@ export declare function needsRehash(storedHash: string, params: ScryptParams): b
|
|
|
22
22
|
* The dummy hash is made once per parameter set.
|
|
23
23
|
*/
|
|
24
24
|
export declare function verifyDummyPassword(password: string, params: ScryptParams): Promise<void>;
|
|
25
|
+
/** Whether `value` is in the `scrypt$N$r$p$salt$key` format this module writes and reads. */
|
|
26
|
+
export declare function isPasswordHash(value: string): boolean;
|
|
25
27
|
//# sourceMappingURL=password.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/server/password.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,8FAA8F;AAC9F,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAQxC,uCAAuC;AACvC,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1F;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAMhG;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE5D,gFAAgF;AAChF,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3F;AAMD,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAG7E;AAID;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F"}
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/server/password.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD,8FAA8F;AAC9F,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAQxC,uCAAuC;AACvC,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1F;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAMhG;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE5D,gFAAgF;AAChF,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE3F;AAMD,yEAAyE;AACzE,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAG7E;AAID;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAmBD,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
package/dist/server/password.js
CHANGED
|
@@ -74,20 +74,28 @@ function deriveKey(password, salt, params) {
|
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
/** Whether `value` is in the `scrypt$N$r$p$salt$key` format this module writes and reads. */
|
|
78
|
+
export function isPasswordHash(value) {
|
|
79
|
+
return readHashParts(value) !== null;
|
|
80
|
+
}
|
|
81
|
+
function readHashParts(value) {
|
|
82
|
+
const [scheme, cost, blockSize, parallelization, salt, key, ...rest] = value.split("$");
|
|
79
83
|
const params = { cost: Number(cost), blockSize: Number(blockSize), parallelization: Number(parallelization) };
|
|
80
84
|
const isValid = scheme === "scrypt" &&
|
|
81
85
|
rest.length === 0 &&
|
|
82
|
-
Object.values(params).every((
|
|
86
|
+
Object.values(params).every((part) => Number.isSafeInteger(part) && part > 0) &&
|
|
83
87
|
salt !== undefined &&
|
|
84
88
|
salt !== "" &&
|
|
85
89
|
key !== undefined &&
|
|
86
90
|
key !== "";
|
|
87
|
-
|
|
91
|
+
return isValid ? { params, salt, key } : null;
|
|
92
|
+
}
|
|
93
|
+
function parseHash(storedHash) {
|
|
94
|
+
const parts = readHashParts(storedHash);
|
|
95
|
+
if (parts === null) {
|
|
88
96
|
// The hash itself stays out of the message: it is secret-derived data.
|
|
89
97
|
throw new Error("@softure-ai/auth: a stored password hash is not in the scrypt$N$r$p$salt$key format");
|
|
90
98
|
}
|
|
91
|
-
return { params, salt: Buffer.from(salt, "base64url"), key: Buffer.from(key, "base64url") };
|
|
99
|
+
return { params: parts.params, salt: Buffer.from(parts.salt, "base64url"), key: Buffer.from(parts.key, "base64url") };
|
|
92
100
|
}
|
|
93
101
|
//# sourceMappingURL=password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../src/server/password.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,mGAAmG;AACnG,iFAAiF;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAsB,MAAM,aAAa,CAAC;AAGvF,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,8FAA8F;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAQxC,uCAAuC;AACvC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB,EAAE,MAAoB;IACvE,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACrE,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,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CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,CAAC;AACxH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Letters and digits without the ones that read alike when dictated or copied by hand (`0`/`O`,
|
|
3
|
+
* `1`/`l`/`I`) and without `-` and `_`: 57 characters.
|
|
4
|
+
*/
|
|
5
|
+
export declare const READABLE_PASSWORD_ALPHABET = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
6
|
+
export interface TemporaryPasswordOptions {
|
|
7
|
+
/** The characters to draw from, each at most once; base64url by default. */
|
|
8
|
+
readonly alphabet?: string;
|
|
9
|
+
/** How many characters; 20 by default. Use at least the app's `password.minLength`. */
|
|
10
|
+
readonly length?: number;
|
|
11
|
+
}
|
|
12
|
+
/** A random password of `length` characters from `alphabet`. Throws on an unusable alphabet or length. */
|
|
13
|
+
export declare function createTemporaryPassword(options?: TemporaryPasswordOptions): string;
|
|
14
|
+
//# sourceMappingURL=temporary-password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporary-password.d.ts","sourceRoot":"","sources":["../../src/server/temporary-password.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,eAAO,MAAM,0BAA0B,8DAA8D,CAAC;AAItG,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,0GAA0G;AAC1G,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAUtF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Temporary passwords an operator hands over: random characters drawn uniformly with `randomInt`
|
|
2
|
+
// from `node:crypto`. The same function serves the `set-temporary-password` script and an
|
|
3
|
+
// operator's local half, which hashes the password with `hashPassword` and gives the script only
|
|
4
|
+
// the hash, so the plain password never reaches the server.
|
|
5
|
+
import { randomInt } from "node:crypto";
|
|
6
|
+
/** The URL-safe base64 alphabet: the default, what the script printed before alphabets existed. */
|
|
7
|
+
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
8
|
+
/**
|
|
9
|
+
* Letters and digits without the ones that read alike when dictated or copied by hand (`0`/`O`,
|
|
10
|
+
* `1`/`l`/`I`) and without `-` and `_`: 57 characters.
|
|
11
|
+
*/
|
|
12
|
+
export const READABLE_PASSWORD_ALPHABET = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
13
|
+
const DEFAULT_LENGTH = 20;
|
|
14
|
+
/** A random password of `length` characters from `alphabet`. Throws on an unusable alphabet or length. */
|
|
15
|
+
export function createTemporaryPassword(options = {}) {
|
|
16
|
+
const alphabet = [...(options.alphabet ?? BASE64URL_ALPHABET)];
|
|
17
|
+
const length = options.length ?? DEFAULT_LENGTH;
|
|
18
|
+
if (!Number.isSafeInteger(length) || length < 1) {
|
|
19
|
+
throw new Error("@softure-ai/auth: createTemporaryPassword needs a whole length of at least 1");
|
|
20
|
+
}
|
|
21
|
+
if (alphabet.length < 2 || new Set(alphabet).size !== alphabet.length) {
|
|
22
|
+
throw new Error("@softure-ai/auth: createTemporaryPassword needs an alphabet of at least 2 distinct characters");
|
|
23
|
+
}
|
|
24
|
+
return Array.from({ length }, () => alphabet[randomInt(alphabet.length)]).join("");
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=temporary-password.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporary-password.js","sourceRoot":"","sources":["../../src/server/temporary-password.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,0FAA0F;AAC1F,iGAAiG;AACjG,4DAA4D;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,mGAAmG;AACnG,MAAM,kBAAkB,GAAG,kEAAkE,CAAC;AAE9F;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,2DAA2D,CAAC;AAEtG,MAAM,cAAc,GAAG,EAAE,CAAC;AAS1B,0GAA0G;AAC1G,MAAM,UAAU,uBAAuB,CAAC,UAAoC,EAAE;IAC5E,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,cAAc,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,+FAA+F,CAAC,CAAC;IACnH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrF,CAAC"}
|
package/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "SOFTURE AI auth module: users, scrypt passwords, database sessions, register with consent, login, logout, password change, roles, a proxy route guard, pages and forms for Next.js, and a password reset sender over @softure-ai/mailing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export const AUTH_RATE_LIMIT_BUCKETS = {
|
|
|
41
41
|
export const auth = defineModule({
|
|
42
42
|
manifest: {
|
|
43
43
|
id: MODULE_ID,
|
|
44
|
-
version: "0.1.
|
|
44
|
+
version: "0.1.9",
|
|
45
45
|
dependsOn: { security: "^0.1.0", mailing: "^0.1.0?", ops: "^0.1.0?" },
|
|
46
46
|
dbSchema: "auth",
|
|
47
47
|
tables: ["users", "sessions", "user_roles", "password_resets"],
|
package/src/next/actions.ts
CHANGED
|
@@ -225,9 +225,27 @@ async function endPreviousSession(config: SoftureConfig): Promise<void> {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
/**
|
|
229
|
-
export
|
|
228
|
+
/** Where to go after logout: a path on this app, checked like login's `next`. */
|
|
229
|
+
export interface LogoutInput {
|
|
230
|
+
readonly next?: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Any client can call the action with any serializable value: only a `next` string counts.
|
|
234
|
+
const logoutInput = z.object({ next: nextPath }).catch({ next: "" });
|
|
235
|
+
|
|
236
|
+
/** The `next` of a posted form or of an object; anything else is no target. */
|
|
237
|
+
function readLogoutNext(input: unknown): string {
|
|
238
|
+
if (input instanceof FormData) return logoutInput.parse({ next: input.get("next") }).next;
|
|
239
|
+
return logoutInput.parse(input).next;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Ends the request's sessions and goes to `next` (a form field or `{ next }`, e.g. `/login?next=…` to
|
|
244
|
+
* sign in as someone else), else to `afterLogout`. The cookies are cleared even if the delete fails.
|
|
245
|
+
*/
|
|
246
|
+
export async function logoutAction(input?: FormData | LogoutInput): Promise<void> {
|
|
230
247
|
const config = getSoftureConfig();
|
|
248
|
+
const target = toSafeNextPath(readLogoutNext(input), getAuthRoutes(config).afterLogout);
|
|
231
249
|
for (const token of await readHeldTokens(config)) {
|
|
232
250
|
try {
|
|
233
251
|
await logoutSession(await getAuthContext(config), token);
|
|
@@ -236,5 +254,5 @@ export async function logoutAction(): Promise<void> {
|
|
|
236
254
|
}
|
|
237
255
|
}
|
|
238
256
|
await clearSessionCookie(config);
|
|
239
|
-
redirect(await resolveRedirectTarget(config,
|
|
257
|
+
redirect(await resolveRedirectTarget(config, target));
|
|
240
258
|
}
|
package/src/next/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// A logout button for the app's own pages: a plain form posting to `logoutAction`, so it works
|
|
2
|
-
// without JavaScript. Server component.
|
|
2
|
+
// without JavaScript. Server component. `next` rides along as a hidden field.
|
|
3
3
|
import { getSoftureConfig } from "@softure-ai/core/next";
|
|
4
4
|
import { Button, type ButtonVariant } from "@softure-ai/ui";
|
|
5
5
|
import { logoutAction } from "./actions.js";
|
|
@@ -8,12 +8,15 @@ import { getAuthMessages } from "./messages.js";
|
|
|
8
8
|
export interface LogoutButtonProps {
|
|
9
9
|
readonly variant?: ButtonVariant;
|
|
10
10
|
readonly className?: string;
|
|
11
|
+
/** Where to go after logout (a path on this app), e.g. `/login?next=…`; default `afterLogout`. */
|
|
12
|
+
readonly next?: string;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
export function LogoutButton({ variant = "secondary", className }: LogoutButtonProps) {
|
|
15
|
+
export function LogoutButton({ variant = "secondary", className, next }: LogoutButtonProps) {
|
|
14
16
|
const messages = getAuthMessages(getSoftureConfig());
|
|
15
17
|
return (
|
|
16
18
|
<form action={logoutAction} className={className}>
|
|
19
|
+
{next === undefined ? null : <input type="hidden" name="next" value={next} />}
|
|
17
20
|
<Button type="submit" variant={variant}>
|
|
18
21
|
{messages.logout.submit}
|
|
19
22
|
</Button>
|
package/src/proxy/index.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface AuthGuardOptions {
|
|
|
19
19
|
* public pages here). `"/"` here is the home page only. The change-password route stays guarded.
|
|
20
20
|
*/
|
|
21
21
|
readonly exclude?: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* Origins besides `appOrigin` that the login redirect may stay on (`https://example.com`), for an app
|
|
24
|
+
* served on several hosts. The request's public origin (`X-Forwarded-Proto` / `X-Forwarded-Host`,
|
|
25
|
+
* else `Host` and the URL's scheme) is used only when it is listed; any other goes to `appOrigin`.
|
|
26
|
+
*/
|
|
27
|
+
readonly trustedOrigins?: readonly string[];
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
/** Mounted at a fixed path by the module (manifest `mount`); it answers `{ user: null }` without a session. */
|
|
@@ -37,6 +43,7 @@ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions
|
|
|
37
43
|
normalizePrefix(path, "excluded"),
|
|
38
44
|
);
|
|
39
45
|
const excluded = (options.exclude ?? []).map((prefix) => normalizePrefix(prefix, "excluded"));
|
|
46
|
+
const trustedOrigins = new Set((options.trustedOrigins ?? []).map(normalizeOrigin));
|
|
40
47
|
|
|
41
48
|
const isGuarded = (path: string): boolean => {
|
|
42
49
|
if (isUnder(path, changePassword)) return true;
|
|
@@ -52,8 +59,10 @@ export function createAuthGuard(config: SoftureConfig, options: AuthGuardOptions
|
|
|
52
59
|
if (path !== null && !isGuarded(path)) return null;
|
|
53
60
|
const cookieHeader = request.headers.get("cookie");
|
|
54
61
|
if (cookieNames.some((name) => readSessionToken(cookieHeader, name) !== null)) return null;
|
|
55
|
-
// Built on appOrigin
|
|
56
|
-
|
|
62
|
+
// Built on appOrigin, or on the request's public origin when the app trusts it: behind a proxy
|
|
63
|
+
// the request URL carries an internal host, and request headers alone are never trusted.
|
|
64
|
+
const origin = findPublicOrigin(request, url);
|
|
65
|
+
const login = new URL(routes.login, origin !== null && trustedOrigins.has(origin) ? origin : config.appOrigin);
|
|
57
66
|
login.searchParams.set("next", `${url.pathname}${url.search}`);
|
|
58
67
|
return Response.redirect(login, 307);
|
|
59
68
|
};
|
|
@@ -67,6 +76,38 @@ function normalizePrefix(prefix: string, kind: "protected" | "excluded"): string
|
|
|
67
76
|
return trimmed.toLowerCase();
|
|
68
77
|
}
|
|
69
78
|
|
|
79
|
+
/** `entry` as an origin (`https://example.com`, a trailing `/` dropped); anything else is a config error. */
|
|
80
|
+
function normalizeOrigin(entry: string): string {
|
|
81
|
+
const parsed = parseOrigin(entry.endsWith("/") ? entry.slice(0, -1) : entry);
|
|
82
|
+
if (parsed === null) {
|
|
83
|
+
throw new Error(`createAuthGuard: trusted origin "${entry}" must be an http(s) origin such as https://example.com`);
|
|
84
|
+
}
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The origin the browser used: the front proxy's forwarded scheme and host, else `Host` and the URL's scheme. */
|
|
89
|
+
function findPublicOrigin(request: Request, url: URL): string | null {
|
|
90
|
+
const host = firstValue(request.headers.get("x-forwarded-host")) ?? firstValue(request.headers.get("host")) ?? url.host;
|
|
91
|
+
const scheme = firstValue(request.headers.get("x-forwarded-proto")) ?? url.protocol.slice(0, -1);
|
|
92
|
+
return parseOrigin(`${scheme}://${host}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function firstValue(header: string | null): string | null {
|
|
96
|
+
const value = header?.split(",")[0]?.trim();
|
|
97
|
+
return value === undefined || value === "" ? null : value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The normalized origin of `candidate` when it is exactly `http(s)://host[:port]`, else null. */
|
|
101
|
+
function parseOrigin(candidate: string): string | null {
|
|
102
|
+
// Checked on the raw text, so a path, query, fragment or credentials make it no origin.
|
|
103
|
+
if (!/^https?:\/\/[^/\\?#@\s]+$/i.test(candidate)) return null;
|
|
104
|
+
try {
|
|
105
|
+
return new URL(candidate).origin;
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
70
111
|
function decodePath(pathname: string): string | null {
|
|
71
112
|
try {
|
|
72
113
|
return decodeURIComponent(pathname).toLowerCase();
|
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
// The operator's account recovery: a safe ops script (`@softure-ai/ops/scripts`), dry run by
|
|
2
|
-
// default, `--commit` writes. It sets a
|
|
3
|
-
// pending reset link
|
|
4
|
-
// that proves the owner (a reply to the account's own address)
|
|
5
|
-
|
|
2
|
+
// default, `--commit` writes. It sets a new password, ends every session of the account and its
|
|
3
|
+
// pending reset link. Either the script draws a random password and prints it once for the operator
|
|
4
|
+
// to hand over through a channel that proves the owner (a reply to the account's own address), or
|
|
5
|
+
// the operator computes the password and its hash locally and passes only the hash
|
|
6
|
+
// (`--password-hash`, best through `--password-hash-file=-`), so the plain password never reaches
|
|
7
|
+
// the server. Reports carry the user id, never the email or the hash.
|
|
6
8
|
import { ok, systemClock, type Clock, type SoftureConfig } from "@softure-ai/core";
|
|
7
9
|
import { defineOpsScript, refuseOpsScript, type OpsScript } from "@softure-ai/ops/scripts";
|
|
8
10
|
import { eq } from "drizzle-orm";
|
|
9
11
|
import { z } from "zod";
|
|
10
12
|
import { passwordResets, sessions, users } from "../schema.js";
|
|
11
13
|
import { getAuthOptions } from "../server/options.js";
|
|
12
|
-
import { hashPassword } from "../server/password.js";
|
|
14
|
+
import { hashPassword, isPasswordHash } from "../server/password.js";
|
|
13
15
|
import { revokeUserSessions, type AuthContext } from "../server/sessions.js";
|
|
16
|
+
import { createTemporaryPassword } from "../server/temporary-password.js";
|
|
14
17
|
import { normalizeEmail } from "../server/validation.js";
|
|
15
18
|
|
|
16
19
|
/** Long enough to be out of guessing range in any rate limit window. */
|
|
17
20
|
const MIN_TEMPORARY_LENGTH = 20;
|
|
21
|
+
const PASSWORD_HASH_KEY = "password-hash";
|
|
18
22
|
|
|
19
23
|
export interface TemporaryPasswordScriptArgs {
|
|
20
24
|
readonly email: string;
|
|
25
|
+
/** A hash from `hashPassword`, computed where the password was made; the script then draws none. */
|
|
26
|
+
readonly "password-hash"?: string;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export interface TemporaryPasswordScriptOptions {
|
|
24
30
|
/** The time stored as `password_changed_at`; the system clock by default. */
|
|
25
31
|
readonly clock?: Clock;
|
|
32
|
+
/** The characters a drawn password uses (e.g. `READABLE_PASSWORD_ALPHABET`); base64url by default. */
|
|
33
|
+
readonly alphabet?: string;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
const scriptArgs = z.strictObject({
|
|
36
|
+
const scriptArgs = z.strictObject({
|
|
37
|
+
email: z.string().min(1, "--email=<account email> is required"),
|
|
38
|
+
// A constant message: the value is secret-derived and must not be echoed.
|
|
39
|
+
[PASSWORD_HASH_KEY]: z.string().refine(isPasswordHash, "is not a scrypt hash written by @softure-ai/auth").optional(),
|
|
40
|
+
});
|
|
29
41
|
|
|
30
|
-
/**
|
|
31
|
-
function createTemporaryPassword(length: number): string {
|
|
32
|
-
return randomBytes(Math.ceil((length * 3) / 4)).toString("base64url").slice(0, length);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** `set-temporary-password --email=…`: a new random password, every session and reset link ended. */
|
|
42
|
+
/** `set-temporary-password --email=… [--password-hash=…]`: a new password, every session and reset link ended. */
|
|
36
43
|
export function createSetTemporaryPasswordScript(
|
|
37
44
|
config: SoftureConfig,
|
|
38
45
|
options: TemporaryPasswordScriptOptions = {},
|
|
@@ -40,23 +47,34 @@ export function createSetTemporaryPasswordScript(
|
|
|
40
47
|
const clock = options.clock ?? systemClock;
|
|
41
48
|
return defineOpsScript({
|
|
42
49
|
name: "set-temporary-password",
|
|
43
|
-
description:
|
|
44
|
-
|
|
50
|
+
description:
|
|
51
|
+
"Sets a new password for the account with the given email (a random one, or the given hash) and ends its sessions and reset link.",
|
|
52
|
+
usage: ["--email=<account email>", `--${PASSWORD_HASH_KEY}=<hash> store this hashPassword() hash instead of drawing a password`],
|
|
45
53
|
args: scriptArgs,
|
|
54
|
+
secrets: [PASSWORD_HASH_KEY],
|
|
46
55
|
run: async (tx, args) => {
|
|
47
56
|
const ctx: AuthContext = { db: tx, clock, config };
|
|
48
57
|
const [account] = await tx.select({ id: users.id }).from(users).where(eq(users.email, normalizeEmail(args.email))).limit(1);
|
|
49
58
|
if (account === undefined) return refuseOpsScript("no account has this email");
|
|
50
59
|
const before = { userId: account.id, sessions: (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length };
|
|
51
60
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const passwordHash = await hashPassword(temporaryPassword, authOptions.password.scrypt);
|
|
55
|
-
await tx.update(users).set({ passwordHash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
|
|
61
|
+
const password = await choosePassword(args[PASSWORD_HASH_KEY], config, options.alphabet);
|
|
62
|
+
await tx.update(users).set({ passwordHash: password.hash, passwordChangedAt: clock.now() }).where(eq(users.id, account.id));
|
|
56
63
|
await revokeUserSessions(ctx, account.id);
|
|
57
64
|
await tx.delete(passwordResets).where(eq(passwordResets.userId, account.id));
|
|
58
65
|
const remaining = (await tx.select().from(sessions).where(eq(sessions.userId, account.id))).length;
|
|
59
|
-
|
|
66
|
+
const after = password.from === "hash" ? { passwordFrom: "hash" } : { temporaryPassword: password.plain };
|
|
67
|
+
return ok({ before, after: { userId: account.id, sessions: remaining, ...after } });
|
|
60
68
|
},
|
|
61
69
|
});
|
|
62
70
|
}
|
|
71
|
+
|
|
72
|
+
type ChosenPassword = { readonly from: "hash"; readonly hash: string } | { readonly from: "drawn"; readonly hash: string; readonly plain: string };
|
|
73
|
+
|
|
74
|
+
/** The given hash, or a drawn password of at least 20 characters and `password.minLength`, with its hash. */
|
|
75
|
+
async function choosePassword(givenHash: string | undefined, config: SoftureConfig, alphabet: string | undefined): Promise<ChosenPassword> {
|
|
76
|
+
if (givenHash !== undefined) return { from: "hash", hash: givenHash };
|
|
77
|
+
const { password } = getAuthOptions(config);
|
|
78
|
+
const plain = createTemporaryPassword({ alphabet, length: Math.max(password.minLength, MIN_TEMPORARY_LENGTH) });
|
|
79
|
+
return { from: "drawn", hash: await hashPassword(plain, password.scrypt), plain };
|
|
80
|
+
}
|
package/src/server/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
|
|
4
4
|
export { loginUser, type LoginInput, type LoginResult } from "./login.js";
|
|
5
5
|
export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
|
|
6
|
-
export { hashPassword, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
|
|
6
|
+
export { hashPassword, isPasswordHash, matchPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword, type PasswordMatch } from "./password.js";
|
|
7
7
|
export {
|
|
8
8
|
deliverPasswordReset,
|
|
9
9
|
findPasswordResetUser,
|
|
@@ -44,3 +44,4 @@ export {
|
|
|
44
44
|
type RevokeUserSessionsOptions,
|
|
45
45
|
} from "./sessions.js";
|
|
46
46
|
export { isRegistrationClosed } from "./switches.js";
|
|
47
|
+
export { createTemporaryPassword, READABLE_PASSWORD_ALPHABET, type TemporaryPasswordOptions } from "./temporary-password.js";
|
package/src/server/password.ts
CHANGED
|
@@ -89,20 +89,30 @@ function deriveKey(password: string, salt: Buffer, params: ScryptParams): Promis
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
/** Whether `value` is in the `scrypt$N$r$p$salt$key` format this module writes and reads. */
|
|
93
|
+
export function isPasswordHash(value: string): boolean {
|
|
94
|
+
return readHashParts(value) !== null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readHashParts(value: string): { params: ScryptParams; salt: string; key: string } | null {
|
|
98
|
+
const [scheme, cost, blockSize, parallelization, salt, key, ...rest] = value.split("$");
|
|
94
99
|
const params = { cost: Number(cost), blockSize: Number(blockSize), parallelization: Number(parallelization) };
|
|
95
100
|
const isValid =
|
|
96
101
|
scheme === "scrypt" &&
|
|
97
102
|
rest.length === 0 &&
|
|
98
|
-
Object.values(params).every((
|
|
103
|
+
Object.values(params).every((part) => Number.isSafeInteger(part) && part > 0) &&
|
|
99
104
|
salt !== undefined &&
|
|
100
105
|
salt !== "" &&
|
|
101
106
|
key !== undefined &&
|
|
102
107
|
key !== "";
|
|
103
|
-
|
|
108
|
+
return isValid ? { params, salt, key } : null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseHash(storedHash: string): ParsedHash {
|
|
112
|
+
const parts = readHashParts(storedHash);
|
|
113
|
+
if (parts === null) {
|
|
104
114
|
// The hash itself stays out of the message: it is secret-derived data.
|
|
105
115
|
throw new Error("@softure-ai/auth: a stored password hash is not in the scrypt$N$r$p$salt$key format");
|
|
106
116
|
}
|
|
107
|
-
return { params, salt: Buffer.from(salt, "base64url"), key: Buffer.from(key, "base64url") };
|
|
117
|
+
return { params: parts.params, salt: Buffer.from(parts.salt, "base64url"), key: Buffer.from(parts.key, "base64url") };
|
|
108
118
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Temporary passwords an operator hands over: random characters drawn uniformly with `randomInt`
|
|
2
|
+
// from `node:crypto`. The same function serves the `set-temporary-password` script and an
|
|
3
|
+
// operator's local half, which hashes the password with `hashPassword` and gives the script only
|
|
4
|
+
// the hash, so the plain password never reaches the server.
|
|
5
|
+
import { randomInt } from "node:crypto";
|
|
6
|
+
|
|
7
|
+
/** The URL-safe base64 alphabet: the default, what the script printed before alphabets existed. */
|
|
8
|
+
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Letters and digits without the ones that read alike when dictated or copied by hand (`0`/`O`,
|
|
12
|
+
* `1`/`l`/`I`) and without `-` and `_`: 57 characters.
|
|
13
|
+
*/
|
|
14
|
+
export const READABLE_PASSWORD_ALPHABET = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
15
|
+
|
|
16
|
+
const DEFAULT_LENGTH = 20;
|
|
17
|
+
|
|
18
|
+
export interface TemporaryPasswordOptions {
|
|
19
|
+
/** The characters to draw from, each at most once; base64url by default. */
|
|
20
|
+
readonly alphabet?: string;
|
|
21
|
+
/** How many characters; 20 by default. Use at least the app's `password.minLength`. */
|
|
22
|
+
readonly length?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A random password of `length` characters from `alphabet`. Throws on an unusable alphabet or length. */
|
|
26
|
+
export function createTemporaryPassword(options: TemporaryPasswordOptions = {}): string {
|
|
27
|
+
const alphabet = [...(options.alphabet ?? BASE64URL_ALPHABET)];
|
|
28
|
+
const length = options.length ?? DEFAULT_LENGTH;
|
|
29
|
+
if (!Number.isSafeInteger(length) || length < 1) {
|
|
30
|
+
throw new Error("@softure-ai/auth: createTemporaryPassword needs a whole length of at least 1");
|
|
31
|
+
}
|
|
32
|
+
if (alphabet.length < 2 || new Set(alphabet).size !== alphabet.length) {
|
|
33
|
+
throw new Error("@softure-ai/auth: createTemporaryPassword needs an alphabet of at least 2 distinct characters");
|
|
34
|
+
}
|
|
35
|
+
return Array.from({ length }, () => alphabet[randomInt(alphabet.length)]).join("");
|
|
36
|
+
}
|