@runeditrun/rer 0.2.10 → 0.2.11
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/global/CHANGELOG.md +10 -0
- package/modules/operator-auth/dev/index.mjs +7 -5
- package/modules/operator-auth/dev-gate.mjs +2 -1
- package/modules/operator-auth/identity/oidc/index.mjs +6 -1
- package/modules/operator-auth/rejected-response.mjs +44 -0
- package/modules/operator-auth/routes.mjs +6 -1
- package/package.json +1 -1
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.11
|
|
4
|
+
|
|
5
|
+
- New Base foundations generate public Run instructions for the edition's planned product repository, distinct migration ordinals, and setup names matching the edition.
|
|
6
|
+
- Owned early auth, OIDC, local dev and template refusals finish ordinary request bodies before responding. Oversized or stalled uploads are bounded while privacy headers are retained.
|
|
7
|
+
|
|
8
|
+
### Upgrade notes
|
|
9
|
+
|
|
10
|
+
- Seeds receive these source changes with their next Base refresh; changing the npm pin alone does not refresh seed-owned runtime copies. Existing applied migration histories keep their names.
|
|
11
|
+
- Optional import-kit selection remains deferred until a canonical complete migration schema can drive generation; product import flows still need their own authorized adapter.
|
|
12
|
+
|
|
3
13
|
## 0.2.10
|
|
4
14
|
|
|
5
15
|
- First-owner bootstrap and signed owner claims use a client-IP rate budget, so junk setup-token requests from another client cannot block the correct claim. Repeated wrong tokens from one client remain limited.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from '../rejected-response.mjs';
|
|
1
2
|
// Local dev identity. SERVER-ONLY and LOCAL-ONLY: load this layer only from a
|
|
2
3
|
// local-only Worker entry (a `wrangler dev` or Vite-serve entry), never from the
|
|
3
4
|
// deployed main. `rer build` refuses any build output containing the marker.
|
|
@@ -40,19 +41,20 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
40
41
|
if (managedInstallation(env)) {
|
|
41
42
|
// Never admit a dev credential here; with dev identity on, serve nothing.
|
|
42
43
|
registerDevAdmission(null);
|
|
43
|
-
if (env.RER_DEV_IDENTITY !== 'off') return text(503, 'Dev identity refuses to run beside RER_INSTALLATION_ID with a non-loopback RER_MANAGEMENT_ORIGIN. Remove those bindings from local settings or use rer dev --login.');
|
|
44
|
-
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' ? devNotFound() : worker.fetch(request, original, execution);
|
|
44
|
+
if (env.RER_DEV_IDENTITY !== 'off') return rejectedResponse(request, text(503, 'Dev identity refuses to run beside RER_INSTALLATION_ID with a non-loopback RER_MANAGEMENT_ORIGIN. Remove those bindings from local settings or use rer dev --login.'));
|
|
45
|
+
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' ? rejectedResponse(request, devNotFound()) : worker.fetch(request, original, execution);
|
|
45
46
|
}
|
|
46
47
|
const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
|
|
47
48
|
registerDevAdmission(gate ? r => gate.admits(r) : null);
|
|
48
49
|
const path = new URL(request.url).pathname;
|
|
49
50
|
if (path === '/auth/dev/enter' || path === '/__dev/personas') {
|
|
50
|
-
if (!gate || env.RER_DEV_IDENTITY === 'off' || !await gate.admits(request)) return devNotFound();
|
|
51
|
+
if (!gate || env.RER_DEV_IDENTITY === 'off' || !await gate.admits(request)) return rejectedResponse(request, devNotFound());
|
|
51
52
|
const context = identity(env, authConfig, declared);
|
|
52
53
|
try {
|
|
53
|
-
|
|
54
|
+
const response = path === '/__dev/personas' ? Response.json(await context.list(), { headers }) : await enter(request, gate, context);
|
|
55
|
+
return rejectedResponse(request, response);
|
|
54
56
|
} catch (error) {
|
|
55
|
-
if (error instanceof AuthError) return Response.json({ error: error.code }, { status: error.status, headers });
|
|
57
|
+
if (error instanceof AuthError) return rejectedResponse(request, Response.json({ error: error.code }, { status: error.status, headers }));
|
|
56
58
|
throw error;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from './rejected-response.mjs';
|
|
1
2
|
import { constantEqual } from './crypto.mjs';
|
|
2
3
|
import { isLoopbackHost, localCookieName } from './http.mjs';
|
|
3
4
|
|
|
@@ -76,7 +77,7 @@ export function devGate({ key, origin, local }) {
|
|
|
76
77
|
return new Response(request.method === 'HEAD' ? null : body, { headers: { ...privateHeaders, 'content-type': 'text/html; charset=utf-8',
|
|
77
78
|
'content-security-policy': `default-src 'none'; script-src ${script}; style-src ${style}; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'` } });
|
|
78
79
|
}
|
|
79
|
-
if (request.method !== 'POST' || request.headers.get('sec-fetch-site') === 'cross-site' || !request.headers.get('content-type')?.startsWith('application/json')) return devNotFound();
|
|
80
|
+
if (request.method !== 'POST' || request.headers.get('sec-fetch-site') === 'cross-site' || !request.headers.get('content-type')?.startsWith('application/json')) return rejectedResponse(request, devNotFound());
|
|
80
81
|
const text = await request.text();
|
|
81
82
|
let presented; try { presented = text.length <= 1024 ? JSON.parse(text)?.key : undefined; } catch {}
|
|
82
83
|
if (typeof presented !== 'string' || !constantEqual(presented, key)) return devNotFound();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from '../../rejected-response.mjs';
|
|
1
2
|
// Server-only entry. Never include this module or its configuration in a browser bundle.
|
|
2
3
|
// OpenID Connect sign-in for several pinned providers at once. Each provider
|
|
3
4
|
// has its own start and callback route; its output is a verified principal,
|
|
@@ -279,7 +280,7 @@ export function createOidcProviders({ admission, db, config: input, clientIp, fe
|
|
|
279
280
|
|
|
280
281
|
// Exact routes only: /auth/oidc/<id>/start and /auth/oidc/<id>/callback.
|
|
281
282
|
export function createOidcHandler(oidc, { signInPath = oidc.signInPath ?? '/signin' } = {}) {
|
|
282
|
-
|
|
283
|
+
const handle = async request => {
|
|
283
284
|
const path = new URL(request.url).pathname;
|
|
284
285
|
const callbackId = oidc.callbackPaths?.[path];
|
|
285
286
|
if (callbackId) return oidc.callback(request, callbackId);
|
|
@@ -303,4 +304,8 @@ export function createOidcHandler(oidc, { signInPath = oidc.signInPath ?? '/sign
|
|
|
303
304
|
return oidc.begin(request, match[1], { returnTo: input.returnTo });
|
|
304
305
|
} catch (e) { return errorResponse(e instanceof OidcError ? e : new OidcError('oidc_invalid_input'), { signInPath }, request); }
|
|
305
306
|
};
|
|
307
|
+
return async request => {
|
|
308
|
+
const response = await handle(request);
|
|
309
|
+
return response ? rejectedResponse(request, response) : response;
|
|
310
|
+
};
|
|
306
311
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const maximumDiscardBytes = 64 * 1024
|
|
2
|
+
const maximumDiscardMs = 2000
|
|
3
|
+
|
|
4
|
+
function limitedResponse(response, message, status) {
|
|
5
|
+
const headers = new Headers(response.headers)
|
|
6
|
+
// Keep privacy/security policy, but never issue credentials or a redirect
|
|
7
|
+
// when the upload itself was refused.
|
|
8
|
+
for (const name of ['set-cookie', 'location', 'content-length', 'content-encoding']) headers.delete(name)
|
|
9
|
+
headers.set('content-type', 'text/plain; charset=utf-8')
|
|
10
|
+
void response.body?.cancel().catch(() => {})
|
|
11
|
+
return new Response(message, { status, headers })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Finish a rejected upload before returning its response. This preserves the
|
|
16
|
+
* intended status through workerd's upload proxy without buffering input.
|
|
17
|
+
* Oversized or stalled uploads receive explicit 413/408 responses instead.
|
|
18
|
+
*/
|
|
19
|
+
export async function rejectedResponse(request, response) {
|
|
20
|
+
if (!request.body || request.bodyUsed || request.body.locked) return response
|
|
21
|
+
const reader = request.body.getReader()
|
|
22
|
+
let bytes = 0
|
|
23
|
+
let timer
|
|
24
|
+
const deadline = new Promise(resolve => {
|
|
25
|
+
timer = setTimeout(() => resolve('timeout'), maximumDiscardMs)
|
|
26
|
+
})
|
|
27
|
+
try {
|
|
28
|
+
for (;;) {
|
|
29
|
+
const result = await Promise.race([reader.read(), deadline])
|
|
30
|
+
if (result === 'timeout') {
|
|
31
|
+
void reader.cancel('Rejected upload exceeded time limit').catch(() => {})
|
|
32
|
+
return limitedResponse(response, 'Request body timeout', 408)
|
|
33
|
+
}
|
|
34
|
+
if (result.done) return response
|
|
35
|
+
bytes += result.value.byteLength
|
|
36
|
+
if (bytes > maximumDiscardBytes) {
|
|
37
|
+
void reader.cancel('Rejected upload exceeded size limit').catch(() => {})
|
|
38
|
+
return limitedResponse(response, 'Request body too large', 413)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timer)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from './rejected-response.mjs';
|
|
1
2
|
import { identitySettingsPage } from './accounts/settings-page.mjs';
|
|
2
3
|
import { confirmationResponse } from './identity/email-link/confirmation.mjs';
|
|
3
4
|
import { createOidcHandler } from './identity/oidc/index.mjs';
|
|
@@ -20,7 +21,7 @@ function notice(auth, code, extra = {}) {
|
|
|
20
21
|
/** Fetch-compatible optional HTTP adapter. Returns null for paths it does not own. */
|
|
21
22
|
export function createAuthHandler(auth) {
|
|
22
23
|
const oidc = auth.providers ? createOidcHandler(auth.providers, { signInPath: auth.presentation.signInPath }) : null;
|
|
23
|
-
|
|
24
|
+
const handleAuth = async function(request) {
|
|
24
25
|
const url = new URL(request.url);
|
|
25
26
|
const path = url.pathname;
|
|
26
27
|
let form = false;
|
|
@@ -88,4 +89,8 @@ export function createAuthHandler(auth) {
|
|
|
88
89
|
return json({ error: 'auth_unavailable' }, 503);
|
|
89
90
|
}
|
|
90
91
|
};
|
|
92
|
+
return async function(request) {
|
|
93
|
+
const response = await handleAuth(request);
|
|
94
|
+
return response ? rejectedResponse(request, response) : response;
|
|
95
|
+
};
|
|
91
96
|
}
|