@runeditrun/rer 0.2.24 → 0.2.26
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 +16 -7
- package/cli/browser-runtime.mjs +65 -0
- package/cli/demo-host.mjs +31 -5
- package/cli/deploy-claim-request.mjs +5 -4
- package/cli/deploy-command.mjs +3 -3
- package/cli/deploy-inputs.mjs +2 -1
- package/cli/deploy.mjs +16 -4
- package/cli/export.mjs +1 -1
- package/cli/hosted-mail.mjs +23 -0
- package/cli/hosted-output.mjs +6 -2
- package/cli/hydration/browser.mjs +3 -9
- package/cli/inspect.mjs +3 -1
- package/cli/lifecycle.mjs +4 -1
- package/global/CHANGELOG.md +36 -0
- package/global/README.md +16 -7
- package/global/browser-runtime.mjs +45 -0
- package/global/cli/layout.mjs +8 -4
- package/global/main.mjs +13 -3
- package/install.sh +56 -3
- package/modules/container/README.md +11 -0
- package/modules/container/build.mjs +2 -1
- package/modules/container/demo-egress.mjs +15 -2
- package/modules/container/image-variables.mjs +27 -0
- package/modules/container/worker-engine.mjs +2 -2
- package/modules/delivery-producer/declarations.mjs +6 -1
- package/modules/delivery-producer/mail.mjs +66 -0
- package/modules/demo/label.mjs +5 -2
- package/modules/demo-host/README.md +9 -2
- package/modules/demo-host/certificate.mjs +56 -0
- package/modules/demo-host/measurement.mjs +19 -0
- package/modules/demo-host/operator.mjs +11 -6
- package/modules/demo-host/plan.mjs +1 -1
- package/modules/demo-host/worker.mjs +2 -0
- package/modules/deploy-kit/README.md +6 -4
- package/modules/deploy-kit/asset-health.mjs +28 -0
- package/modules/deploy-kit/d1-import.mjs +22 -4
- package/modules/deploy-kit/diagnostics.mjs +30 -0
- package/modules/deploy-kit/health.mjs +2 -23
- package/modules/deploy-kit/migration-ledger.mjs +6 -2
- package/modules/deploy-kit/migration-retry.mjs +91 -0
- package/modules/deploy-kit/migrations.mjs +9 -5
- package/modules/deploy-kit/owner-cli.mjs +6 -3
- package/modules/deploy-kit/owner-remove.mjs +87 -65
- package/modules/deploy-kit/provider-transport.mjs +28 -5
- package/modules/deploy-kit/provider.mjs +9 -6
- package/modules/deploy-kit/worker.mjs +5 -2
- package/modules/mail/README.md +18 -2
- package/modules/mail/src/adapters/rer/contract.mjs +5 -2
- package/modules/mail/src/adapters/rer/list-headers.mjs +44 -0
- package/modules/mail/src/core/validation.mjs +5 -2
- package/modules/mail/src/sender.mjs +1 -1
- package/modules/mail/src/unsubscribe/index.mjs +5 -5
- package/modules/operator-auth/README.md +10 -2
- package/modules/operator-auth/config.mjs +1 -0
- package/modules/operator-auth/conformance/presentation.mjs +2 -2
- package/modules/operator-auth/identity/email-link/confirmation.mjs +2 -1
- package/modules/operator-auth/identity/email-link/expiry.mjs +8 -0
- package/modules/operator-auth/identity/email-link/index.mjs +2 -1
- package/modules/operator-auth/identity/email-link/message.mjs +3 -2
- package/modules/operator-auth/index.d.mts +2 -0
- package/modules/portability/README.md +7 -2
- package/modules/portability/import-staging.mjs +45 -0
- package/modules/portability/import.mjs +8 -8
- package/modules/portability/storage.mjs +5 -2
- package/package.json +1 -1
|
@@ -25,8 +25,9 @@ async function boundedText(response, limit = 4 * 1024 * 1024, onReadError) {
|
|
|
25
25
|
export async function boundedJSON(response, limit) {
|
|
26
26
|
try { return JSON.parse(await boundedText(response,limit)); } catch (error) { if (error instanceof SyntaxError) throw new Error('malformed-response'); throw error; }
|
|
27
27
|
}
|
|
28
|
+
const redactValues = (text, values) => values.filter(Boolean).flatMap(value=>[value,encodeURIComponent(value),JSON.stringify(value).slice(1,-1)]).sort((a,b)=>b.length-a.length).reduce((value,secret)=>value.split(secret).join('[REDACTED]'),text);
|
|
28
29
|
/** Only this fixed origin and the explicitly selected account ever receive the token. */
|
|
29
|
-
export function cloudflare({ accountId, token, fetch: request = globalThis.fetch, objectDelete = deleteR2Object, timeoutMs = 30000, maxRequests = 500 }) {
|
|
30
|
+
export function cloudflare({ accountId, token, fetch: request = globalThis.fetch, objectDelete = deleteR2Object, timeoutMs = 30000, maxRequests = 500, removal = false }) {
|
|
30
31
|
assert(hexId(accountId), 'invalid-cloudflare-account-id');
|
|
31
32
|
assert(typeof token === 'string' && token.trim() && !/[\r\n]/.test(token), 'invalid-cloudflare-api-token');
|
|
32
33
|
let requests = 0;
|
|
@@ -38,8 +39,9 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
|
|
|
38
39
|
assert(!assetToken || path === '/workers/assets/upload?base64=true', 'invalid-asset-auth-target');
|
|
39
40
|
// Asset-session credentials are discovered at runtime, outside the CLI env.
|
|
40
41
|
// Preserve complete text for the CLI's remaining redaction before truncation.
|
|
41
|
-
const redactCredentials = text => [accountId,token,assetToken]
|
|
42
|
-
|
|
42
|
+
const redactCredentials = text => redactValues(text,[accountId,token,assetToken]);
|
|
43
|
+
// D1 import text keeps Cloudflare's reason, never its signed upload destinations.
|
|
44
|
+
const redactAuth = text => /\/r2\/buckets\/[^/]+\/objects(?:[/?]|$)/.test(path) ? '[R2 object details omitted]' : /\/d1\/database\/[^/]+\/import$/.test(path) ? redactCredentials(text).replace(/\bhttps?:\/\/\S+/gi,'[URL omitted]') : redactCredentials(text);
|
|
43
45
|
const operation = `${method} ${path.split('?')[0].replace(/(\/r2\/buckets\/[^/]+\/objects)\/.*/, '$1/[object]')}`;
|
|
44
46
|
const endpoint = redactCredentials(`https://api.cloudflare.com/client/v4${zone ? '' : '/accounts/[REDACTED]'}${operation.slice(method.length + 1)}`);
|
|
45
47
|
const transportFailure = (cause, attempts, status = null) => {
|
|
@@ -49,13 +51,14 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
|
|
|
49
51
|
error.providerTransport = {operation:redactCredentials(operation),endpoint,attempts,status,reason:transportReason(cause)};
|
|
50
52
|
return recordDeployFailure(error,{output:redactAuth(transportOutput(cause))});
|
|
51
53
|
};
|
|
52
|
-
const {response,
|
|
54
|
+
const {response,output = ''} = await providerResponse({method,timeoutMs,callerSignal,removal,
|
|
55
|
+
replayableAsset:method === 'POST' && (/^\/workers\/scripts\/[^/]+\/assets-upload-session$/.test(path) || path === '/workers/assets/upload?base64=true'),
|
|
53
56
|
reserveRetry:() => requests < maxRequests && (++requests, true),failure:transportFailure,
|
|
57
|
+
consume:(response,attempts) => response.body ? boundedText(response,undefined,cause => transportFailure(cause,attempts,response.status)) : '',
|
|
54
58
|
send:signal => isR2ObjectDelete(path, method) ? objectDelete(`/client/v4/accounts/${accountId}${path}`, {headers:{Authorization:`Bearer ${token}`},signal}) : request(zone ? `https://api.cloudflare.com/client/v4${path}` : `https://api.cloudflare.com/client/v4/accounts/${accountId}${path}`, {
|
|
55
59
|
method, redirect: 'error', signal, headers: { Authorization: `Bearer ${assetToken ?? token}`, ...(body && !(body instanceof FormData) ? { 'Content-Type':'application/json' } : {}) },
|
|
56
60
|
...(body === undefined ? {} : { body: body instanceof FormData ? body : JSON.stringify(body) }),
|
|
57
61
|
})});
|
|
58
|
-
const output = response.body ? await boundedText(response,undefined,cause => transportFailure(cause,attempts,response.status)) : '';
|
|
59
62
|
// A successful DELETE may have no response body (including HTTP 200).
|
|
60
63
|
// Nonempty replies and all other methods still require the API envelope.
|
|
61
64
|
if (method === 'DELETE' && response.ok && output === '') return { success: true, result: null };
|
|
@@ -127,6 +130,6 @@ export function cloudflare({ accountId, token, fetch: request = globalThis.fetch
|
|
|
127
130
|
assert(response.status === 200, 'd1-import-upload-failed');
|
|
128
131
|
assert(response.headers.get('etag')?.replace(/^"|"$/g, '') === etag, 'd1-import-upload-etag-mismatch');
|
|
129
132
|
}
|
|
130
|
-
return { accountId, envelope, list, importSql(id, sql) { return importD1({envelope,upload}, id, sql); }, request:requestResult,
|
|
133
|
+
return { accountId, envelope, list, importSql(id, sql) { return importD1({envelope,upload,redact:text => redactValues(text,[accountId,token])}, id, sql); }, request:requestResult,
|
|
131
134
|
zoneRequest(path, options = {}) { return requestResult(path, { ...options, zone: true }); } };
|
|
132
135
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { nameAssetFailure } from './diagnostics.mjs';
|
|
1
2
|
import { extname } from 'node:path';
|
|
2
3
|
import { assert, hash, hexId, uuid } from './validation.mjs';
|
|
3
4
|
import { moduleType, assetType } from './artifact.mjs';
|
|
@@ -61,7 +62,8 @@ export async function uploadAssets(api, worker, files) {
|
|
|
61
62
|
manifest[`/${file.path}`] = {hash:digest,size:Buffer.from(file.base64,'base64').length};
|
|
62
63
|
byHash.set(digest,file);
|
|
63
64
|
}
|
|
64
|
-
const session = await api.request(`/workers/scripts/${worker}/assets-upload-session`,{method:'POST',body:{manifest}})
|
|
65
|
+
const session = await api.request(`/workers/scripts/${worker}/assets-upload-session`,{method:'POST',body:{manifest}})
|
|
66
|
+
.catch(error => { throw nameAssetFailure(error,files.map(file => file.path)); });
|
|
65
67
|
assert(typeof session.jwt === 'string' && session.jwt && Array.isArray(session.buckets),'invalid-asset-session');
|
|
66
68
|
let completion = session.buckets.length ? null : session.jwt;
|
|
67
69
|
const seen = new Set();
|
|
@@ -72,7 +74,8 @@ export async function uploadAssets(api, worker, files) {
|
|
|
72
74
|
assert(byHash.has(key) && !seen.has(key),'invalid-asset-request'); seen.add(key);
|
|
73
75
|
const file = byHash.get(key); data.set(key,new Blob([file.base64],{type:assetType(file.path)}),file.path.split('/').at(-1));
|
|
74
76
|
}
|
|
75
|
-
const uploaded = await api.request('/workers/assets/upload?base64=true',{method:'POST',body:data,assetToken:session.jwt})
|
|
77
|
+
const uploaded = await api.request('/workers/assets/upload?base64=true',{method:'POST',body:data,assetToken:session.jwt})
|
|
78
|
+
.catch(error => { throw nameAssetFailure(error,bucket.map(key => byHash.get(key).path)); });
|
|
76
79
|
if (uploaded.jwt) completion = uploaded.jwt;
|
|
77
80
|
}
|
|
78
81
|
assert(typeof completion === 'string' && completion,'incomplete-asset-upload');
|
package/modules/mail/README.md
CHANGED
|
@@ -161,8 +161,24 @@ values are refused. `List-Unsubscribe` (one or two `<https:…>`/`<mailto:…>`
|
|
|
161
161
|
entries, at most 2,000 characters) travels as `listUnsubscribe`, and
|
|
162
162
|
`List-Unsubscribe-Post: List-Unsubscribe=One-Click` as `listUnsubscribePost:
|
|
163
163
|
true`, which requires an HTTPS entry. The structured `unsubscribe` request
|
|
164
|
-
assembles the same headers.
|
|
165
|
-
|
|
164
|
+
assembles the same headers.
|
|
165
|
+
|
|
166
|
+
`List-Id`, `List-Archive`, `List-Help`, `In-Reply-To` and `References` travel as
|
|
167
|
+
`listId`, `listArchive`, `listHelp`, `inReplyTo` and `references`, respectively.
|
|
168
|
+
They match platform's relay validation at `098ba40` (`src/managed-mail/headers.ts`):
|
|
169
|
+
each is a string of at most 2,000 characters, without newlines or controls.
|
|
170
|
+
`List-Id` accepts an optional ASCII phrase or quoted display name followed by an
|
|
171
|
+
angle-bracketed ASCII dot-atom identifier containing a dot (at most 255
|
|
172
|
+
characters). `List-Archive` and `List-Help` accept one or two angle-bracketed
|
|
173
|
+
HTTPS or mailto URLs, using the relay's URL and mailbox checks. These three
|
|
174
|
+
headers allow separator tabs. `In-Reply-To` accepts exactly one `<local@domain>`
|
|
175
|
+
message ID with ASCII dot-atoms or a bracketed domain literal. `References`
|
|
176
|
+
accepts 1–20 such IDs separated by ASCII spaces, without leading/trailing
|
|
177
|
+
spaces, tabs or commas. Invalid values fail locally with `invalid_list_id`,
|
|
178
|
+
`invalid_list_archive`, `invalid_list_help`, `invalid_in_reply_to` or
|
|
179
|
+
`invalid_references`. Values are preserved; raw headers are never forwarded.
|
|
180
|
+
Other recipients, attachments, reply-to and every other header are unsupported
|
|
181
|
+
and fail before dispatch.
|
|
166
182
|
|
|
167
183
|
HTTP 202 returns `accepted` with no provider message ID. HTTP 400, 401, 402,
|
|
168
184
|
403 and 413 return `rejected`, and so does any 3xx (`provider_redirected`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fail } from '../../core/errors.mjs';
|
|
2
|
+
import { rerListHeaderField } from './list-headers.mjs';
|
|
2
3
|
|
|
3
4
|
// The relay's own List-Unsubscribe rule: one or two <https:…>/<mailto:…> entries.
|
|
4
5
|
const listEntries = /^[ \t]*<([^<>\s]+)>[ \t]*(?:,[ \t]*<([^<>\s]+)>[ \t]*)?$/;
|
|
@@ -17,7 +18,9 @@ export function rerHeaderFields(headers = {}) {
|
|
|
17
18
|
const fields = {};
|
|
18
19
|
for (const [name, value] of Object.entries(headers)) {
|
|
19
20
|
const lower = name.toLowerCase();
|
|
20
|
-
|
|
21
|
+
const field = rerListHeaderField(lower, value);
|
|
22
|
+
if (field) fields[field] = value;
|
|
23
|
+
else if (lower === 'auto-submitted') {
|
|
21
24
|
if (value.trim().toLowerCase() !== 'auto-generated') fail('unsupported_provider_setting');
|
|
22
25
|
} else if (lower === 'list-unsubscribe') fields.listUnsubscribe = value;
|
|
23
26
|
else if (lower === 'list-unsubscribe-post') {
|
|
@@ -41,7 +44,7 @@ export function rerHeaderFields(headers = {}) {
|
|
|
41
44
|
export function validateRerMessage(message) {
|
|
42
45
|
if (message.to.length !== 1) fail('rer_one_recipient_required');
|
|
43
46
|
// The relay cannot preserve these features. Refuse them rather than silently
|
|
44
|
-
// dropping recipients
|
|
47
|
+
// dropping recipients or attachments.
|
|
45
48
|
if (['cc', 'bcc', 'replyTo', 'attachments'].some(field => message[field] !== undefined)) fail('unsupported_provider_setting');
|
|
46
49
|
rerHeaderFields(message.headers);
|
|
47
50
|
if (!message.subject.trim() || message.subject.length > 200) fail('invalid_subject');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { fail } from '../../core/errors.mjs';
|
|
2
|
+
|
|
3
|
+
// Match platform 098ba4034b80c1d704cf96398a41da94f2b879af:
|
|
4
|
+
// src/managed-mail/headers.ts:3-8,21-40,44-50 and src/platform/mail.ts:20.
|
|
5
|
+
const atom = "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+";
|
|
6
|
+
const dotAtom = atom + '(?:\\.' + atom + ')*';
|
|
7
|
+
const word = atom + '|"(?:[\\x20-\\x21\\x23-\\x5b\\x5d-\\x7e]|\\\\[\\x20-\\x7e])*"';
|
|
8
|
+
const listIdPattern = new RegExp('^[ \\t]*(?:(?:' + word + ')(?:[ \\t]+(?:' + word + '))*[ \\t]*)?<(' + atom + '(?:\\.' + atom + ')+)>[ \\t]*$');
|
|
9
|
+
const messageIdPattern = new RegExp('^<' + dotAtom + '@(?:' + dotAtom + '|\\[[\\x21-\\x5a\\x5e-\\x7e]*\\])>$');
|
|
10
|
+
const controls = /[\r\n\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/;
|
|
11
|
+
const listEntries = /^[ \t]*<([^<>\s]+)>[ \t]*(?:,[ \t]*<([^<>\s]+)>[ \t]*)?$/;
|
|
12
|
+
const mailbox = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
|
|
13
|
+
const fields = new Map([
|
|
14
|
+
['list-id', ['listId', 'invalid_list_id']],
|
|
15
|
+
['list-archive', ['listArchive', 'invalid_list_archive']],
|
|
16
|
+
['list-help', ['listHelp', 'invalid_list_help']],
|
|
17
|
+
['in-reply-to', ['inReplyTo', 'invalid_in_reply_to']],
|
|
18
|
+
['references', ['references', 'invalid_references']],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
/** Validate a supported list/thread header and return its relay field, or null. */
|
|
22
|
+
export function rerListHeaderField(name, value) {
|
|
23
|
+
const mapping = fields.get(name.toLowerCase());
|
|
24
|
+
if (!mapping) return null;
|
|
25
|
+
const [field, code] = mapping;
|
|
26
|
+
if (typeof value !== 'string' || value.length > 2000 || controls.test(value)) fail(code);
|
|
27
|
+
if (field === 'listId') {
|
|
28
|
+
const match = listIdPattern.exec(value);
|
|
29
|
+
if (!match || match[1].length > 255) fail(code);
|
|
30
|
+
} else if (field === 'listArchive' || field === 'listHelp') {
|
|
31
|
+
const entries = value.match(listEntries);
|
|
32
|
+
if (!entries) fail(code);
|
|
33
|
+
for (const entry of entries.slice(1).filter(Boolean)) {
|
|
34
|
+
let url;
|
|
35
|
+
try { url = new URL(entry); } catch { fail(code); }
|
|
36
|
+
if (/^https:\/\//i.test(entry) && url.protocol === 'https:' && url.hostname && !entry.includes('\\')) continue;
|
|
37
|
+
if (url.protocol !== 'mailto:' || !mailbox.test(url.pathname)) fail(code);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
const ids = field === 'references' ? value.split(/ +/) : [value];
|
|
41
|
+
if (!value || ids.length > (field === 'references' ? 20 : 1) || ids.some(id => !messageIdPattern.test(id))) fail(code);
|
|
42
|
+
}
|
|
43
|
+
return field;
|
|
44
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { fail } from './errors.mjs';
|
|
2
2
|
import { validateMessagingConfig, validateMessagingResult, identity, rfc3339 } from '../adapters/messaging/contract.mjs';
|
|
3
3
|
import { validateRerConfig, validateRerMessage } from '../adapters/rer/contract.mjs';
|
|
4
|
+
import { rerListHeaderField } from '../adapters/rer/list-headers.mjs';
|
|
4
5
|
|
|
5
6
|
const providers = ['sendgrid', 'resend', 'cloudflare', 'rer', 'development', 'messaging'];
|
|
6
7
|
const controls = /[\x00-\x1f\x7f]/;
|
|
@@ -62,7 +63,7 @@ export function parseAddress(value) {
|
|
|
62
63
|
return name ? { email, name } : { email };
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
export function validateHeaders(headers = {}) {
|
|
66
|
+
export function validateHeaders(headers = {}, provider) {
|
|
66
67
|
record(headers, 'invalid_headers');
|
|
67
68
|
const names = new Set();
|
|
68
69
|
for (const name of Reflect.ownKeys(headers)) {
|
|
@@ -70,6 +71,8 @@ export function validateHeaders(headers = {}) {
|
|
|
70
71
|
const lower = name.toLowerCase();
|
|
71
72
|
if (reservedHeaders.has(lower) || names.has(lower)) fail('reserved_or_duplicate_header');
|
|
72
73
|
names.add(lower);
|
|
74
|
+
// These relay grammars allow separator tabs and report field-specific errors.
|
|
75
|
+
if (provider === 'rer' && rerListHeaderField(lower, headers[name])) continue;
|
|
73
76
|
bounded(headers[name], 8192, 'invalid_header_value', true);
|
|
74
77
|
}
|
|
75
78
|
return headers;
|
|
@@ -128,7 +131,7 @@ export function validateMessage(message, provider) {
|
|
|
128
131
|
bounded(message.subject, 998, 'invalid_subject', true);
|
|
129
132
|
for (const field of ['text', 'html']) if (message[field] !== undefined && typeof message[field] !== 'string') fail('invalid_body');
|
|
130
133
|
if (!message.text?.trim() && !message.html?.trim()) fail('body_required');
|
|
131
|
-
if (message.headers !== undefined) validateHeaders(message.headers);
|
|
134
|
+
if (message.headers !== undefined) validateHeaders(message.headers, provider);
|
|
132
135
|
if (message.attachments !== undefined) {
|
|
133
136
|
if (!Array.isArray(message.attachments)) fail('invalid_attachments');
|
|
134
137
|
for (const attachment of message.attachments) validateAttachment(attachment);
|
|
@@ -26,7 +26,7 @@ export function createMailSender(config, dependencies = {}) {
|
|
|
26
26
|
validateMessage(message, configured.provider);
|
|
27
27
|
let snapshot;
|
|
28
28
|
try { snapshot = structuredClone(message); } catch { fail('invalid_message'); }
|
|
29
|
-
const prepared = applyUnsubscribeHeaders(snapshot);
|
|
29
|
+
const prepared = applyUnsubscribeHeaders(snapshot, configured.provider);
|
|
30
30
|
validateMessage(prepared, configured.provider);
|
|
31
31
|
return validateSendResult(await transport(configured, prepared, host), configured.provider);
|
|
32
32
|
},
|
|
@@ -104,8 +104,8 @@ function addOrCheckHeader(headers, name, expected) {
|
|
|
104
104
|
headers[name] = expected;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
function assemble(message) {
|
|
108
|
-
validateMessage(message);
|
|
107
|
+
function assemble(message, provider) {
|
|
108
|
+
validateMessage(message, provider);
|
|
109
109
|
|
|
110
110
|
const headers = { ...(message.headers ?? {}) };
|
|
111
111
|
validateExistingListHeaders(headers);
|
|
@@ -127,14 +127,14 @@ function assemble(message) {
|
|
|
127
127
|
|
|
128
128
|
const prepared = { ...message, headers };
|
|
129
129
|
delete prepared.unsubscribe;
|
|
130
|
-
validateMessage(prepared);
|
|
130
|
+
validateMessage(prepared, provider);
|
|
131
131
|
return prepared;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/** Return a copy with validated unsubscribe headers assembled and the request consumed. */
|
|
135
|
-
export function applyUnsubscribeHeaders(message) {
|
|
135
|
+
export function applyUnsubscribeHeaders(message, provider) {
|
|
136
136
|
try {
|
|
137
|
-
return assemble(message);
|
|
137
|
+
return assemble(message, provider);
|
|
138
138
|
} catch (error) {
|
|
139
139
|
if (error instanceof MailValidationError) throw error;
|
|
140
140
|
fail('invalid_message');
|
|
@@ -151,7 +151,8 @@ Do not log confirmation URLs, input tokens, cookies or provider message bodies.
|
|
|
151
151
|
GET/HEAD confirmation uses a self-contained, responsive document. A magic link
|
|
152
152
|
says “Confirm sign-in to Example”; an invitation says “Accept your invitation to
|
|
153
153
|
Example”. Both explain that the link works once and show its remaining lifetime,
|
|
154
|
-
rounded up to
|
|
154
|
+
rounded up to days for lifetimes of a day or more, otherwise minutes (singular
|
|
155
|
+
for one day or minute). The sole primary form button is
|
|
155
156
|
“Confirm”. Only its hidden POST field contains the token. Invalid, expired,
|
|
156
157
|
consumed or unauthorized links return a styled 400 document with “Request a new
|
|
157
158
|
link” pointing to the configured sign-in page. HEAD has the same status and
|
|
@@ -219,7 +220,8 @@ Cookies are host-only, Path=/, HttpOnly, SameSite=Lax; production uses Secure an
|
|
|
219
220
|
127.0.0.1 or [::1] and uses `operator_session_local_<port>` (for example
|
|
220
221
|
`operator_session_local_8787`): browsers keep cookies per host, not per port, so
|
|
221
222
|
checkouts side by side on one loopback host each keep their own session. Session expiry defaults to
|
|
222
|
-
7 days (maximum 30), links to 15 minutes (maximum 60)
|
|
223
|
+
7 days (maximum 30), sign-in and step-up links to 15 minutes (maximum 60), and
|
|
224
|
+
invitations to 7 days; no silent sliding renewal.
|
|
223
225
|
`returnTo` must be a local absolute path; unsafe values become `/app`. It is stored
|
|
224
226
|
with the token, and cannot be replaced on confirmation. Auth methods never return
|
|
225
227
|
raw link tokens. `CompletedSession.cookie` is server-only and must only be emitted
|
|
@@ -309,6 +311,12 @@ The exported `isActiveOperator` is the shared admission predicate.
|
|
|
309
311
|
|
|
310
312
|
## Mail, OIDC, password and review seams
|
|
311
313
|
|
|
314
|
+
Invitation links default to seven days (604800 seconds). `invitationSeconds`
|
|
315
|
+
can shorten that lifetime, up to the seven-day maximum. `linkSeconds` remains
|
|
316
|
+
independent: sign-in and step-up links default to 15 minutes and allow at most
|
|
317
|
+
one hour. Invitation mail and confirmation pages describe the longer lifetime
|
|
318
|
+
in days; single use, cancellation and issuer-authority checks still apply.
|
|
319
|
+
|
|
312
320
|
Magic and invitation mail include both plain text and HTML. Each part has exactly
|
|
313
321
|
one confirmation URL; the HTML part presents it as a button with inline mail-safe
|
|
314
322
|
styling. The body sets Arial; its centered main content has a 480px maximum width
|
|
@@ -28,6 +28,7 @@ export function configure(input) {
|
|
|
28
28
|
allowList: input.allowList === undefined ? undefined : input.allowList.map(normalizeEmail),
|
|
29
29
|
sessionSeconds: seconds(input.sessionSeconds, 7 * 86400, 30 * 86400),
|
|
30
30
|
linkSeconds: seconds(input.linkSeconds, 900, 3600),
|
|
31
|
+
invitationSeconds: seconds(input.invitationSeconds, 7 * 86400, 7 * 86400),
|
|
31
32
|
reviewSeconds: seconds(input.reviewSeconds, 3600, 3600),
|
|
32
33
|
limitWindowSeconds: seconds(input.limitWindowSeconds, 900, 86400),
|
|
33
34
|
ipLimit: seconds(input.ipLimit, 30, 10000), emailLimit: seconds(input.emailLimit, 5, 1000),
|
|
@@ -35,7 +35,7 @@ export async function checkConfirmation(response, { kind, productName, minutes =
|
|
|
35
35
|
expect(html.includes(escape(productName)), 'escaped product name');
|
|
36
36
|
if (valid) {
|
|
37
37
|
expect(html.includes(`<h1>${kind === 'invite' ? 'Accept your invitation to' : 'Confirm sign-in to'} ${escape(productName)}</h1>`), 'plain confirmation heading');
|
|
38
|
-
expect(html.includes(`This link works once and expires in ${minutes} minutes.`), 'preview lifetime');
|
|
38
|
+
expect(html.includes(`This link works once and expires in ${kind === 'invite' ? '7 days' : `${minutes} minutes`}.`), 'preview lifetime');
|
|
39
39
|
expect(html.includes('<button type="submit">Confirm</button>'), 'explicit confirmation control');
|
|
40
40
|
expect(html.includes(`<input type="hidden" name="token" value="${token}">`) && html.split(token).length === 2, 'token appears only in hidden field');
|
|
41
41
|
} else {
|
|
@@ -47,7 +47,7 @@ export function checkMail(message, { kind, productName, token }) {
|
|
|
47
47
|
expect(message.subject === (kind === 'invite' ? `You're invited to ${productName}` : `Your sign-in link for ${productName}`), 'plain mail subject');
|
|
48
48
|
expect(!message.subject.includes(token), 'subject contains no credential');
|
|
49
49
|
for (const part of [message.text, message.html]) {
|
|
50
|
-
expect(typeof part === 'string' && part.includes(
|
|
50
|
+
expect(typeof part === 'string' && part.includes(`This link works once and expires in ${kind === 'invite' ? '7 days' : '15 minutes'}.`), 'multipart expiry');
|
|
51
51
|
expect(part.split(token).length === 2 && (part.match(/https?:\/\//g) ?? []).length === 1, 'one confirmation URL per part');
|
|
52
52
|
}
|
|
53
53
|
expect((message.html.match(/<a /g) ?? []).length === 1 && message.html.includes('>Confirm</a>'), 'one confirmation mail button');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { escapeHtml } from '../../http.mjs';
|
|
2
2
|
import { pageResponse } from '../../page.mjs';
|
|
3
|
+
import { linkExpiry } from './expiry.mjs';
|
|
3
4
|
|
|
4
5
|
const HEADINGS = { invite: 'Accept your invitation to', magic: 'Confirm sign-in to', step_up: "Confirm it's you in", owner: 'Sign in as the owner of' };
|
|
5
6
|
|
|
@@ -7,7 +8,7 @@ export async function confirmationResponse({ branding, preview, token, method, a
|
|
|
7
8
|
const product = escapeHtml(branding.productName);
|
|
8
9
|
const heading = preview ? `${HEADINGS[preview.kind]} ${product}` : 'This link is invalid or expired';
|
|
9
10
|
const content = preview
|
|
10
|
-
? `<p>This link works once and expires in ${preview.expiresInMinutes}
|
|
11
|
+
? `<p>This link works once and expires in ${linkExpiry(preview.expiresInMinutes)}.</p><form method="post" action="${escapeHtml(action)}"><input type="hidden" name="token" value="${escapeHtml(token)}"><button type="submit">Confirm</button></form>`
|
|
11
12
|
: `<p>This link may have expired or already been used. Request a new link to continue.</p><a class="action" href="${escapeHtml(branding.signInPath)}">Request a new link</a>`;
|
|
12
13
|
// Native form POSTs need their Origin; never disclose the token path/query.
|
|
13
14
|
return pageResponse({ branding, heading, content, status: preview ? 200 : 400, method, referrer: preview ? 'strict-origin' : undefined });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Mail and confirmation pages describe the same configured/remaining lifetime.
|
|
2
|
+
export function linkExpiry(minutes) {
|
|
3
|
+
if (minutes >= 1440) {
|
|
4
|
+
const days = Math.ceil(minutes / 1440);
|
|
5
|
+
return `${days} ${days === 1 ? 'day' : 'days'}`;
|
|
6
|
+
}
|
|
7
|
+
return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`;
|
|
8
|
+
}
|
|
@@ -36,7 +36,8 @@ export function createEmailLinkLifecycle({ config: input, clock = Date.now, mail
|
|
|
36
36
|
}
|
|
37
37
|
async function newToken(kind, returnTo) {
|
|
38
38
|
const token = opaqueToken();
|
|
39
|
-
|
|
39
|
+
const lifetime = kind === 'invite' ? config.invitationSeconds : config.linkSeconds;
|
|
40
|
+
return { id: crypto.randomUUID(), token, hash: await hash('link', token), kind, returnTo, expiresAt: clock() + lifetime * 1000 };
|
|
40
41
|
}
|
|
41
42
|
// The email link: the app's own proof that a person holds an address.
|
|
42
43
|
async function sendLink(email, token, revoke = () => store.revokeLink(token.id, clock())) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { accentInk } from '../../branding.mjs';
|
|
2
2
|
import { escapeHtml } from '../../http.mjs';
|
|
3
|
+
import { linkExpiry } from './expiry.mjs';
|
|
3
4
|
|
|
4
5
|
export function linkMessage(config, token, url) {
|
|
5
6
|
const { productName, accentColor } = config.branding;
|
|
6
7
|
const invitation = token.kind === 'invite', stepUp = token.kind === 'step_up';
|
|
7
8
|
const action = invitation ? 'accept your invitation to' : stepUp ? 'confirm a sensitive change in' : 'sign in to';
|
|
8
|
-
const minutes = config.linkSeconds / 60;
|
|
9
|
-
const expiry = `This link works once and expires in ${minutes}
|
|
9
|
+
const minutes = (invitation ? config.invitationSeconds : config.linkSeconds) / 60;
|
|
10
|
+
const expiry = `This link works once and expires in ${linkExpiry(minutes)}.`;
|
|
10
11
|
const heading = invitation ? `Accept your invitation to ${productName}` : stepUp ? `Confirm it's you in ${productName}` : `Confirm sign-in to ${productName}`;
|
|
11
12
|
return {
|
|
12
13
|
subject: invitation ? `You're invited to ${productName}` : stepUp ? `Confirm it's you in ${productName}` : `Your sign-in link for ${productName}`,
|
|
@@ -46,6 +46,8 @@ export interface AuthConfig {
|
|
|
46
46
|
origin: string; OWNER_EMAIL: string; SESSION_SECRET: string; SETUP_TOKEN?: string; MAIL_FROM?: string;
|
|
47
47
|
/** Local HTTP is allowed only for literal localhost, 127.0.0.1 or [::1] with matching Host. */
|
|
48
48
|
local?: boolean; allowList?: string[]; sessionSeconds?: number; linkSeconds?: number;
|
|
49
|
+
/** Invitation lifetime in seconds, up to seven days (the default); independent of sign-in/step-up links. */
|
|
50
|
+
invitationSeconds?: number;
|
|
49
51
|
review?: { enabled: boolean; operatorEmail: string }; reviewSeconds?: number;
|
|
50
52
|
limitWindowSeconds?: number; ipLimit?: number; emailLimit?: number;
|
|
51
53
|
/** Issuers the original admitVerifiedIdentity/createIdentityAdmission seams accept. */
|
|
@@ -301,8 +301,12 @@ transactions remain atomic.
|
|
|
301
301
|
download streams completed jobs. Abort removes snapshots and stored parts.
|
|
302
302
|
|
|
303
303
|
`imports.create(manifest,actor?)` creates staging under one durable import lock.
|
|
304
|
-
Upload parts strictly in order.
|
|
305
|
-
|
|
304
|
+
Upload parts strictly in order. Each upload stages rows and archived JSON in
|
|
305
|
+
batches bounded by D1 transport bytes, checkpointing each batch atomically.
|
|
306
|
+
A same-index/same-hash retry resumes an interrupted part or acknowledges a finished
|
|
307
|
+
part; different content returns 409. Reassembled bytes pass the part checksum
|
|
308
|
+
before completion advances. Staged data stays private until finalization.
|
|
309
|
+
Finalize requires the closing `archiveHash` and verifies all
|
|
306
310
|
parts, semantic contents, destination
|
|
307
311
|
emptiness, erasure and product invariants. R2 ownership is recorded after the
|
|
308
312
|
empty-namespace check. Verified object writes precede one atomic D1 batch, with
|
|
@@ -439,6 +443,7 @@ modules/portability/migration-statements.mjs
|
|
|
439
443
|
modules/portability/legacy-safety.mjs
|
|
440
444
|
modules/portability/export.mjs
|
|
441
445
|
modules/portability/import.mjs
|
|
446
|
+
modules/portability/import-staging.mjs
|
|
442
447
|
modules/portability/payloads.mjs
|
|
443
448
|
modules/portability/journal.mjs
|
|
444
449
|
modules/portability/http.mjs
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RPC_LIMIT, rpcSize, rpcSizeBytes } from '../d1-transport/index.mjs';
|
|
2
|
+
import { canonicalJson } from './hash.mjs';
|
|
3
|
+
import { statement, save, readPart, insist } from './storage.mjs';
|
|
4
|
+
import { checkPart } from './format.mjs';
|
|
5
|
+
|
|
6
|
+
const combine=(a,b)=>({utf8:a.utf8+b.utf8-2,units:a.units+b.units-2,hasWide:a.hasWide||b.hasWide});
|
|
7
|
+
const guardSql=`INSERT INTO rer_portability_guard(value) SELECT CASE WHEN (
|
|
8
|
+
EXISTS(SELECT 1 FROM rer_portability_jobs WHERE id=? AND phase='staging' AND completed=? AND metadata=?)
|
|
9
|
+
AND (SELECT import_job FROM rer_portability_state WHERE id=1)=?
|
|
10
|
+
) THEN 1 ELSE 0 END`;
|
|
11
|
+
|
|
12
|
+
// Rows and the archived JSON share the same durable cursor. Each checkpoint
|
|
13
|
+
// commits with its writes; retries cannot duplicate rows, even after a lost ACK.
|
|
14
|
+
// Product tables remain untouched until finalizeImport's atomic publication.
|
|
15
|
+
export async function stagePart(context,row,part,queries,stagedCounts) {
|
|
16
|
+
const {db,config}=context;
|
|
17
|
+
const pending=row.metadata.pendingPart;
|
|
18
|
+
insist(!pending || (pending.index===part.index && pending.sha256===part.sha256),'part_conflict',409);
|
|
19
|
+
let next=pending?.next??0;
|
|
20
|
+
while(next<queries.length) {
|
|
21
|
+
const before=canonicalJson(row.metadata),chunk=[];
|
|
22
|
+
// Reserve the largest cursor for this part before admitting any data.
|
|
23
|
+
row.metadata.pendingPart={index:part.index,sha256:part.sha256,next:queries.length};
|
|
24
|
+
const guard={sql:guardSql,params:[row.id,row.completed,before,row.id]};
|
|
25
|
+
const checkpoint={sql:'UPDATE rer_portability_jobs SET phase=?,completed=?,metadata=? WHERE id=?',params:[row.phase,row.completed,canonicalJson(row.metadata),row.id]};
|
|
26
|
+
let size=rpcSize([guard,checkpoint,{sql:'DELETE FROM rer_portability_guard'}]),end=next;
|
|
27
|
+
for(;end<queries.length;end++) {
|
|
28
|
+
const candidate=combine(size,rpcSize([queries[end]]));
|
|
29
|
+
if(rpcSizeBytes(candidate)>RPC_LIMIT)break;
|
|
30
|
+
size=candidate;chunk.push(queries[end]);
|
|
31
|
+
}
|
|
32
|
+
insist(end>next,'D1_RPC_TRANSPORT_LIMIT',413);
|
|
33
|
+
row.metadata.pendingPart.next=end;
|
|
34
|
+
await db.batch([statement(db,guard.sql,...guard.params),...chunk.map(q=>statement(db,q.sql,...q.params)),save(db,row),db.prepare('DELETE FROM rer_portability_guard')]);
|
|
35
|
+
next=end;
|
|
36
|
+
}
|
|
37
|
+
// Authenticate the reassembled stored bytes before acknowledging the part.
|
|
38
|
+
const stored=await readPart(db,row.id,part.index);
|
|
39
|
+
await checkPart(stored,part.index,config.partBytes);insist(stored.sha256===part.sha256,'part_checksum');
|
|
40
|
+
const before=canonicalJson(row.metadata),completed=row.completed;
|
|
41
|
+
delete row.metadata.pendingPart;row.metadata.stagedCounts=stagedCounts;row.completed++;
|
|
42
|
+
await db.batch([statement(db,guardSql,row.id,completed,before,row.id),
|
|
43
|
+
statement(db,'INSERT INTO rer_portability_parts VALUES(?,?,?)',row.id,part.index,part.sha256),
|
|
44
|
+
save(db,row),db.prepare('DELETE FROM rer_portability_guard')]);
|
|
45
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { all, statement, state, guard, job, save,
|
|
1
|
+
import { all, statement, state, guard, job, save, partQueries, parts, readPart, cleanCopies, quote, stream, insist, run } from './storage.mjs';
|
|
2
|
+
import { stagePart } from './import-staging.mjs';
|
|
2
3
|
import { refuseProviderData } from './provider-data.mjs';
|
|
3
4
|
import { refuseDevData } from './dev-data.mjs';
|
|
4
5
|
import { catalogue, validateRow, bindCell, writableColumns } from './catalogue.mjs';
|
|
@@ -69,20 +70,19 @@ export async function uploadPart(context,id,index,part) {
|
|
|
69
70
|
insist(entry && item.offset+unbase64(item.data).length<=entry.size,'binary_inventory');
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
const stagedCounts=Object.assign(Object.create(null),row.metadata.stagedCounts);
|
|
73
74
|
for(const [table,group] of groups) {
|
|
74
75
|
const width=group.rows[0].length,count=Math.min(30,Math.floor(100/width));
|
|
75
76
|
insist(count>0,'unsupported_restore_width:'+table);
|
|
76
|
-
const copy=row.metadata.copies[table],first=(
|
|
77
|
+
const copy=row.metadata.copies[table],first=(stagedCounts[table]??0)+1;
|
|
77
78
|
for(let start=0;start<group.rows.length;start+=count) {
|
|
78
79
|
const chunk=group.rows.slice(start,start+count);
|
|
79
|
-
inserts.push(
|
|
80
|
-
inserts.push(
|
|
80
|
+
inserts.push({sql:`INSERT INTO ${quote(copy)} (${group.columns}) VALUES${chunk.map(()=> '('+Array(width).fill('?').join(',')+')').join(',')}`,params:chunk.flat()});
|
|
81
|
+
inserts.push({sql:`INSERT INTO ${quote(sidecar(copy))} VALUES${chunk.map((_,i)=>`(?,${first+start+i},?,?)`).join(',')}`,params:group.metadata.slice(start,start+count).flat()});
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
stagedCounts[table]=first-1+group.rows.length;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
try{await db.batch([guard(db,'(SELECT completed FROM rer_portability_jobs WHERE id=?)=?',id,before),...inserts,...partStatements(db,id,part),save(db,row),db.prepare('DELETE FROM rer_portability_guard')]);}
|
|
85
|
+
try{await stagePart(context,row,part,[...inserts,...partQueries(id,part).slice(1)],stagedCounts);}
|
|
86
86
|
catch(e){const duplicate=await statement(db,'SELECT sha256 FROM rer_portability_parts WHERE job=? AND idx=?',id,index).first();if(!duplicate || duplicate.sha256!==part.sha256)throw e;}
|
|
87
87
|
return importStatus(context,id);
|
|
88
88
|
}
|
|
@@ -26,12 +26,15 @@ export function save(db,row) {
|
|
|
26
26
|
return statement(db,'UPDATE rer_portability_jobs SET phase=?,completed=?,metadata=? WHERE id=?',row.phase,row.completed,canonicalJson(row.metadata),row.id);
|
|
27
27
|
}
|
|
28
28
|
export function partStatements(db,id,part) {
|
|
29
|
-
|
|
29
|
+
return partQueries(id,part).map(({sql,params})=>statement(db,sql,...params));
|
|
30
|
+
}
|
|
31
|
+
export function partQueries(id,part) {
|
|
32
|
+
const json=canonicalJson(part), result=[{sql:'INSERT INTO rer_portability_parts VALUES(?,?,?)',params:[id,part.index,part.sha256]}];
|
|
30
33
|
for(let i=0,segment=0;i<json.length;segment++) {
|
|
31
34
|
let end=Math.min(i+32000,json.length);
|
|
32
35
|
const last=json.charCodeAt(end-1),next=json.charCodeAt(end);
|
|
33
36
|
if(last>=0xd800 && last<=0xdbff && next>=0xdc00 && next<=0xdfff) end--;
|
|
34
|
-
result.push(
|
|
37
|
+
result.push({sql:'INSERT INTO rer_portability_segments VALUES(?,?,?,?)',params:[id,part.index,segment,json.slice(i,end)]});i=end;
|
|
35
38
|
}
|
|
36
39
|
return result;
|
|
37
40
|
}
|