@ultimat3/auth 31.51.0 → 31.52.0
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 +1 -1
- package/package.json +4 -4
- package/src/member-invite.ts +4 -5
- package/src/verification-purposes.ts +2 -0
- package/src/verify.ts +32 -2
package/README.md
CHANGED
|
@@ -700,7 +700,7 @@ const verification = await consumeVerification(runtime, {
|
|
|
700
700
|
| `VERIFICATION_TEMPLATES` | purpose → **catalog key** (`auth.email-verify`, `auth.password-reset`), never copy: the body lives in the app's i18n catalog |
|
|
701
701
|
| `DEFAULT_VERIFICATION_TTL_MS` | 24 h for `email-verify`, 1 h for `password-reset` — a reset link is a password |
|
|
702
702
|
| `MailSender` | the injected port: `send(template, to, data, locale)`. `@ultimat3/mail` is tier 4 and this package is tier 2, so the app wires it |
|
|
703
|
-
| `issueVerification(runtime, input)` | `{ token, expiresAt }`. The token comes back for a test or a CLI; production only ever mails it |
|
|
703
|
+
| `issueVerification(runtime, input)` | `{ token, expiresAt }`. The token comes back for a test or a CLI; production only ever mails it. `to?` names the recipient, and only on a purpose declared `recipient: 'explicit'` (the member invite: its identifier is tenant + address, not an address): mail goes to that `to`, never normalised, and it is required. On any other purpose, `passwordReset` and every sign-in purpose included, a `to` is `X_CONFIG_INVALID` before any row is written, so a request body spread into `issue` cannot redirect a reset link |
|
|
704
704
|
| `consumeVerification(runtime, input)` | the `AuthVerification` row, or `X_UNAUTHENTICATED`. Unknown, spent, expired and mismatched are one answer. Reads only `{ store, clock }` of the runtime. An undeclared purpose on either door is `X_VERIFICATION_PURPOSE_UNKNOWN` |
|
|
705
705
|
|
|
706
706
|
One live token per `(purpose, identifier)`. A wrong guess destroys nothing: the store's
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/auth",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.52.0",
|
|
4
4
|
"description": "Sessions, passwords, OAuth, MFA and api keys — resolved to one Actor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"test": "bun test"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ultimat3/core": "31.
|
|
54
|
-
"@ultimat3/db": "31.
|
|
55
|
-
"@ultimat3/schema": "31.
|
|
53
|
+
"@ultimat3/core": "31.52.0",
|
|
54
|
+
"@ultimat3/db": "31.52.0",
|
|
55
|
+
"@ultimat3/schema": "31.52.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/member-invite.ts
CHANGED
|
@@ -92,6 +92,7 @@ export function defineMemberInvite(input: DefineMemberInviteInput): MemberInvite
|
|
|
92
92
|
template: input.template,
|
|
93
93
|
ttlMs: input.ttlMs,
|
|
94
94
|
identifier: (raw) => raw,
|
|
95
|
+
recipient: 'explicit',
|
|
95
96
|
});
|
|
96
97
|
const runtime = (auth: Auth, mail: MailSender): VerificationRuntime => ({
|
|
97
98
|
store: auth.adapter,
|
|
@@ -105,12 +106,10 @@ export function defineMemberInvite(input: DefineMemberInviteInput): MemberInvite
|
|
|
105
106
|
async invite(auth, mail, invite) {
|
|
106
107
|
const orgId = tenantOf(invite.orgId);
|
|
107
108
|
const to = normaliseEmail(invite.email);
|
|
108
|
-
|
|
109
|
-
const addressed: MailSender = {
|
|
110
|
-
send: (template, _key, data, locale) => mail.send(template, to, data, locale),
|
|
111
|
-
};
|
|
112
|
-
return purpose.issue(runtime(auth, addressed), {
|
|
109
|
+
return purpose.issue(runtime(auth, mail), {
|
|
113
110
|
identifier: storeKey(orgId, to),
|
|
111
|
+
// The store key is not an address; the mail goes to the address it was built from.
|
|
112
|
+
to,
|
|
114
113
|
locale: invite.locale,
|
|
115
114
|
link: invite.link,
|
|
116
115
|
data: invite.data,
|
|
@@ -15,6 +15,8 @@ export interface VerificationPurposeDef {
|
|
|
15
15
|
readonly identifier: (raw: string) => string;
|
|
16
16
|
/** Declared a sign-in credential: the one thing `signInWithLink` consumes. Absent is no. */
|
|
17
17
|
readonly signIn?: boolean | undefined;
|
|
18
|
+
/** `'explicit'`: `issueVerification` mails `to`, not the identifier (an invite). Absent refuses `to`. */
|
|
19
|
+
readonly recipient?: 'explicit' | undefined;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
// A Map, never a record keyed by an attacker-reachable string: `consumeVerification` looks a
|
package/src/verify.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// tier 4 and auth is tier 2, so the app wires mail's `send` in and auth imports nothing upward.
|
|
5
5
|
|
|
6
6
|
import type { Clock } from '@ultimat3/core';
|
|
7
|
-
import { renderFixLiteral, timingSafeEqual } from '@ultimat3/core';
|
|
7
|
+
import { renderCauseValue, renderFixLiteral, timingSafeEqual } from '@ultimat3/core';
|
|
8
8
|
import type { AuthVerification, VerificationStore } from './adapter';
|
|
9
9
|
import { normaliseEmail } from './email';
|
|
10
10
|
import { AuthError } from './errors';
|
|
@@ -58,6 +58,8 @@ export interface IssueVerificationInput {
|
|
|
58
58
|
readonly purpose: VerificationPurpose;
|
|
59
59
|
/** The email address. Also the store key — one live token per purpose per address. */
|
|
60
60
|
readonly identifier: string;
|
|
61
|
+
/** Only on a purpose declared `recipient: 'explicit'`; refused on any other. Never normalised. */
|
|
62
|
+
readonly to?: string | undefined;
|
|
61
63
|
readonly locale: string;
|
|
62
64
|
readonly ttlMs?: number | undefined;
|
|
63
65
|
/** Builds the URL that carries the token. Defaults to the token alone. */
|
|
@@ -98,6 +100,13 @@ export async function issueVerification(
|
|
|
98
100
|
// the case, and each one of them is a password. It is also the address the mail is sent to, so
|
|
99
101
|
// the link goes to the inbox the account is keyed by rather than to whatever a form posted.
|
|
100
102
|
const identifier = purpose.identifier(input.identifier);
|
|
103
|
+
// Refused above the write, like the TTL: a blank recipient would leave a live row nobody can read.
|
|
104
|
+
// `to` is a door only a purpose that declared `recipient: 'explicit'` opens: a reset or sign-in
|
|
105
|
+
// link must reach the inbox the account is keyed by, even when an app spreads a request body in.
|
|
106
|
+
const explicit = purpose.recipient === 'explicit';
|
|
107
|
+
if (!explicit && input.to !== undefined) throw recipientRefused(purpose.name, 'undeclared');
|
|
108
|
+
const to = explicit ? (input.to ?? '') : identifier;
|
|
109
|
+
if (to.trim() === '') throw recipientRefused(purpose.name, 'blank');
|
|
101
110
|
await runtime.store.putVerification({
|
|
102
111
|
id: randomToken(12),
|
|
103
112
|
purpose: purpose.name,
|
|
@@ -109,7 +118,7 @@ export async function issueVerification(
|
|
|
109
118
|
});
|
|
110
119
|
await runtime.mail.send(
|
|
111
120
|
purpose.template,
|
|
112
|
-
|
|
121
|
+
to,
|
|
113
122
|
{
|
|
114
123
|
...(input.data ?? {}),
|
|
115
124
|
link: input.link?.(token) ?? token,
|
|
@@ -120,6 +129,20 @@ export async function issueVerification(
|
|
|
120
129
|
return { token, expiresAt };
|
|
121
130
|
}
|
|
122
131
|
|
|
132
|
+
const recipientRefused = (purpose: string, why: 'blank' | 'undeclared'): AuthError =>
|
|
133
|
+
new AuthError({
|
|
134
|
+
code: 'X_CONFIG_INVALID',
|
|
135
|
+
cause:
|
|
136
|
+
why === 'blank'
|
|
137
|
+
? `the ${renderCauseValue(purpose)} purpose mails to an explicit \`to\`, and it is blank or absent, so the credential has nowhere to go`
|
|
138
|
+
: `issueVerification({ to }) on the ${renderCauseValue(purpose)} purpose, which mails to the address it is keyed by; a \`to\` there could send the link to another inbox`,
|
|
139
|
+
fix:
|
|
140
|
+
why === 'blank'
|
|
141
|
+
? `await issueVerification(runtime, { purpose: ${renderFixLiteral(purpose, "'<purpose>'")}, identifier: key, to: 'ada@example.com', locale }) // name the address`
|
|
142
|
+
: "defineVerificationPurpose({ name, template, ttlMs, recipient: 'explicit' }) // or drop `to`: the identifier is the address",
|
|
143
|
+
meta: { option: 'verification.to' },
|
|
144
|
+
});
|
|
145
|
+
|
|
123
146
|
/**
|
|
124
147
|
* One error for "no such token", "already used", "expired" and "wrong token". Distinguishing
|
|
125
148
|
* them tells an attacker which address has a live reset in flight.
|
|
@@ -195,6 +218,12 @@ export interface DefineVerificationPurposeInput {
|
|
|
195
218
|
* an email-change or account-deletion link proves the same inbox but was mailed to do one job.
|
|
196
219
|
*/
|
|
197
220
|
readonly signIn?: boolean | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* `'explicit'`: the mail goes to the `to` each issue names, because the identifier is a store key
|
|
223
|
+
* and not an address (a member invite's tenant + address). Required then, never normalised.
|
|
224
|
+
* Absent: `issue` refuses a `to`, so a reset link cannot be redirected by a caller's input.
|
|
225
|
+
*/
|
|
226
|
+
readonly recipient?: 'explicit' | undefined;
|
|
198
227
|
}
|
|
199
228
|
|
|
200
229
|
export interface VerificationPurposeHandle {
|
|
@@ -229,6 +258,7 @@ export function defineVerificationPurpose(
|
|
|
229
258
|
ttlMs,
|
|
230
259
|
identifier: input.identifier ?? normaliseEmail,
|
|
231
260
|
signIn: input.signIn === true,
|
|
261
|
+
...(input.recipient === 'explicit' ? { recipient: 'explicit' as const } : {}),
|
|
232
262
|
});
|
|
233
263
|
const name = input.name;
|
|
234
264
|
return {
|