ref0-git 0.6.0 → 0.7.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/app/apps/github/README.md +3 -7
- package/app/apps/github/generated/git-rest.ts +12 -12
- package/app/apps/github/src/clients/allowed.ts +7 -9
- package/app/apps/github/src/clients/avatars.ts +5 -3
- package/app/apps/github/src/clients/graphql.ts +12 -2
- package/app/apps/github/src/clients/host-calls.ts +2 -1
- package/app/apps/github/src/clients/transfers.ts +56 -19
- package/app/apps/github/src/context/context.ts +5 -5
- package/app/apps/github/src/context/host.ts +115 -0
- package/app/apps/github/src/ingress.ts +28 -0
- package/app/apps/github/src/policy.ts +113 -78
- package/app/apps/github/src/private-repos.ts +7 -7
- package/app/apps/github/src/pulls/review.ts +2 -1
- package/app/apps/github/src/releases/release-form.tsx +40 -4
- package/app/apps/github/src/releases/releases.ts +148 -22
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +9 -2
- package/app/apps/github/src/seed/seed.ts +9 -2
- package/app/apps/github/src/server.ts +28 -11
- package/app/apps/github/src/signin/approval.ts +20 -15
- package/app/apps/github/src/signin/attempts.ts +306 -0
- package/app/apps/github/src/signin/auth.ts +9 -0
- package/app/apps/github/src/signin/host-session.ts +30 -18
- package/app/apps/github/src/signin/limits.ts +35 -0
- package/app/pnpm-workspace.yaml +37 -36
- package/dist/cli/setup.mjs +1 -1
- package/dist/init/app.mjs +43 -23
- package/dist/init/cloudflare.mjs +8 -4
- package/dist/init/create.mjs +1 -1
- package/dist/init/detect.mjs +5 -3
- package/dist/init/files.mjs +6 -1
- package/dist/init/git-module.mjs +4 -6
- package/dist/init/metadata.mjs +6 -6
- package/dist/init/node-app.mjs +5 -2
- package/dist/init/stores.mjs +3 -2
- package/dist/init/template.mjs +13 -7
- package/dist/init/templates.mjs +51 -39
- package/dist/init/vercel.mjs +1 -1
- package/dist/init/versions.mjs +1 -1
- package/package.json +13 -13
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { signInPaths } from '@ref0/git/auth';
|
|
2
|
+
import { Records } from '@ref0/infra';
|
|
3
|
+
import * as Clock from 'effect/Clock';
|
|
4
|
+
import * as Effect from 'effect/Effect';
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { deviceAttemptLimits as limits } from './limits.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The device page's front door (Q635, #1962): every GET and POST to `/login/device` spends an
|
|
11
|
+
* attempt, in the host's records, before Git reads the code it carries. An attempt needs room in
|
|
12
|
+
* three buckets of the window: the host's, the caller's address's and, signed in, its session's.
|
|
13
|
+
* Every ingress of a host shares the one scope, so every isolate and process counts together.
|
|
14
|
+
*
|
|
15
|
+
* The rows, in one collection of one scope, never named from the request:
|
|
16
|
+
* - `host`, `{ window, used }`: the host's attempts in its latest window, which never moves back,
|
|
17
|
+
* so a clock that does reopens no window;
|
|
18
|
+
* - `<window>.<key>`, `{ used }`: an address's or a session's attempts in that window, its key a
|
|
19
|
+
* SHA-256 of what it counts, so no row holds an address or a session.
|
|
20
|
+
*
|
|
21
|
+
* An admitted attempt deletes up to `limits.cleanup` rows of past windows and writes at most two,
|
|
22
|
+
* so the rows never pass the host's 100 attempts' 200, and the host's own row.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** The scope every ingress of a host counts in, whatever host name a request names. */
|
|
26
|
+
const scope = 'host/device-attempts';
|
|
27
|
+
|
|
28
|
+
const collection = 'attempts';
|
|
29
|
+
|
|
30
|
+
const hostId = 'host';
|
|
31
|
+
|
|
32
|
+
/** A window's number as its rows' ids start, so the ids of past windows sort before it. */
|
|
33
|
+
const windowId = (window: number) => String(window).padStart(15, '0');
|
|
34
|
+
|
|
35
|
+
const HostRow = Schema.Struct({ window: Schema.Int, used: Schema.Int });
|
|
36
|
+
|
|
37
|
+
const KeyRow = Schema.Struct({ used: Schema.Int });
|
|
38
|
+
|
|
39
|
+
/** The store failed, a row didn't decode, or racing attempts took every try: answered 503. */
|
|
40
|
+
export class DeviceAttemptsUnavailable extends Schema.TaggedError<DeviceAttemptsUnavailable>()(
|
|
41
|
+
'DeviceAttemptsUnavailable',
|
|
42
|
+
{ reason: Schema.String },
|
|
43
|
+
) {}
|
|
44
|
+
|
|
45
|
+
/** Whether an attempt may reach Git, or else how many seconds until its window ends. */
|
|
46
|
+
export type Admission =
|
|
47
|
+
| { readonly admitted: true }
|
|
48
|
+
| { readonly admitted: false; readonly retryAfter: number };
|
|
49
|
+
|
|
50
|
+
/** Who an attempt counts against: the platform's address for it, and its checked session's ID. */
|
|
51
|
+
export interface Attempter {
|
|
52
|
+
readonly address: string | undefined;
|
|
53
|
+
readonly session?: string | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** An IPv4 address's four bytes, in decimal with no leading zero, or `undefined`. */
|
|
57
|
+
const ipv4Bytes = (text: string) => {
|
|
58
|
+
const parts = text.split('.');
|
|
59
|
+
if (parts.length !== 4) return undefined;
|
|
60
|
+
|
|
61
|
+
const bytes = parts.map((part) => (/^(?:0|[1-9]\d{0,2})$/.test(part) ? Number(part) : 256));
|
|
62
|
+
|
|
63
|
+
return bytes.every((byte) => byte <= 255) ? bytes : undefined;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Groups of an IPv6 address's text, or `undefined` for one that isn't hex of one to four digits. */
|
|
67
|
+
const groupsIn = (text: string) => {
|
|
68
|
+
if (text === '') return [];
|
|
69
|
+
|
|
70
|
+
const groups = text.split(':');
|
|
71
|
+
|
|
72
|
+
return groups.every((group) => /^[0-9a-f]{1,4}$/i.test(group))
|
|
73
|
+
? groups.map((group) => parseInt(group, 16))
|
|
74
|
+
: undefined;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** An IPv6 address's eight 16-bit groups, an IPv4 tail as its last two, or `undefined`. */
|
|
78
|
+
const ipv6Groups = (text: string) => {
|
|
79
|
+
const tailAt = text.lastIndexOf(':') + 1;
|
|
80
|
+
const dotted = text.includes('.');
|
|
81
|
+
const tail = dotted ? ipv4Bytes(text.slice(tailAt)) : [];
|
|
82
|
+
if (tail === undefined) return undefined;
|
|
83
|
+
|
|
84
|
+
const ending = dotted ? [tail[0]! * 256 + tail[1]!, tail[2]! * 256 + tail[3]!] : [];
|
|
85
|
+
const kept = dotted ? text.slice(0, tailAt) : text;
|
|
86
|
+
// An IPv4 tail follows one colon of its own, or the two that stand for zeros.
|
|
87
|
+
const head = dotted && !kept.endsWith('::') ? kept.slice(0, -1) : kept;
|
|
88
|
+
const halves = head.split('::');
|
|
89
|
+
if (halves.length > 2) return undefined;
|
|
90
|
+
|
|
91
|
+
const left = groupsIn(halves[0] ?? '');
|
|
92
|
+
const right = groupsIn(halves[1] ?? '');
|
|
93
|
+
if (left === undefined || right === undefined) return undefined;
|
|
94
|
+
|
|
95
|
+
const missing = 8 - ending.length - left.length - right.length;
|
|
96
|
+
if (halves.length === 1) return missing === 0 ? [...left, ...ending] : undefined;
|
|
97
|
+
|
|
98
|
+
// `::` stands for one zero group or more, never none.
|
|
99
|
+
return missing < 1
|
|
100
|
+
? undefined
|
|
101
|
+
: [...left, ...Array<number>(missing).fill(0), ...right, ...ending];
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* What an address counts as: an IPv4 address, an IPv4-mapped IPv6 one as its IPv4, or an IPv6
|
|
106
|
+
* address's /64, each one spelling for every way to write it. An address missing, or one that
|
|
107
|
+
* isn't either, counts as one `unknown`, so it shares a bucket rather than escaping one.
|
|
108
|
+
*/
|
|
109
|
+
export const addressKey = (address: string | undefined) => {
|
|
110
|
+
const text = (address ?? '').trim();
|
|
111
|
+
const v4 = text.includes(':') ? undefined : ipv4Bytes(text);
|
|
112
|
+
if (v4 !== undefined) return `4:${v4.join('.')}`;
|
|
113
|
+
|
|
114
|
+
// A zone names the host's own interface, never another address: its letters as Node's `isIP` takes.
|
|
115
|
+
const zoneAt = text.indexOf('%');
|
|
116
|
+
const zoned = zoneAt === -1 || /^[0-9a-z.:-]+$/i.test(text.slice(zoneAt + 1));
|
|
117
|
+
const bare = zoneAt === -1 ? text : text.slice(0, zoneAt);
|
|
118
|
+
const groups = text.includes(':') && zoned ? ipv6Groups(bare) : undefined;
|
|
119
|
+
if (groups === undefined) return 'unknown';
|
|
120
|
+
|
|
121
|
+
const mapped = groups.slice(0, 5).every((group) => group === 0) && groups[5] === 0xffff;
|
|
122
|
+
if (mapped)
|
|
123
|
+
return `4:${[groups[6]! >> 8, groups[6]! & 255, groups[7]! >> 8, groups[7]! & 255].join('.')}`;
|
|
124
|
+
|
|
125
|
+
return `6:${groups
|
|
126
|
+
.slice(0, 4)
|
|
127
|
+
.map((group) => group.toString(16).padStart(4, '0'))
|
|
128
|
+
.join('')}`;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** `text`'s SHA-256, in hex. */
|
|
132
|
+
const sha256 = (text: string) =>
|
|
133
|
+
Effect.promise(() => crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))).pipe(
|
|
134
|
+
Effect.map((digest) =>
|
|
135
|
+
Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join(''),
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
/** The buckets past the host's an attempter's attempt needs room in: each key and its cap. */
|
|
140
|
+
const bucketsOf = (who: Attempter) =>
|
|
141
|
+
Effect.all([
|
|
142
|
+
Effect.map(sha256(`address:${addressKey(who.address)}`), (hash) => ({
|
|
143
|
+
key: `a${hash}`,
|
|
144
|
+
cap: limits.address,
|
|
145
|
+
})),
|
|
146
|
+
...(who.session === undefined
|
|
147
|
+
? []
|
|
148
|
+
: [
|
|
149
|
+
Effect.map(sha256(`session:${who.session}`), (hash) => ({
|
|
150
|
+
key: `s${hash}`,
|
|
151
|
+
cap: limits.session,
|
|
152
|
+
})),
|
|
153
|
+
]),
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
/** The 503 a failed store call, or a row that doesn't decode, answers, by what failed. */
|
|
157
|
+
const unavailable = (error: { readonly _tag: string }) =>
|
|
158
|
+
new DeviceAttemptsUnavailable({ reason: error._tag });
|
|
159
|
+
|
|
160
|
+
const decodeHost = Schema.decodeUnknownEffect(HostRow);
|
|
161
|
+
|
|
162
|
+
const decodeKey = Schema.decodeUnknownEffect(KeyRow);
|
|
163
|
+
|
|
164
|
+
type Buckets = Effect.Success<ReturnType<typeof bucketsOf>>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* One try at `now`, in `window` or the later one the host's row holds: admitted, refused, or a
|
|
168
|
+
* later window to try in, after a clock behind the host's or a commit another attempt won.
|
|
169
|
+
*/
|
|
170
|
+
const tryAt = (buckets: Buckets, now: number, window: number) =>
|
|
171
|
+
Effect.gen(function* () {
|
|
172
|
+
const ids = buckets.map(({ key }) => `${windowId(window)}.${key}`);
|
|
173
|
+
const snapshot = yield* Effect.mapError(
|
|
174
|
+
Records.read(scope, [
|
|
175
|
+
{ collection, id: hostId },
|
|
176
|
+
{ collection, to: windowId(window), limit: limits.cleanup },
|
|
177
|
+
...ids.map((id) => ({ collection, id })),
|
|
178
|
+
]),
|
|
179
|
+
unavailable,
|
|
180
|
+
);
|
|
181
|
+
const [hostRows = [], past = [], ...keyRows] = snapshot.results;
|
|
182
|
+
|
|
183
|
+
const host =
|
|
184
|
+
hostRows[0] === undefined
|
|
185
|
+
? undefined
|
|
186
|
+
: yield* Effect.mapError(decodeHost(hostRows[0].value), unavailable);
|
|
187
|
+
if (host !== undefined && host.window > window) return { later: host.window } as const;
|
|
188
|
+
|
|
189
|
+
const hostUsed = host?.window === window ? host.used : 0;
|
|
190
|
+
const used = yield* Effect.forEach(keyRows, (rows) =>
|
|
191
|
+
rows[0] === undefined
|
|
192
|
+
? Effect.succeed(0)
|
|
193
|
+
: Effect.mapError(decodeKey(rows[0].value), unavailable).pipe(
|
|
194
|
+
Effect.map((row) => row.used),
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
const full = hostUsed >= limits.host || buckets.some(({ cap }, at) => (used[at] ?? 0) >= cap);
|
|
198
|
+
|
|
199
|
+
if (full) {
|
|
200
|
+
const ends = (window + 1) * limits.window;
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
admission: { admitted: false, retryAfter: Math.max(1, Math.ceil((ends - now) / 1000)) },
|
|
204
|
+
} as const;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const committed = yield* Effect.mapError(
|
|
208
|
+
Records.commit(scope, {
|
|
209
|
+
id: crypto.randomUUID(),
|
|
210
|
+
expect: snapshot.version,
|
|
211
|
+
put: [
|
|
212
|
+
{ collection, id: hostId, value: { window, used: hostUsed + 1 } },
|
|
213
|
+
...ids.map((id, at) => ({ collection, id, value: { used: (used[at] ?? 0) + 1 } })),
|
|
214
|
+
],
|
|
215
|
+
delete: past.map((row) => ({ collection, id: row.id })),
|
|
216
|
+
}),
|
|
217
|
+
unavailable,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
return committed.ok
|
|
221
|
+
? ({ admission: { admitted: true } } as const)
|
|
222
|
+
: ({ later: window } as const);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Spends one attempt for `who`, or refuses it, before any code is read. Each try reads the rows
|
|
227
|
+
* again and commits only at the version it read, so racing attempts never admit past a cap; up to
|
|
228
|
+
* `limits.tries` tries, keeping only the latest window a try saw, then `DeviceAttemptsUnavailable`.
|
|
229
|
+
* A committed attempt stays spent, whatever becomes of its request.
|
|
230
|
+
*/
|
|
231
|
+
export const admitDeviceAttempt = (who: Attempter) =>
|
|
232
|
+
Effect.gen(function* () {
|
|
233
|
+
const buckets = yield* bucketsOf(who);
|
|
234
|
+
let seen = 0;
|
|
235
|
+
|
|
236
|
+
for (let tries = 0; tries < limits.tries; tries++) {
|
|
237
|
+
const now = yield* Clock.currentTimeMillis;
|
|
238
|
+
const tried = yield* tryAt(buckets, now, Math.max(Math.floor(now / limits.window), seen));
|
|
239
|
+
if ('admission' in tried) return tried.admission;
|
|
240
|
+
|
|
241
|
+
seen = tried.later;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return yield* new DeviceAttemptsUnavailable({ reason: 'Racing attempts took every try' });
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/** A refused attempt's answer: the same whether or not the code exists, and never cached. */
|
|
248
|
+
const refusedPage = (retryAfter: number) =>
|
|
249
|
+
new Response('Too many sign-in attempts: try again later', {
|
|
250
|
+
status: 429,
|
|
251
|
+
headers: {
|
|
252
|
+
'retry-after': String(retryAfter),
|
|
253
|
+
'cache-control': 'no-store',
|
|
254
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
/** Git's own answer when sign-in's store fails, which a failed front door answers too. */
|
|
259
|
+
const unavailablePage = () =>
|
|
260
|
+
new Response('Sign-in is unavailable: try again', {
|
|
261
|
+
status: 503,
|
|
262
|
+
headers: { 'cache-control': 'no-store', 'content-type': 'text/plain; charset=utf-8' },
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
/** Whether the front door counts a request: a GET or a POST to the device page, Git's 405 else. */
|
|
266
|
+
export const isDeviceAttempt = (pathname: string, method: string) =>
|
|
267
|
+
pathname === signInPaths.device && (method === 'GET' || method === 'POST');
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The front door's answer for an attempt of `who`'s: `undefined` once it's spent, a 429 refused, or
|
|
271
|
+
* Git's 503 when the store fails, a row doesn't decode or racing attempts take every try.
|
|
272
|
+
*/
|
|
273
|
+
export const deviceAttemptAnswer = (who: Attempter) =>
|
|
274
|
+
admitDeviceAttempt(who).pipe(
|
|
275
|
+
Effect.map((admission) => (admission.admitted ? undefined : refusedPage(admission.retryAfter))),
|
|
276
|
+
Effect.catchCause(() => Effect.succeed(unavailablePage())),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
export interface DeviceAttemptGateOptions {
|
|
280
|
+
/** `deviceAttemptAnswer` for `who`, run on the host's runtime, with its records. */
|
|
281
|
+
readonly answer: (who: Attempter) => Promise<Response | undefined>;
|
|
282
|
+
/** The header the platform sets with the caller's address, in place of any the caller sent. */
|
|
283
|
+
readonly addressHeader: string;
|
|
284
|
+
/** The ID of the session Better Auth checked, or `undefined` signed out; a throw answers 503. */
|
|
285
|
+
readonly session?: (request: Request) => Promise<string | undefined>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The front door to put before a host's routes: a 429 or a 503 for a device-page request it
|
|
290
|
+
* refuses, or `undefined` for one it admits and for any other request. It reads no body, and runs
|
|
291
|
+
* an attempt without the request's signal, so a caller who hangs up keeps it spent.
|
|
292
|
+
*/
|
|
293
|
+
export const deviceAttemptGate =
|
|
294
|
+
(options: DeviceAttemptGateOptions) =>
|
|
295
|
+
async (request: Request): Promise<Response | undefined> => {
|
|
296
|
+
if (!isDeviceAttempt(new URL(request.url).pathname, request.method)) return undefined;
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
const session = await options.session?.(request);
|
|
300
|
+
const address = request.headers.get(options.addressHeader) ?? undefined;
|
|
301
|
+
|
|
302
|
+
return await options.answer({ address, session });
|
|
303
|
+
} catch {
|
|
304
|
+
return unavailablePage();
|
|
305
|
+
}
|
|
306
|
+
};
|
|
@@ -738,6 +738,15 @@ export const sessionFrom =
|
|
|
738
738
|
return { login, token, tokenId: held.gitTokenId, expiresAt: found.session.expiresAt.getTime() };
|
|
739
739
|
};
|
|
740
740
|
|
|
741
|
+
/**
|
|
742
|
+
* The ID of the session Better Auth checked for `request`, or `undefined` signed out: what the
|
|
743
|
+
* device page's attempts count a session by, never its cookie, which a caller can change.
|
|
744
|
+
*/
|
|
745
|
+
export const sessionIdFrom =
|
|
746
|
+
(auth: StarterAuth) =>
|
|
747
|
+
async (request: Request): Promise<string | undefined> =>
|
|
748
|
+
(await auth.api.getSession({ headers: request.headers }))?.session.id;
|
|
749
|
+
|
|
741
750
|
/**
|
|
742
751
|
* Ends the browser's session, once Git refuses its token: Better Auth deletes its row, and the
|
|
743
752
|
* delete hook revokes the token, so a revoke Git already made only logs its id.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Auth } from '@ref0/git';
|
|
2
|
+
import type { NamedActor } from '@ref0/git';
|
|
3
|
+
import * as Clock from 'effect/Clock';
|
|
4
|
+
import * as Effect from 'effect/Effect';
|
|
3
5
|
import * as Option from 'effect/Option';
|
|
6
|
+
import * as Redacted from 'effect/Redacted';
|
|
4
7
|
import * as Schema from 'effect/Schema';
|
|
5
8
|
|
|
6
9
|
import { loginProblem } from '../names/owners.ts';
|
|
@@ -23,6 +26,8 @@ const HostSession = Schema.Struct({ login: Schema.String, expiresAt: Schema.Numb
|
|
|
23
26
|
|
|
24
27
|
const hostSessionOf = Schema.decodeUnknownOption(Schema.fromJsonString(HostSession));
|
|
25
28
|
|
|
29
|
+
const encodeHostSession = Schema.encodeSync(Schema.fromJsonString(HostSession));
|
|
30
|
+
|
|
26
31
|
/** `request` with no host session on it: what the Worker serves, whoever sent it. */
|
|
27
32
|
export const withoutHostSession = (request: Request): Request => {
|
|
28
33
|
if (!request.headers.has(hostSessionHeader)) return request;
|
|
@@ -34,11 +39,15 @@ export const withoutHostSession = (request: Request): Request => {
|
|
|
34
39
|
};
|
|
35
40
|
|
|
36
41
|
/** The header's value for `login`, sealed under the session key, which opens for a minute. */
|
|
37
|
-
export const hostSessionFor = (key: CryptoKey, login: string):
|
|
38
|
-
|
|
42
|
+
export const hostSessionFor = (key: CryptoKey, login: string): Effect.Effect<string> =>
|
|
43
|
+
Effect.flatMap(Clock.currentTimeMillis, (now) =>
|
|
44
|
+
Effect.promise(() =>
|
|
45
|
+
seal(key, purpose, encodeHostSession({ login, expiresAt: now + lifetime })),
|
|
46
|
+
),
|
|
47
|
+
);
|
|
39
48
|
|
|
40
49
|
/**
|
|
41
|
-
* Git's `
|
|
50
|
+
* Git's `Auth` for the app: the admin's bearer secret, or, on a request with no credential, a
|
|
42
51
|
* host session the app's server sealed, as its person, when its login is one. It never reads
|
|
43
52
|
* Better Auth's cookie, so a browser's session acts only through its capped Git token (Q520). Git's own tokens never reach it: Git reads
|
|
44
53
|
* them first, and a token's holder stays capped by its scope.
|
|
@@ -47,22 +56,25 @@ export const appAuth = (options: {
|
|
|
47
56
|
readonly adminToken: string;
|
|
48
57
|
readonly admin: NamedActor;
|
|
49
58
|
readonly key: Promise<CryptoKey>;
|
|
50
|
-
}):
|
|
51
|
-
const asAdmin = bearer({ token: options.adminToken, actor: options.admin });
|
|
59
|
+
}): Auth.AuthService => {
|
|
60
|
+
const asAdmin = Auth.bearer({ token: Redacted.make(options.adminToken), actor: options.admin });
|
|
52
61
|
|
|
53
|
-
return
|
|
54
|
-
|
|
62
|
+
return Auth.make(
|
|
63
|
+
Effect.fnUntraced(function* (input) {
|
|
64
|
+
if (input.credentials !== undefined) return yield* asAdmin.identify(input);
|
|
55
65
|
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
const text = input.request.headers.get(hostSessionHeader);
|
|
67
|
+
if (text === null) return Option.none();
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
const opened = yield* Effect.promise(async () => open(await options.key, purpose, text));
|
|
70
|
+
const session = opened === undefined ? Option.none() : hostSessionOf(opened);
|
|
71
|
+
const now = yield* Clock.currentTimeMillis;
|
|
72
|
+
if (Option.isNone(session) || session.value.expiresAt <= now) return Option.none();
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
// A person's ID is their login, never the admin's `_admin`, however the session was made.
|
|
75
|
+
const login = session.value.login;
|
|
65
76
|
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
return loginProblem(login) === undefined ? Option.some({ id: login }) : Option.none();
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
68
80
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The device flow's attempt limits (Q635, #1962): how many requests to `/login/device`, the page a
|
|
3
|
+
* person types a code into, a host takes before Git reads any code. Every shipped host reads these
|
|
4
|
+
* numbers from here, the examples through copies `scripts/host-copies.ts` writes.
|
|
5
|
+
*
|
|
6
|
+
* A code lives 900 seconds, so it overlaps at most 16 windows, and the host takes at most
|
|
7
|
+
* 16 × 100 = 1,600 tries at it: one live code of the 32^8 = 2^40 is found with a chance under
|
|
8
|
+
* 1.5 × 10^-9, and N live codes under N times that, however many addresses send them.
|
|
9
|
+
*/
|
|
10
|
+
const host = 100;
|
|
11
|
+
|
|
12
|
+
export const deviceAttemptLimits = {
|
|
13
|
+
/** One window's length, in milliseconds, on the host's clock. */
|
|
14
|
+
window: 60_000,
|
|
15
|
+
/** Attempts the whole host takes in a window, from every address and session. */
|
|
16
|
+
host,
|
|
17
|
+
/** Attempts one address takes in a window: an IPv4 address, or an IPv6 address's /64. */
|
|
18
|
+
address: 10,
|
|
19
|
+
/** Attempts one signed-in session takes in a window, whatever address it comes from. */
|
|
20
|
+
session: 5,
|
|
21
|
+
/** Rows of past windows an admitted attempt deletes, at most. */
|
|
22
|
+
cleanup: 4,
|
|
23
|
+
/**
|
|
24
|
+
* Reads and commits one attempt makes before it answers 503, as racing attempts take turns.
|
|
25
|
+
* Only an admitted attempt writes the scope, so a try loses only to another admission, and a
|
|
26
|
+
* full window refuses on its read, writing nothing: an attempt loses at most `host` tries a
|
|
27
|
+
* window. While an attempt stays within two windows it ends in an admit or a 429. Spending
|
|
28
|
+
* every try needs `tries` admissions by others during that one attempt, so only a host
|
|
29
|
+
* saturated across three or more windows answers 503. Each try is a read and a commit: 203
|
|
30
|
+
* tries, 406 store calls, within a Worker's 8,000 subrequests. A window's worst burst, every
|
|
31
|
+
* attempt reading before any commits, costs about 100 × 101 / 2 = 5,050 reads and as many
|
|
32
|
+
* commits.
|
|
33
|
+
*/
|
|
34
|
+
tries: 2 * host + 3,
|
|
35
|
+
} as const;
|
package/app/pnpm-workspace.yaml
CHANGED
|
@@ -17,9 +17,9 @@ catalog:
|
|
|
17
17
|
'@base-ui/react': 1.9.0
|
|
18
18
|
# The app's Worker build: Cloudflare's Vite plugin at the release that runs wrangler's workerd, so
|
|
19
19
|
# the app and its tests share one miniflare.
|
|
20
|
-
'@cloudflare/vite-plugin': 1.70.
|
|
20
|
+
'@cloudflare/vite-plugin': 1.70.2
|
|
21
21
|
# Workers' runtime types, for @ref0/infra/cloudflare. Moves with wrangler's workerd.
|
|
22
|
-
'@cloudflare/workers-types': 5.
|
|
22
|
+
'@cloudflare/workers-types': 5.20261123.1
|
|
23
23
|
# The app's profile pictures, drawn from each login in the page, with no avatar service. MIT.
|
|
24
24
|
'@dicebear/core': 10.7.0
|
|
25
25
|
# The pictures' styles, of which the app imports two by subpath: Pixelbot for people and Planets
|
|
@@ -27,13 +27,13 @@ catalog:
|
|
|
27
27
|
'@dicebear/styles': 10.6.0
|
|
28
28
|
# Effect's Node platform, which Alchemy's CLI runs on: for examples/git-alchemy alone, at
|
|
29
29
|
# Effect's own version. MIT.
|
|
30
|
-
'@effect/platform-node': 4.1.
|
|
30
|
+
'@effect/platform-node': 4.1.7
|
|
31
31
|
# Effect's Node services without the Redis and undici platform-node brings: the CLI's file
|
|
32
32
|
# system, child processes, terminal and path, at Effect's own version (Q802). MIT.
|
|
33
|
-
'@effect/platform-node-shared': 4.1.
|
|
34
|
-
'@effect/tsgo': 0.
|
|
33
|
+
'@effect/platform-node-shared': 4.1.7
|
|
34
|
+
'@effect/tsgo': 0.74.0
|
|
35
35
|
# Effect's Vitest helpers, `it.effect` and `it.prop`, at Effect's own version.
|
|
36
|
-
'@effect/vitest': 4.1.
|
|
36
|
+
'@effect/vitest': 4.1.7
|
|
37
37
|
# GitHub's REST shapes as TypeScript types, which @ref0/github's contracts serve. MIT. Built from
|
|
38
38
|
# @octokit/openapi 23.0.1. The shapes' tests check answers against 24.0.0's description, whose
|
|
39
39
|
# label fields `RestLabel` adds until a release built from it exists.
|
|
@@ -56,7 +56,7 @@ catalog:
|
|
|
56
56
|
# MIT.
|
|
57
57
|
'@octokit/webhooks': 14.2.0
|
|
58
58
|
# The app's diff view: virtualized, highlighted by Shiki, which only the browser loads. Apache-2.0.
|
|
59
|
-
'@pierre/diffs': 1.
|
|
59
|
+
'@pierre/diffs': 1.7.2
|
|
60
60
|
# Folder, submodule and symlink icons on the code pages and in the diff headers. Apache-2.0. A
|
|
61
61
|
# 2.0 beta, pinned: 0.9.0, the newest release, imports without extensions, which Node can't load.
|
|
62
62
|
'@pierre/icons': 2.0.0-beta.6
|
|
@@ -67,16 +67,16 @@ catalog:
|
|
|
67
67
|
# The app's Markdown renderer: words, a WebAssembly parser, with hooks for GitHub's alerts,
|
|
68
68
|
# anchors, references and URLs (Q213). Apache-2.0.
|
|
69
69
|
'@pierre/words': 0.3.0
|
|
70
|
-
'@ref0/workspace': 0.
|
|
70
|
+
'@ref0/workspace': 0.9.0
|
|
71
71
|
'@tailwindcss/vite': 4.3.5
|
|
72
72
|
# The app's stack: TanStack Start, its router and Query, and React, as spike F ran them, at the
|
|
73
73
|
# newest releases past pnpm's minimum release age.
|
|
74
|
-
'@tanstack/react-query': 5.108.
|
|
74
|
+
'@tanstack/react-query': 5.108.4
|
|
75
75
|
'@tanstack/react-router': 1.170.46
|
|
76
76
|
# The router's integration with Query: the server's page sends the queries its loaders read, so
|
|
77
77
|
# the browser hydrates from the same data. MIT.
|
|
78
78
|
'@tanstack/react-router-ssr-query': 1.167.3
|
|
79
|
-
'@tanstack/react-start': 1.169.
|
|
79
|
+
'@tanstack/react-start': 1.169.7
|
|
80
80
|
# hast's types, for the app's Markdown tests, which read renders as hast. MIT.
|
|
81
81
|
'@types/hast': 3.0.5
|
|
82
82
|
# libSQL's client, which a host passes to @ref0/infra/turso's turso() as createClient, and its
|
|
@@ -85,10 +85,10 @@ catalog:
|
|
|
85
85
|
'@libsql/kysely-libsql': 0.4.1
|
|
86
86
|
# better-sqlite3's types, for @ref0/infra/sqlite's tests over it. MIT.
|
|
87
87
|
'@types/better-sqlite3': 9.6.0
|
|
88
|
-
'@types/node': 24.19.
|
|
88
|
+
'@types/node': 24.19.4
|
|
89
89
|
# pg's types, for @ref0/infra/postgres's `listen` and its tests. MIT.
|
|
90
90
|
'@types/pg': 8.23.1
|
|
91
|
-
'@types/react': 19.3.
|
|
91
|
+
'@types/react': 19.3.3
|
|
92
92
|
# semver's types, for ref0-git's property over npm's version ranges, beside semver. MIT.
|
|
93
93
|
'@types/semver': 7.8.0
|
|
94
94
|
'@types/react-dom': 19.3.0
|
|
@@ -106,43 +106,44 @@ catalog:
|
|
|
106
106
|
diff: 9.0.0
|
|
107
107
|
# Exact, as ref0 pins it: npm ignores pnpm's lockfile, so a range would let a consumer pull a
|
|
108
108
|
# newer Effect than the one tested.
|
|
109
|
-
effect: 4.1.
|
|
109
|
+
effect: 4.1.7
|
|
110
110
|
# Postgres 17's binaries, which @ref0/infra/postgres's tests start a server from, with no Docker.
|
|
111
111
|
# The package is MIT, and the binaries in its platform packages are under the PostgreSQL License.
|
|
112
112
|
# The tests never import it: on `beforeExit` it calls `process.exit(0)`.
|
|
113
|
-
embedded-postgres: 17.
|
|
114
|
-
# The app's people, sign-up and sessions, over D1 through its own Kysely dialect: 1.7.19,
|
|
115
|
-
# 10 Nov 2026 (Q639),
|
|
116
|
-
# second connection beside it. Its username plugin is the login. No install scripts. MIT.
|
|
117
|
-
better-auth: 1.7.
|
|
113
|
+
embedded-postgres: 17.12.0-beta.19
|
|
114
|
+
# The app's people, sign-up and sessions, over D1 through its own Kysely dialect: from 1.7.19,
|
|
115
|
+
# published 10 Nov 2026 (Q639), its username plugin checks a login on a sign-up's transaction, not
|
|
116
|
+
# on a second connection beside it. Its username plugin is the login. No install scripts. MIT.
|
|
117
|
+
better-auth: 1.7.28
|
|
118
118
|
# Better Auth's passkeys, at its own release, over @simplewebauthn/server and /browser. No install
|
|
119
119
|
# scripts. MIT.
|
|
120
|
-
'@better-auth/passkey': 1.7.
|
|
120
|
+
'@better-auth/passkey': 1.7.28
|
|
121
121
|
# The query builder Better Auth's adapter runs on, at the release it resolves: a platform's file hands
|
|
122
122
|
# the app's people a Kysely dialect, such as libSQL's or Postgres's. MIT.
|
|
123
123
|
kysely: 0.29.9
|
|
124
124
|
# A SQLite driver @ref0/infra/sqlite's conformance runs on, beside node:sqlite. MIT.
|
|
125
|
-
better-sqlite3: 13.0
|
|
125
|
+
better-sqlite3: 13.2.0
|
|
126
126
|
# bun:sqlite's types, which @ref0/infra/sqlite's type test checks its database shape against. MIT.
|
|
127
|
-
bun-types: 1.4.
|
|
127
|
+
bun-types: 1.4.5
|
|
128
128
|
# A DOM for the app's mounted tests, at ref0's version. MIT.
|
|
129
129
|
happy-dom: 21.0.4
|
|
130
130
|
# IndexedDB in Node, which the app's saved-read tests run code/saved-reads.ts's store on, since
|
|
131
|
-
# happy-dom has none. 6.2.
|
|
131
|
+
# happy-dom has none. 6.2.8, published 8 Nov 2026: no dependencies, no install scripts, no
|
|
132
132
|
# network or `process` use, and no eval but two `Function` calls on fixed strings, which find the
|
|
133
133
|
# global under jsdom. Apache-2.0.
|
|
134
|
-
fake-indexeddb: 6.2.
|
|
134
|
+
fake-indexeddb: 6.2.8
|
|
135
135
|
# HTML read as hast, which the app's Markdown tests compare GitHub's render with. MIT.
|
|
136
|
-
hast-util-from-html: 2.0
|
|
137
|
-
# The app's icons
|
|
138
|
-
lucide-react: 1.
|
|
136
|
+
hast-util-from-html: 2.1.0
|
|
137
|
+
# The app's icons. ISC.
|
|
138
|
+
lucide-react: 1.82.0
|
|
139
139
|
# The app's fonts, from its shadcn preset: Inter for text and Geist for headings, bundled. OFL-1.1.
|
|
140
140
|
'@fontsource-variable/geist': 5.3.0
|
|
141
141
|
'@fontsource-variable/inter': 5.3.0
|
|
142
|
+
nitro: 3.0.261103-rc
|
|
142
143
|
# A pack's zlib members inflated one at a time, through its low-level API alone, in @ref0/git's
|
|
143
144
|
# `protocol/bytes/inflate.ts`, which reports the input each consumed. pako 3 exports no
|
|
144
|
-
# low-level API.
|
|
145
|
-
|
|
145
|
+
# low-level API. Pinned at 2.1.0: `inflate.ts` and `deflate.ts` reset its state field by field,
|
|
146
|
+
# and `inflate.fuzz.test.ts` holds the version a move to another must re-read.
|
|
146
147
|
pako: 2.1.0
|
|
147
148
|
# node-postgres: the pool @ref0/infra/postgres's tests run on, and the client its `listen` opens,
|
|
148
149
|
# an optional peer loaded only when `listen` is given. MIT.
|
|
@@ -178,7 +179,7 @@ catalog:
|
|
|
178
179
|
# package.json spec as npm does. ISC. At the release already in the lockfile.
|
|
179
180
|
semver: 7.8.6
|
|
180
181
|
# shadcn's CLI, which copies the app's components, and its `tailwind.css`. MIT.
|
|
181
|
-
shadcn: 4.23.
|
|
182
|
+
shadcn: 4.23.1
|
|
182
183
|
# Toasts, through shadcn's `sonner` component in the app. MIT.
|
|
183
184
|
sonner: 2.0.8
|
|
184
185
|
# Tailwind, which styles shadcn's components. MIT.
|
|
@@ -192,21 +193,21 @@ catalog:
|
|
|
192
193
|
github-slugger: 2.0.0
|
|
193
194
|
# A TLA+ model checker in TypeScript, for the models in verification/. MIT.
|
|
194
195
|
tla-ts: 0.0.10
|
|
195
|
-
tsrs: 7.1.0-beta.
|
|
196
|
+
tsrs: 7.1.0-beta.tsrs4
|
|
196
197
|
typescript: 7.0.2
|
|
197
|
-
vite-plus: 1.
|
|
198
|
-
# The Vitest that Vite+ 1.
|
|
198
|
+
vite-plus: 1.8.0
|
|
199
|
+
# The Vitest that Vite+ 1.8.0 bundles, `vp --version`'s, for `@effect/vitest`'s peer. Moves with
|
|
199
200
|
# `vite-plus`.
|
|
200
|
-
vitest: 5.1.
|
|
201
|
+
vitest: 5.1.1
|
|
201
202
|
# A YAML parser for scripts/detect-tables.ts, which reads linguist's tables into
|
|
202
203
|
# @ref0/github's language table. ISC.
|
|
203
204
|
yaml: 2.9.1
|
|
204
205
|
# Runs @ref0/infra/cloudflare's objects in workerd for its tests, through `createTestHarness`.
|
|
205
|
-
wrangler: 4.
|
|
206
|
+
wrangler: 4.168.0
|
|
206
207
|
|
|
207
208
|
# Vite+ is Vite here: Vitest, which Vite+ bundles, asks for Vite as its peer, and gets Vite+'s core.
|
|
208
209
|
overrides:
|
|
209
|
-
vite@*: npm:@voidzero-dev/vite-plus-core@8.3.
|
|
210
|
+
vite@*: npm:@voidzero-dev/vite-plus-core@8.3.8001
|
|
210
211
|
vitest@*: 'catalog:'
|
|
211
212
|
|
|
212
213
|
# wrangler's: esbuild fetches its binary, and workerd its runtime, on install. better-sqlite3
|
|
@@ -220,4 +221,4 @@ allowBuilds:
|
|
|
220
221
|
workerd: true
|
|
221
222
|
|
|
222
223
|
minimumReleaseAgeExclude:
|
|
223
|
-
- '@ref0/workspace@0.
|
|
224
|
+
- '@ref0/workspace@0.9.0'
|
package/dist/cli/setup.mjs
CHANGED
|
@@ -1402,7 +1402,7 @@ const findingsOf = (view, project, chosen, disk, source) => {
|
|
|
1402
1402
|
const classesBound = gitClasses.every((each) => bindings.includes(each.name) && made.includes(each.class_name));
|
|
1403
1403
|
const entry = main === void 0 ? "" : view.read(main) ?? "";
|
|
1404
1404
|
const exported = gitClasses.every(({ class_name: name }) => new RegExp(`export\\s+(const|class|\\{[^}]*)\\s*\\b${name}\\b`).test(entry));
|
|
1405
|
-
const routed = /from ['"]\.\/git\.ts['"]/.test(entry) && /\b(github|rest|git)\.(route|fetch)\b/.test(entry);
|
|
1405
|
+
const routed = /from ['"]\.\/git\.ts['"]/.test(entry) && /\b(github|rest|git)\.(route|fetch)\b|\bingressOf\(\{[^}]*\b(github|rest|git)\b/.test(entry);
|
|
1406
1406
|
const packs = chosen.objects === "packs";
|
|
1407
1407
|
const bucketBound = buckets.includes("PACKS");
|
|
1408
1408
|
const vars = devVars(view);
|