gestalt-mobile 0.12.0 → 0.13.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/dist/client/assets/index-D2sT9ZHY.js +19 -0
- package/dist/client/index.html +1 -1
- package/dist/server/server/app.js +22 -227
- package/dist/server/server/composition.js +0 -5
- package/dist/server/server/features/auth/application/ceremony-attempts.js +22 -0
- package/dist/server/server/features/auth/domain/errors.js +7 -0
- package/dist/server/server/features/auth/http/cookies.js +10 -0
- package/dist/server/server/features/auth/login/options/endpoint.js +22 -20
- package/dist/server/server/features/auth/login/verify/endpoint.js +6 -14
- package/dist/server/server/features/auth/logout/endpoint.js +2 -6
- package/dist/server/server/features/auth/register/options/endpoint.js +43 -11
- package/dist/server/server/features/auth/register/verify/endpoint.js +4 -3
- package/dist/server/server/features/auth/register-routes.js +41 -0
- package/dist/server/server/features/git/checkout-branch/endpoint.js +1 -1
- package/dist/server/server/features/git/clone-repository/endpoint.js +1 -1
- package/dist/server/server/features/git/register-routes.js +34 -0
- package/dist/server/server/features/plans/register-routes.js +22 -0
- package/dist/server/server/features/sessions/promote-recent-thread/endpoint.js +1 -1
- package/dist/server/server/features/sessions/register-routes.js +138 -0
- package/dist/server/server/features/sessions/respond-interaction/endpoint.js +1 -1
- package/dist/server/server/features/sessions/select-model/endpoint.js +1 -1
- package/dist/server/server/features/sessions/start-session/endpoint.js +5 -2
- package/dist/server/server/features/sessions/start-turn/endpoint.js +2 -1
- package/dist/server/server/features/skills/register-routes.js +17 -0
- package/dist/server/server/features/skills/replace-profile/endpoint.js +20 -5
- package/dist/server/server/platform/auth/sqlite-authorization-store.js +29 -6
- package/dist/server/server/platform/codex/normalizer.js +32 -6
- package/dist/server/server/platform/codex/protocol-compatibility.js +19 -1
- package/dist/server/server/platform/codex/server-request.js +2 -0
- package/dist/server/server/platform/codex/session-runtime.js +193 -125
- package/dist/server/server/platform/http/problem-handler.js +10 -0
- package/dist/server/server/platform/http/problem-reply.js +10 -0
- package/package.json +2 -1
- package/dist/client/assets/index-B7KwEjTE.js +0 -19
- package/dist/server/server/features/plans/application/native-plan-alignment.js +0 -39
|
@@ -8,53 +8,25 @@ import fastifyCookie from '@fastify/cookie';
|
|
|
8
8
|
import fastify, {} from 'fastify';
|
|
9
9
|
import { registerGetHealth } from './features/health/get-health/endpoint.js';
|
|
10
10
|
import { registerGetBootstrap } from './features/catalog/get-bootstrap/endpoint.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { registerCheckoutBranch } from './features/git/checkout-branch/endpoint.js';
|
|
16
|
-
import { registerCloneRepository } from './features/git/clone-repository/endpoint.js';
|
|
17
|
-
import { registerGetSession } from './features/sessions/get-session/endpoint.js';
|
|
18
|
-
import { registerListSessions } from './features/sessions/list-sessions/endpoint.js';
|
|
19
|
-
import { registerListRecentThreads, } from './features/sessions/list-recent-threads/endpoint.js';
|
|
20
|
-
import { registerPromoteRecentThread } from './features/sessions/promote-recent-thread/endpoint.js';
|
|
21
|
-
import { registerGetHistory } from './features/sessions/get-history/endpoint.js';
|
|
22
|
-
import { registerStartSession } from './features/sessions/start-session/endpoint.js';
|
|
23
|
-
import { registerStartTurn } from './features/sessions/start-turn/endpoint.js';
|
|
24
|
-
import { registerSelectModel } from './features/sessions/select-model/endpoint.js';
|
|
25
|
-
import { registerInterruptTurn } from './features/sessions/interrupt-turn/endpoint.js';
|
|
26
|
-
import { registerStopSession } from './features/sessions/stop-session/endpoint.js';
|
|
27
|
-
import { registerRestoreSession } from './features/sessions/restore-session/endpoint.js';
|
|
28
|
-
import { registerReleaseSession } from './features/sessions/release-session/endpoint.js';
|
|
29
|
-
import { registerForgetSession } from './features/sessions/forget-session/endpoint.js';
|
|
30
|
-
import { registerRespondInteraction } from './features/sessions/respond-interaction/endpoint.js';
|
|
31
|
-
import { stopSession } from './features/sessions/lifecycle/use-case.js';
|
|
32
|
-
import { registerSessionEvents } from './features/sessions/session-events/endpoint.js';
|
|
33
|
-
import { registerGetPlan } from './features/plans/get-plan/endpoint.js';
|
|
34
|
-
import { registerGetWorkspacePlan } from './features/plans/get-workspace-plan/endpoint.js';
|
|
35
|
-
import { registerListWorkspacePlans } from './features/plans/list-workspace-plans/endpoint.js';
|
|
36
|
-
import { registerClosePlan } from './features/plans/close-plan/endpoint.js';
|
|
37
|
-
import { registerGetPlanMeasurement } from './features/plans/get-measurement/endpoint.js';
|
|
11
|
+
import { registerAuthRoutes } from './features/auth/register-routes.js';
|
|
12
|
+
import { registerGitRoutes } from './features/git/register-routes.js';
|
|
13
|
+
import { registerPlanRoutes } from './features/plans/register-routes.js';
|
|
14
|
+
import { registerSessionRoutes } from './features/sessions/register-routes.js';
|
|
38
15
|
import { registerProblemHandler } from './platform/http/problem-handler.js';
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import { registerListSkillProfiles, } from './features/skills/list-profiles/endpoint.js';
|
|
42
|
-
import { registerReplaceSkillProfile, } from './features/skills/replace-profile/endpoint.js';
|
|
43
|
-
import { registerDeleteSkillProfile, } from './features/skills/delete-profile/endpoint.js';
|
|
44
|
-
import { registerRegistrationOptions } from './features/auth/register/options/endpoint.js';
|
|
45
|
-
import { registerRegistrationVerification } from './features/auth/register/verify/endpoint.js';
|
|
46
|
-
import { registerLoginOptions } from './features/auth/login/options/endpoint.js';
|
|
47
|
-
import { registerLoginVerification } from './features/auth/login/verify/endpoint.js';
|
|
48
|
-
import { registerAuthStatus, registerDisabledAuthStatus, } from './features/auth/status/endpoint.js';
|
|
49
|
-
import { registerLogout } from './features/auth/logout/endpoint.js';
|
|
50
|
-
import { registerListAuthorizedDevices } from './features/auth/devices/list/endpoint.js';
|
|
51
|
-
import { registerRenameAuthorizedDevice } from './features/auth/devices/rename/endpoint.js';
|
|
52
|
-
import { registerRevokeAuthorizedDevice } from './features/auth/devices/revoke/endpoint.js';
|
|
53
|
-
import { registerCreateEnrollmentTicket } from './features/auth/enrollment-tickets/endpoint.js';
|
|
54
|
-
import { registerEnrollmentTicketStatus } from './features/auth/enrollment-tickets/status/endpoint.js';
|
|
55
|
-
import { registerCancelEnrollmentTicket } from './features/auth/enrollment-tickets/cancel/endpoint.js';
|
|
16
|
+
import { registerAuthorizationBoundary } from './platform/http/authorization-boundary.js';
|
|
17
|
+
import { registerSkillRoutes } from './features/skills/register-routes.js';
|
|
56
18
|
export async function buildApp(deps) {
|
|
57
|
-
|
|
19
|
+
// Keep the default boundary finite even when an endpoint forgot a narrower schema.
|
|
20
|
+
const app = fastify({ logger: false, bodyLimit: 1024 * 1024 });
|
|
21
|
+
app.addHook('onSend', async (_request, reply, payload) => {
|
|
22
|
+
reply.header('Content-Security-Policy', "default-src 'self'; base-uri 'self'; object-src 'none'; frame-ancestors 'none'; form-action 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'");
|
|
23
|
+
reply.header('X-Frame-Options', 'DENY');
|
|
24
|
+
reply.header('X-Content-Type-Options', 'nosniff');
|
|
25
|
+
reply.header('Referrer-Policy', 'strict-origin-when-cross-origin');
|
|
26
|
+
// WebAuthn is same-origin; explicitly allow only this origin's ceremony calls.
|
|
27
|
+
reply.header('Permissions-Policy', 'publickey-credentials-get=(self), publickey-credentials-create=(self)');
|
|
28
|
+
return payload;
|
|
29
|
+
});
|
|
58
30
|
await app.register(fastifyCookie);
|
|
59
31
|
if (deps.staticDir)
|
|
60
32
|
await app.register(fastifyStatic, { root: deps.staticDir });
|
|
@@ -65,190 +37,13 @@ export async function buildApp(deps) {
|
|
|
65
37
|
publicOrigin: deps.auth.relyingParty.publicOrigin,
|
|
66
38
|
});
|
|
67
39
|
registerGetHealth(app, deps.health);
|
|
68
|
-
|
|
69
|
-
registerRegistrationOptions(app, deps.auth);
|
|
70
|
-
registerRegistrationVerification(app, deps.auth);
|
|
71
|
-
registerLoginOptions(app, deps.auth);
|
|
72
|
-
registerLoginVerification(app, deps.auth);
|
|
73
|
-
registerAuthStatus(app, deps.auth);
|
|
74
|
-
registerLogout(app, deps.auth);
|
|
75
|
-
registerListAuthorizedDevices(app, deps.auth);
|
|
76
|
-
registerRenameAuthorizedDevice(app, deps.auth);
|
|
77
|
-
registerRevokeAuthorizedDevice(app, deps.auth);
|
|
78
|
-
registerCreateEnrollmentTicket(app, deps.auth);
|
|
79
|
-
registerEnrollmentTicketStatus(app, deps.auth);
|
|
80
|
-
registerCancelEnrollmentTicket(app, deps.auth);
|
|
81
|
-
}
|
|
82
|
-
else if (deps.passkeyAuthDisabled)
|
|
83
|
-
registerDisabledAuthStatus(app);
|
|
40
|
+
registerAuthRoutes(app, deps);
|
|
84
41
|
if (deps.bootstrap)
|
|
85
42
|
registerGetBootstrap(app, deps.bootstrap);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const session = deps.sessionRoutes
|
|
91
|
-
?.list?.()
|
|
92
|
-
.find((candidate) => candidate.threadId === threadId);
|
|
93
|
-
if (!session)
|
|
94
|
-
return null;
|
|
95
|
-
return {
|
|
96
|
-
...(session.model === undefined ? {} : { model: session.model }),
|
|
97
|
-
...(session.effectiveSkillSelection?.selectedProfileName === undefined
|
|
98
|
-
? {}
|
|
99
|
-
: { skillProfile: session.effectiveSkillSelection.selectedProfileName }),
|
|
100
|
-
...(session.lastOrgPlan === undefined
|
|
101
|
-
? {}
|
|
102
|
-
: { orgPlanFilename: session.lastOrgPlan.filename }),
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
if (deps.sessionRoutes) {
|
|
107
|
-
registerStartSession(app, {
|
|
108
|
-
...deps.sessionRoutes,
|
|
109
|
-
reportFailure: (operation, error) => deps.logger.error(`${operation} failed: ${safeErrorLabel(error)}`),
|
|
110
|
-
});
|
|
111
|
-
registerGetSession(app, deps.sessionRoutes.find);
|
|
112
|
-
if (deps.sessionRoutes.list)
|
|
113
|
-
registerListSessions(app, { list: deps.sessionRoutes.list });
|
|
114
|
-
if (deps.sessionRoutes.readHistory)
|
|
115
|
-
registerGetHistory(app, {
|
|
116
|
-
find: deps.sessionRoutes.find,
|
|
117
|
-
read: deps.sessionRoutes.readHistory,
|
|
118
|
-
currentSequence: deps.sessionRoutes.currentSequence ?? (() => 0),
|
|
119
|
-
});
|
|
120
|
-
if (deps.sessionRoutes.startTurn)
|
|
121
|
-
registerStartTurn(app, {
|
|
122
|
-
find: deps.sessionRoutes.find,
|
|
123
|
-
start: deps.sessionRoutes.startTurn,
|
|
124
|
-
save: deps.sessionRoutes.save,
|
|
125
|
-
onStarted: deps.sessionRoutes.onTurnStarted,
|
|
126
|
-
});
|
|
127
|
-
if (deps.sessionRoutes.models)
|
|
128
|
-
registerSelectModel(app, {
|
|
129
|
-
find: deps.sessionRoutes.find,
|
|
130
|
-
models: () => deps.sessionRoutes.models.list(),
|
|
131
|
-
now: deps.sessionRoutes.now,
|
|
132
|
-
save: deps.sessionRoutes.save,
|
|
133
|
-
});
|
|
134
|
-
if (deps.sessionRoutes.interruptTurn)
|
|
135
|
-
registerInterruptTurn(app, {
|
|
136
|
-
find: deps.sessionRoutes.find,
|
|
137
|
-
interrupt: deps.sessionRoutes.interruptTurn,
|
|
138
|
-
});
|
|
139
|
-
if (deps.sessionRoutes.restore)
|
|
140
|
-
registerRestoreSession(app, {
|
|
141
|
-
find: deps.sessionRoutes.find,
|
|
142
|
-
restore: deps.sessionRoutes.restore,
|
|
143
|
-
save: deps.sessionRoutes.save,
|
|
144
|
-
idempotency: deps.sessionRoutes.idempotency,
|
|
145
|
-
});
|
|
146
|
-
if (deps.recentThreads && deps.sessionRoutes.promoteRecent)
|
|
147
|
-
registerPromoteRecentThread(app, {
|
|
148
|
-
list: () => deps.recentThreads.list(),
|
|
149
|
-
promote: deps.sessionRoutes.promoteRecent,
|
|
150
|
-
});
|
|
151
|
-
if (deps.sessionRoutes.release && deps.sessionRoutes.close)
|
|
152
|
-
registerReleaseSession(app, {
|
|
153
|
-
find: deps.sessionRoutes.find,
|
|
154
|
-
release: deps.sessionRoutes.release,
|
|
155
|
-
save: deps.sessionRoutes.save,
|
|
156
|
-
close: deps.sessionRoutes.close,
|
|
157
|
-
idempotency: deps.sessionRoutes.idempotency,
|
|
158
|
-
});
|
|
159
|
-
if (deps.sessionRoutes.remove && deps.sessionRoutes.close)
|
|
160
|
-
registerForgetSession(app, {
|
|
161
|
-
find: deps.sessionRoutes.find,
|
|
162
|
-
close: deps.sessionRoutes.close,
|
|
163
|
-
remove: deps.sessionRoutes.remove,
|
|
164
|
-
});
|
|
165
|
-
if (deps.sessionRoutes.close)
|
|
166
|
-
registerStopSession(app, {
|
|
167
|
-
find: deps.sessionRoutes.find,
|
|
168
|
-
stop: (session) => stopSession(session, deps.sessionRoutes.now()),
|
|
169
|
-
save: deps.sessionRoutes.save,
|
|
170
|
-
close: deps.sessionRoutes.close,
|
|
171
|
-
idempotency: deps.sessionRoutes.idempotency,
|
|
172
|
-
});
|
|
173
|
-
if (deps.sessionRoutes.replyInteraction && deps.interactions)
|
|
174
|
-
registerRespondInteraction(app, {
|
|
175
|
-
exists: (id) => deps.sessionRoutes.find(id) !== null,
|
|
176
|
-
resolve: (sessionId, requestId, resolvedAt) => deps.interactions.resolve(sessionId, requestId, resolvedAt),
|
|
177
|
-
validate: deps.interactions.validate,
|
|
178
|
-
reply: deps.sessionRoutes.replyInteraction,
|
|
179
|
-
resolved: deps.sessionRoutes.interactionResolved,
|
|
180
|
-
now: deps.sessionRoutes.now,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
if (deps.sessionEvents)
|
|
184
|
-
registerSessionEvents(app, {
|
|
185
|
-
...deps.sessionEvents,
|
|
186
|
-
...(deps.auth
|
|
187
|
-
? {
|
|
188
|
-
publicOrigin: deps.auth.relyingParty.publicOrigin,
|
|
189
|
-
authorized: (cookieHeader) => authorizationSessionDevice(cookieHeader, deps.auth) !== null,
|
|
190
|
-
}
|
|
191
|
-
: {}),
|
|
192
|
-
});
|
|
193
|
-
if (deps.planRoutes) {
|
|
194
|
-
registerGetPlan(app, deps.planRoutes);
|
|
195
|
-
registerClosePlan(app, deps.planRoutes);
|
|
196
|
-
}
|
|
197
|
-
if (deps.workspacePlanRoutes) {
|
|
198
|
-
registerListWorkspacePlans(app, deps.workspacePlanRoutes);
|
|
199
|
-
registerGetWorkspacePlan(app, deps.workspacePlanRoutes);
|
|
200
|
-
}
|
|
201
|
-
if (deps.planMeasurementRoutes)
|
|
202
|
-
registerGetPlanMeasurement(app, deps.planMeasurementRoutes);
|
|
203
|
-
if (deps.gitSummary)
|
|
204
|
-
registerGetGitSummary(app, {
|
|
205
|
-
workspaces: deps.gitSummary.workspaces,
|
|
206
|
-
inspect: deps.gitSummary.inspect,
|
|
207
|
-
});
|
|
208
|
-
if (deps.gitSummary)
|
|
209
|
-
registerPushUpstream(app, {
|
|
210
|
-
workspaces: deps.gitSummary.workspaces,
|
|
211
|
-
inspect: deps.gitSummary.inspectForPush ?? deps.gitSummary.inspect,
|
|
212
|
-
push: deps.gitSummary.push,
|
|
213
|
-
idempotency: deps.gitSummary.idempotency,
|
|
214
|
-
});
|
|
215
|
-
if (deps.gitSummary)
|
|
216
|
-
registerRefreshGit(app, {
|
|
217
|
-
workspaces: deps.gitSummary.workspaces,
|
|
218
|
-
refresh: deps.gitSummary.refresh,
|
|
219
|
-
idempotency: deps.gitSummary.idempotency,
|
|
220
|
-
});
|
|
221
|
-
if (deps.gitSummary?.pull && deps.gitSummary.checkout) {
|
|
222
|
-
registerPullRebase(app, {
|
|
223
|
-
workspaces: deps.gitSummary.workspaces,
|
|
224
|
-
pull: deps.gitSummary.pull,
|
|
225
|
-
});
|
|
226
|
-
registerCheckoutBranch(app, {
|
|
227
|
-
workspaces: deps.gitSummary.workspaces,
|
|
228
|
-
checkout: deps.gitSummary.checkout,
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (deps.gitSummary?.clone)
|
|
232
|
-
registerCloneRepository(app, {
|
|
233
|
-
workspaces: deps.gitSummary.workspaces,
|
|
234
|
-
clone: deps.gitSummary.clone,
|
|
235
|
-
});
|
|
236
|
-
if (deps.skills) {
|
|
237
|
-
registerListAvailableSkills(app, deps.skills);
|
|
238
|
-
registerListSkillProfiles(app, deps.skills);
|
|
239
|
-
registerReplaceSkillProfile(app, deps.skills);
|
|
240
|
-
registerDeleteSkillProfile(app, deps.skills);
|
|
241
|
-
}
|
|
43
|
+
registerSessionRoutes(app, deps);
|
|
44
|
+
registerPlanRoutes(app, deps);
|
|
45
|
+
registerGitRoutes(app, deps);
|
|
46
|
+
registerSkillRoutes(app, deps);
|
|
242
47
|
registerProblemHandler(app, Boolean(deps.staticDir));
|
|
243
48
|
return app;
|
|
244
49
|
}
|
|
245
|
-
function safeErrorLabel(error) {
|
|
246
|
-
if (typeof error === 'object' && error !== null && 'code' in error) {
|
|
247
|
-
const code = error.code;
|
|
248
|
-
if (typeof code === 'string' && /^[A-Z0-9_]+$/.test(code))
|
|
249
|
-
return code;
|
|
250
|
-
}
|
|
251
|
-
if (error instanceof Error && /^[A-Z0-9_]+$/.test(error.message))
|
|
252
|
-
return error.message;
|
|
253
|
-
return error instanceof Error ? error.name : 'UNKNOWN_ERROR';
|
|
254
|
-
}
|
|
@@ -40,7 +40,6 @@ import { CodexSkillCatalog } from './platform/skills/codex-skill-catalog.js';
|
|
|
40
40
|
import { CachedSkillCatalog } from './platform/skills/cached-skill-catalog.js';
|
|
41
41
|
import { compileSkillOverride } from './features/skills/model/skill-profile.js';
|
|
42
42
|
import { SupervisedPlanRegistry } from './features/plans/application/supervised-plan-registry.js';
|
|
43
|
-
import { NativePlanAlignmentRegistry } from './features/plans/application/native-plan-alignment.js';
|
|
44
43
|
import { FilesystemPlanStatusSource } from './platform/plans/filesystem-plan-status-source.js';
|
|
45
44
|
import { FilesystemWorkspacePlanCatalog } from './platform/plans/filesystem-workspace-plan-catalog.js';
|
|
46
45
|
import { checkpointPlanMeasurement } from './platform/plans/plan-measurement-command.js';
|
|
@@ -74,7 +73,6 @@ export async function composeRelayApp(options) {
|
|
|
74
73
|
const interactions = new SqlitePendingInteractionStore(database);
|
|
75
74
|
const idempotency = new SqliteIdempotencyStore(database);
|
|
76
75
|
const supervisedPlans = new SupervisedPlanRegistry();
|
|
77
|
-
const nativePlanAlignment = new NativePlanAlignmentRegistry();
|
|
78
76
|
const planStatusSource = new FilesystemPlanStatusSource(join(dirname(databasePath), 'plans'));
|
|
79
77
|
const workspacePlanCatalog = new FilesystemWorkspacePlanCatalog();
|
|
80
78
|
const planMeasurementHelperPath = options.planMeasurementHelperPath ?? process.env.GESTALT_MOBILE_ORG_PLAN_HELPER;
|
|
@@ -114,8 +112,6 @@ export async function composeRelayApp(options) {
|
|
|
114
112
|
const runtime = options.startAppServers
|
|
115
113
|
? new CodexSessionRuntime(options.launchAppServer ?? launchCodexAppServer, undefined, (sessionId, notification) => {
|
|
116
114
|
const occurredAt = new Date().toISOString();
|
|
117
|
-
if (notification.method === 'turn/plan/updated')
|
|
118
|
-
nativePlanAlignment.observe(sessionId, sessions.find(sessionId)?.threadId ?? null, notification.params);
|
|
119
115
|
const normalized = normalizeCodexNotification(sessionId, 0, occurredAt, notification, sessions.find(sessionId)?.workspacePath);
|
|
120
116
|
if (!normalized)
|
|
121
117
|
return;
|
|
@@ -141,7 +137,6 @@ export async function composeRelayApp(options) {
|
|
|
141
137
|
supervisedPlans.accept(sessionId, update);
|
|
142
138
|
planMeasurementRefresh?.accept(sessionId, update);
|
|
143
139
|
if (update.kind === 'updated') {
|
|
144
|
-
nativePlanAlignment.replace(sessionId, update.plan);
|
|
145
140
|
void runtime?.syncThreadPlanName(sessionId, update.plan);
|
|
146
141
|
const occurredAt = new Date().toISOString();
|
|
147
142
|
const session = sessions.find(sessionId);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Process-local by design: the relay's authorization database is local state. */
|
|
2
|
+
export class ExpiringCeremonyAttemptGate {
|
|
3
|
+
limit;
|
|
4
|
+
windowMs;
|
|
5
|
+
#attempts = new Map();
|
|
6
|
+
constructor(limit = 8, windowMs = 10 * 60 * 1000) {
|
|
7
|
+
this.limit = limit;
|
|
8
|
+
this.windowMs = windowMs;
|
|
9
|
+
}
|
|
10
|
+
allow(key, now) {
|
|
11
|
+
const old = this.#attempts.get(key);
|
|
12
|
+
const expires = now.getTime() + this.windowMs;
|
|
13
|
+
if (!old || old.expires <= now.getTime()) {
|
|
14
|
+
this.#attempts.set(key, { count: 1, expires });
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (old.count >= this.limit)
|
|
18
|
+
return false;
|
|
19
|
+
old.count++;
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -5,3 +5,10 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export class AuthorizationDomainError extends Error {
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* A finite persistent ceremony pool prevents abandoned browser attempts from
|
|
10
|
+
* indefinitely consuming local authorization state. Endpoints intentionally
|
|
11
|
+
* map this to their existing non-enumerating failure response.
|
|
12
|
+
*/
|
|
13
|
+
export class CeremonyCapacityError extends AuthorizationDomainError {
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const seconds = { gestalt_mobile_login: 600, gestalt_mobile_registration: 600, gestalt_mobile_session: 30 * 24 * 60 * 60 };
|
|
2
|
+
function options(name, origin) {
|
|
3
|
+
return { httpOnly: true, sameSite: 'strict', path: '/', secure: origin.startsWith('https://'), maxAge: seconds[name] };
|
|
4
|
+
}
|
|
5
|
+
export function setAuthCookie(reply, name, value, origin) {
|
|
6
|
+
reply.setCookie(name, value, options(name, origin));
|
|
7
|
+
}
|
|
8
|
+
export function clearAuthCookie(reply, name, origin) {
|
|
9
|
+
reply.clearCookie(name, options(name, origin));
|
|
10
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { sendProblem } from '../../../../platform/http/problem-reply.js';
|
|
3
3
|
import { passkeyCeremonyId } from '../../domain/identifiers.js';
|
|
4
|
+
import { CeremonyCapacityError } from '../../domain/errors.js';
|
|
5
|
+
import { setAuthCookie } from '../../http/cookies.js';
|
|
4
6
|
const lifetimeMs = 10 * 60 * 1000;
|
|
5
7
|
const responseSchema = z
|
|
6
8
|
.object({ options: z.object({ challenge: z.string().min(1) }).passthrough() })
|
|
7
9
|
.strict();
|
|
8
10
|
export function registerLoginOptions(app, deps) {
|
|
9
|
-
app.post('/api/auth/login/options', async (
|
|
11
|
+
app.post('/api/auth/login/options', { bodyLimit: 1024 }, async (request, reply) => {
|
|
12
|
+
if (!deps.ceremonyAttempts.allow(`login:${request.ip}`, deps.clock.now()))
|
|
13
|
+
return sendProblem(reply, 'AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.');
|
|
10
14
|
if (deps.repository.listAuthorizedDevices().length === 0)
|
|
11
|
-
return reply
|
|
12
|
-
.code(400)
|
|
13
|
-
.type('application/problem+json')
|
|
14
|
-
.send(problem('AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.'));
|
|
15
|
+
return sendProblem(reply, 'AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.');
|
|
15
16
|
const correlation = deps.random.bytes(32);
|
|
16
17
|
const challenge = deps.random.bytes(32);
|
|
17
18
|
if (correlation.length !== 32 || challenge.length !== 32)
|
|
@@ -25,20 +26,21 @@ export function registerLoginOptions(app, deps) {
|
|
|
25
26
|
}),
|
|
26
27
|
});
|
|
27
28
|
const token = passkeyCeremonyId(Buffer.from(correlation).toString('base64url'));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
29
|
+
try {
|
|
30
|
+
deps.repository.saveCeremony(token, {
|
|
31
|
+
purpose: 'authentication',
|
|
32
|
+
challenge,
|
|
33
|
+
expectedOrigin: deps.relyingParty.publicOrigin,
|
|
34
|
+
rpId: deps.relyingParty.rpId,
|
|
35
|
+
expiresAt: new Date(now.getTime() + lifetimeMs).toISOString(),
|
|
36
|
+
}, now.toISOString());
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (error instanceof CeremonyCapacityError)
|
|
40
|
+
return sendProblem(reply, 'AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.');
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
setAuthCookie(reply, 'gestalt_mobile_login', token, deps.relyingParty.publicOrigin);
|
|
42
44
|
return reply.send(options);
|
|
43
45
|
});
|
|
44
46
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { sendProblem } from '../../../../platform/http/problem-reply.js';
|
|
3
3
|
import { PasskeyVerificationError, } from '../../application/ports.js';
|
|
4
4
|
import { passkeyCeremonyId, webAuthnCredentialId } from '../../domain/identifiers.js';
|
|
5
|
+
import { clearAuthCookie, setAuthCookie } from '../../http/cookies.js';
|
|
5
6
|
const responseSchema = z
|
|
6
7
|
.object({
|
|
7
8
|
id: z.string().min(1),
|
|
@@ -22,13 +23,10 @@ const responseSchema = z
|
|
|
22
23
|
const requestSchema = z.object({ response: responseSchema }).strict();
|
|
23
24
|
const lifetimeMs = 30 * 24 * 60 * 60 * 1000;
|
|
24
25
|
export function registerLoginVerification(app, deps) {
|
|
25
|
-
app.post('/api/auth/login/verify', async (request, reply) => {
|
|
26
|
+
app.post('/api/auth/login/verify', { bodyLimit: 64 * 1024 }, async (request, reply) => {
|
|
26
27
|
const parsed = requestSchema.safeParse(request.body);
|
|
27
28
|
const token = request.cookies.gestalt_mobile_login;
|
|
28
|
-
const fail = () => reply
|
|
29
|
-
.code(400)
|
|
30
|
-
.type('application/problem+json')
|
|
31
|
-
.send(problem('AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.'));
|
|
29
|
+
const fail = () => sendProblem(reply, 'AUTHENTICATION_FAILED', 400, 'Authentication could not be completed.');
|
|
32
30
|
if (!parsed.success || typeof token !== 'string')
|
|
33
31
|
return fail();
|
|
34
32
|
const now = deps.clock.now();
|
|
@@ -69,14 +67,8 @@ export function registerLoginVerification(app, deps) {
|
|
|
69
67
|
});
|
|
70
68
|
if (!authenticated)
|
|
71
69
|
return fail();
|
|
72
|
-
reply
|
|
73
|
-
|
|
74
|
-
sameSite: 'strict',
|
|
75
|
-
path: '/',
|
|
76
|
-
secure: deps.relyingParty.publicOrigin.startsWith('https://'),
|
|
77
|
-
maxAge: 2592000,
|
|
78
|
-
});
|
|
79
|
-
reply.clearCookie('gestalt_mobile_login', { path: '/' });
|
|
70
|
+
setAuthCookie(reply, 'gestalt_mobile_session', session, deps.relyingParty.publicOrigin);
|
|
71
|
+
clearAuthCookie(reply, 'gestalt_mobile_login', deps.relyingParty.publicOrigin);
|
|
80
72
|
return reply.send({ status: 'authenticated' });
|
|
81
73
|
}
|
|
82
74
|
catch (error) {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { parseAuthorizationSessionId } from '../domain/identifiers.js';
|
|
2
|
+
import { clearAuthCookie } from '../http/cookies.js';
|
|
2
3
|
export function registerLogout(app, deps) {
|
|
3
4
|
app.post('/api/auth/logout', async (request, reply) => {
|
|
4
5
|
const token = request.cookies.gestalt_mobile_session;
|
|
5
6
|
const session = parseAuthorizationSessionId(token);
|
|
6
7
|
if (session !== null)
|
|
7
8
|
deps.repository.revokeSession(session, deps.clock.now().toISOString());
|
|
8
|
-
reply
|
|
9
|
-
path: '/',
|
|
10
|
-
httpOnly: true,
|
|
11
|
-
sameSite: 'strict',
|
|
12
|
-
secure: deps.relyingParty.publicOrigin.startsWith('https://'),
|
|
13
|
-
});
|
|
9
|
+
clearAuthCookie(reply, 'gestalt_mobile_session', deps.relyingParty.publicOrigin);
|
|
14
10
|
return reply.code(204).send();
|
|
15
11
|
});
|
|
16
12
|
}
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { sendProblem } from '../../../../platform/http/problem-reply.js';
|
|
3
3
|
import { parseEnrollmentTicketId, passkeyCeremonyId } from '../../domain/identifiers.js';
|
|
4
|
+
import { CeremonyCapacityError } from '../../domain/errors.js';
|
|
5
|
+
import { setAuthCookie } from '../../http/cookies.js';
|
|
4
6
|
const requestSchema = z.object({ enrollmentTicket: z.string().min(1).optional() }).strict();
|
|
5
|
-
const optionsResponseSchema = z
|
|
7
|
+
const optionsResponseSchema = z
|
|
8
|
+
.object({ options: z.object({ challenge: z.string().min(1) }).passthrough() })
|
|
9
|
+
.strict();
|
|
6
10
|
const lifetimeMs = 10 * 60 * 1000;
|
|
7
11
|
export function registerRegistrationOptions(app, deps) {
|
|
8
|
-
app.post('/api/auth/register/options', async (request, reply) => {
|
|
12
|
+
app.post('/api/auth/register/options', { bodyLimit: 4 * 1024 }, async (request, reply) => {
|
|
13
|
+
if (!deps.ceremonyAttempts.allow(`register:${request.ip}`, deps.clock.now()))
|
|
14
|
+
return sendProblem(reply, 'REGISTRATION_NOT_AVAILABLE', 400, 'Registration could not be completed.');
|
|
9
15
|
const parsed = requestSchema.safeParse(request.body);
|
|
10
16
|
if (!parsed.success)
|
|
11
|
-
return reply
|
|
12
|
-
const ticket = parsed.data.enrollmentTicket === undefined
|
|
17
|
+
return sendProblem(reply, 'INVALID_REGISTRATION_REQUEST', 400, 'The registration request is invalid.');
|
|
18
|
+
const ticket = parsed.data.enrollmentTicket === undefined
|
|
19
|
+
? undefined
|
|
20
|
+
: parseEnrollmentTicketId(parsed.data.enrollmentTicket);
|
|
13
21
|
if (ticket === null)
|
|
14
|
-
return reply
|
|
22
|
+
return sendProblem(reply, 'INVALID_REGISTRATION_REQUEST', 400, 'The registration request is invalid.');
|
|
15
23
|
const owner = deps.repository.readOwner();
|
|
16
24
|
const devices = deps.repository.listAuthorizedDevices();
|
|
17
25
|
const now = deps.clock.now();
|
|
18
|
-
if (devices.length > 0 &&
|
|
19
|
-
|
|
26
|
+
if (devices.length > 0 &&
|
|
27
|
+
(!ticket || !deps.repository.ticketAvailable(ticket, now.toISOString())))
|
|
28
|
+
return sendProblem(reply, 'ENROLLMENT_NOT_AUTHORIZED', 403, 'Registration is not authorized.');
|
|
20
29
|
const ownerHandle = owner ? undefined : deps.random.bytes(32);
|
|
21
30
|
if (ownerHandle && ownerHandle.length !== 32)
|
|
22
31
|
throw new Error('AUTHORIZATION_RANDOMNESS_INVALID');
|
|
@@ -26,9 +35,32 @@ export function registerRegistrationOptions(app, deps) {
|
|
|
26
35
|
if (correlation.length !== 32 || challenge.length !== 32)
|
|
27
36
|
throw new Error('AUTHORIZATION_RANDOMNESS_INVALID');
|
|
28
37
|
const token = passkeyCeremonyId(Buffer.from(correlation).toString('base64url'));
|
|
29
|
-
const options = optionsResponseSchema.parse({
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
const options = optionsResponseSchema.parse({
|
|
39
|
+
options: await deps.webauthn.registrationOptions({
|
|
40
|
+
challenge,
|
|
41
|
+
rpId: deps.relyingParty.rpId,
|
|
42
|
+
userVerification: 'required',
|
|
43
|
+
rpName: deps.relyingParty.rpName,
|
|
44
|
+
userHandle: initialized.userHandle,
|
|
45
|
+
excludeCredentialIds: devices.map((device) => device.credentialId),
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
deps.repository.saveCeremony(token, {
|
|
50
|
+
purpose: 'registration',
|
|
51
|
+
challenge,
|
|
52
|
+
expectedOrigin: deps.relyingParty.publicOrigin,
|
|
53
|
+
rpId: deps.relyingParty.rpId,
|
|
54
|
+
expiresAt: new Date(now.getTime() + lifetimeMs).toISOString(),
|
|
55
|
+
...(ticket ? { enrollmentTicket: ticket } : {}),
|
|
56
|
+
}, now.toISOString());
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof CeremonyCapacityError)
|
|
60
|
+
return sendProblem(reply, 'REGISTRATION_NOT_AVAILABLE', 400, 'Registration could not be completed.');
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
setAuthCookie(reply, 'gestalt_mobile_registration', token, deps.relyingParty.publicOrigin);
|
|
32
64
|
return reply.send(options);
|
|
33
65
|
});
|
|
34
66
|
}
|
|
@@ -4,6 +4,7 @@ import { PasskeyVerificationError } from '../../application/ports.js';
|
|
|
4
4
|
import { deviceNickname } from '../../domain/device-nickname.js';
|
|
5
5
|
import { passkeyCeremonyId } from '../../domain/identifiers.js';
|
|
6
6
|
import { AuthorizationDomainError } from '../../domain/errors.js';
|
|
7
|
+
import { clearAuthCookie, setAuthCookie } from '../../http/cookies.js';
|
|
7
8
|
const registrationResponseSchema = z.object({
|
|
8
9
|
id: z.string().min(1), rawId: z.string().min(1), type: z.literal('public-key'),
|
|
9
10
|
response: z.object({ clientDataJSON: z.string().min(1), attestationObject: z.string().min(1), authenticatorData: z.string().min(1).optional(), transports: z.array(z.enum(['ble', 'hybrid', 'internal', 'nfc', 'usb', 'cable', 'smart-card'])).optional(), publicKeyAlgorithm: z.number().int().optional(), publicKey: z.string().min(1).optional() }).strict(),
|
|
@@ -13,7 +14,7 @@ const requestSchema = z.object({ response: registrationResponseSchema, nickname:
|
|
|
13
14
|
const successSchema = z.object({ status: z.literal('authenticated') }).strict();
|
|
14
15
|
const sessionLifetimeMs = 30 * 24 * 60 * 60 * 1000;
|
|
15
16
|
export function registerRegistrationVerification(app, deps) {
|
|
16
|
-
app.post('/api/auth/register/verify', async (request, reply) => {
|
|
17
|
+
app.post('/api/auth/register/verify', { bodyLimit: 128 * 1024 }, async (request, reply) => {
|
|
17
18
|
const parsed = requestSchema.safeParse(request.body);
|
|
18
19
|
const token = request.cookies.gestalt_mobile_registration;
|
|
19
20
|
if (!parsed.success || typeof token !== 'string')
|
|
@@ -43,8 +44,8 @@ export function registerRegistrationVerification(app, deps) {
|
|
|
43
44
|
const outcome = deps.repository.completeRegistration({ ceremony: passkeyCeremonyId(token), now: now.toISOString(), device, session: { id: session, deviceId: device.id, expiresAt } });
|
|
44
45
|
if (outcome !== 'registered')
|
|
45
46
|
return reply.code(outcome === 'bootstrapAlreadyClaimed' ? 409 : 400).type('application/problem+json').send(problem(outcome === 'bootstrapAlreadyClaimed' ? 'BOOTSTRAP_ALREADY_CLAIMED' : 'REGISTRATION_NOT_AVAILABLE', outcome === 'bootstrapAlreadyClaimed' ? 409 : 400, 'Registration could not be completed.'));
|
|
46
|
-
reply
|
|
47
|
-
reply
|
|
47
|
+
setAuthCookie(reply, 'gestalt_mobile_session', session, deps.relyingParty.publicOrigin);
|
|
48
|
+
clearAuthCookie(reply, 'gestalt_mobile_registration', deps.relyingParty.publicOrigin);
|
|
48
49
|
return reply.code(201).send(successSchema.parse({ status: 'authenticated' }));
|
|
49
50
|
}
|
|
50
51
|
catch (error) {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2026 Dyne.org foundation
|
|
3
|
+
* Designed by Denis Roio <jaromil@dyne.org>
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import { ExpiringCeremonyAttemptGate } from './application/ceremony-attempts.js';
|
|
7
|
+
import { registerListAuthorizedDevices } from './devices/list/endpoint.js';
|
|
8
|
+
import { registerRenameAuthorizedDevice } from './devices/rename/endpoint.js';
|
|
9
|
+
import { registerRevokeAuthorizedDevice } from './devices/revoke/endpoint.js';
|
|
10
|
+
import { registerCancelEnrollmentTicket } from './enrollment-tickets/cancel/endpoint.js';
|
|
11
|
+
import { registerCreateEnrollmentTicket } from './enrollment-tickets/endpoint.js';
|
|
12
|
+
import { registerEnrollmentTicketStatus } from './enrollment-tickets/status/endpoint.js';
|
|
13
|
+
import { registerLoginOptions } from './login/options/endpoint.js';
|
|
14
|
+
import { registerLoginVerification } from './login/verify/endpoint.js';
|
|
15
|
+
import { registerLogout } from './logout/endpoint.js';
|
|
16
|
+
import { registerRegistrationOptions } from './register/options/endpoint.js';
|
|
17
|
+
import { registerRegistrationVerification } from './register/verify/endpoint.js';
|
|
18
|
+
import { registerAuthStatus, registerDisabledAuthStatus } from './status/endpoint.js';
|
|
19
|
+
/** Registers the complete passkey surface; authorization hooks are composed by app.ts first. */
|
|
20
|
+
export function registerAuthRoutes(app, deps) {
|
|
21
|
+
if (deps.auth) {
|
|
22
|
+
const auth = {
|
|
23
|
+
...deps.auth,
|
|
24
|
+
ceremonyAttempts: deps.auth.ceremonyAttempts ?? new ExpiringCeremonyAttemptGate(),
|
|
25
|
+
};
|
|
26
|
+
registerRegistrationOptions(app, auth);
|
|
27
|
+
registerRegistrationVerification(app, deps.auth);
|
|
28
|
+
registerLoginOptions(app, auth);
|
|
29
|
+
registerLoginVerification(app, deps.auth);
|
|
30
|
+
registerAuthStatus(app, deps.auth);
|
|
31
|
+
registerLogout(app, deps.auth);
|
|
32
|
+
registerListAuthorizedDevices(app, deps.auth);
|
|
33
|
+
registerRenameAuthorizedDevice(app, deps.auth);
|
|
34
|
+
registerRevokeAuthorizedDevice(app, deps.auth);
|
|
35
|
+
registerCreateEnrollmentTicket(app, deps.auth);
|
|
36
|
+
registerEnrollmentTicketStatus(app, deps.auth);
|
|
37
|
+
registerCancelEnrollmentTicket(app, deps.auth);
|
|
38
|
+
}
|
|
39
|
+
else if (deps.passkeyAuthDisabled)
|
|
40
|
+
registerDisabledAuthStatus(app);
|
|
41
|
+
}
|
|
@@ -7,7 +7,7 @@ import { z } from 'zod';
|
|
|
7
7
|
import { resolveRepositoryTarget } from '../application/repository-target.js';
|
|
8
8
|
const requestSchema = z.object({ branch: z.string().min(1) });
|
|
9
9
|
export function registerCheckoutBranch(app, deps) {
|
|
10
|
-
app.post('/api/git/repositories/:workspaceId/checkout', async (request, reply) => {
|
|
10
|
+
app.post('/api/git/repositories/:workspaceId/checkout', { bodyLimit: 8 * 1024 }, async (request, reply) => {
|
|
11
11
|
const target = await resolveRepositoryTarget(deps.workspaces, request.params.workspaceId);
|
|
12
12
|
if (!target.ok)
|
|
13
13
|
return reply.code(target.statusCode).send({ code: target.code });
|
|
@@ -10,7 +10,7 @@ const requestSchema = z.object({
|
|
|
10
10
|
workspaceId: z.string().trim().min(1),
|
|
11
11
|
});
|
|
12
12
|
export function registerCloneRepository(app, deps) {
|
|
13
|
-
app.post('/api/git/clone', async (request, reply) => {
|
|
13
|
+
app.post('/api/git/clone', { bodyLimit: 8 * 1024 }, async (request, reply) => {
|
|
14
14
|
const parsed = requestSchema.safeParse(request.body);
|
|
15
15
|
if (!parsed.success)
|
|
16
16
|
return reply.code(400).send({ code: 'INVALID_CLONE_ADDRESS' });
|