@warlock.js/devtools 5.57.0 → 5.59.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/CHANGELOG.md +23 -0
- package/README.md +3 -0
- package/cjs/{ai-source-DTpxumMA.cjs → ai-source-BdvMfyKw.cjs} +84 -17
- package/cjs/ai-source-BdvMfyKw.cjs.map +1 -0
- package/cjs/app-versions-DfpPZOI2.cjs +253 -0
- package/cjs/app-versions-DfpPZOI2.cjs.map +1 -0
- package/cjs/{auth-DzU0gHDG.cjs → auth-B3wyjJnQ.cjs} +43 -406
- package/cjs/auth-B3wyjJnQ.cjs.map +1 -0
- package/cjs/{boot-Dy5OqgTM.cjs → boot-nczSvJ_F.cjs} +15 -12
- package/cjs/boot-nczSvJ_F.cjs.map +1 -0
- package/cjs/{capture-CqIiaznN.cjs → capture-CuyT8Vab.cjs} +4 -4
- package/cjs/{capture-CqIiaznN.cjs.map → capture-CuyT8Vab.cjs.map} +1 -1
- package/cjs/{cascade-store-pHjKeSFm.cjs → cascade-store-CuRRYzt_.cjs} +141 -4
- package/cjs/cascade-store-CuRRYzt_.cjs.map +1 -0
- package/cjs/{current-request-id-BoJJb3y7.cjs → current-request-id-CeQhRz9Q.cjs} +3 -3
- package/cjs/{current-request-id-BoJJb3y7.cjs.map → current-request-id-CeQhRz9Q.cjs.map} +1 -1
- package/cjs/{errors-CyZp5yS-.cjs → errors-BadbSDX8.cjs} +6 -4
- package/cjs/errors-BadbSDX8.cjs.map +1 -0
- package/cjs/helpers-BcMBFy9v.cjs +439 -0
- package/cjs/helpers-BcMBFy9v.cjs.map +1 -0
- package/cjs/{histogram-BaI-PnCv.cjs → histogram-DTOGnNBW.cjs} +6 -6
- package/cjs/{histogram-BaI-PnCv.cjs.map → histogram-DTOGnNBW.cjs.map} +1 -1
- package/cjs/{http-DCfXQvw-.cjs → http-Biauhqi0.cjs} +517 -28
- package/cjs/http-Biauhqi0.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/{insights-BKtqxdnP.cjs → insights-BjJA6Ret.cjs} +8 -7
- package/cjs/{insights-BKtqxdnP.cjs.map → insights-BjJA6Ret.cjs.map} +1 -1
- package/cjs/{migrations-w7GMsrQw.cjs → migrations-BP4cYTGo.cjs} +40 -5
- package/cjs/migrations-BP4cYTGo.cjs.map +1 -0
- package/cjs/{options-CWqFC5__.cjs → options-B9FHbRAJ.cjs} +29 -5
- package/cjs/options-B9FHbRAJ.cjs.map +1 -0
- package/cjs/{panels-Rcmeitu3.cjs → panels-D1ITm-jc.cjs} +77 -11
- package/cjs/panels-D1ITm-jc.cjs.map +1 -0
- package/cjs/{process-panel-DEOnLxoT.cjs → process-panel-DskSA7Cm.cjs} +4 -4
- package/cjs/{process-panel-DEOnLxoT.cjs.map → process-panel-DskSA7Cm.cjs.map} +1 -1
- package/cjs/production/index.cjs +4 -4
- package/cjs/{server-ykxsOwob.cjs → server-D3XRbSSb.cjs} +8 -5
- package/cjs/server-D3XRbSSb.cjs.map +1 -0
- package/cjs/{src-UPtTCI2j.cjs → src-QcNghoYN.cjs} +52 -15
- package/cjs/src-QcNghoYN.cjs.map +1 -0
- package/cjs/{store-aq207T8v.cjs → store-CNFv3wVp.cjs} +2 -2
- package/cjs/{stream-route-CJTABkUy.cjs → stream-route-BqyAlfxQ.cjs} +92 -17
- package/cjs/stream-route-BqyAlfxQ.cjs.map +1 -0
- package/esm/app-versions.mjs +74 -0
- package/esm/app-versions.mjs.map +1 -0
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +10 -3
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +3 -3
- package/esm/panel-errors.mjs +33 -0
- package/esm/panel-errors.mjs.map +1 -0
- package/esm/panels.mjs +73 -6
- package/esm/panels.mjs.map +1 -1
- package/esm/production/auth/helpers.mjs +8 -5
- package/esm/production/auth/helpers.mjs.map +1 -1
- package/esm/production/auth/service.mjs +15 -5
- package/esm/production/auth/service.mjs.map +1 -1
- package/esm/production/boot.mjs +5 -2
- package/esm/production/boot.mjs.map +1 -1
- package/esm/production/contracts.d.mts +75 -2
- package/esm/production/contracts.d.mts.map +1 -1
- package/esm/production/contracts.mjs +5 -1
- package/esm/production/contracts.mjs.map +1 -1
- package/esm/production/errors.d.mts +1 -1
- package/esm/production/errors.mjs +5 -3
- package/esm/production/errors.mjs.map +1 -1
- package/esm/production/http/access.mjs +6 -2
- package/esm/production/http/access.mjs.map +1 -1
- package/esm/production/http/constants.mjs +7 -1
- package/esm/production/http/constants.mjs.map +1 -1
- package/esm/production/http/context.mjs.map +1 -1
- package/esm/production/http/cookie.mjs +23 -2
- package/esm/production/http/cookie.mjs.map +1 -1
- package/esm/production/http/mount.mjs +25 -3
- package/esm/production/http/mount.mjs.map +1 -1
- package/esm/production/http/share-session.mjs +114 -0
- package/esm/production/http/share-session.mjs.map +1 -0
- package/esm/production/http/share.mjs +339 -0
- package/esm/production/http/share.mjs.map +1 -0
- package/esm/production/index.d.mts +2 -2
- package/esm/production/insights/writer.mjs +2 -1
- package/esm/production/insights/writer.mjs.map +1 -1
- package/esm/production/options.d.mts +10 -1
- package/esm/production/options.d.mts.map +1 -1
- package/esm/production/options.mjs +27 -3
- package/esm/production/options.mjs.map +1 -1
- package/esm/production/store/cascade-store.mjs +49 -2
- package/esm/production/store/cascade-store.mjs.map +1 -1
- package/esm/production/store/mapping.mjs +29 -1
- package/esm/production/store/mapping.mjs.map +1 -1
- package/esm/production/store/memory-store.mjs +62 -0
- package/esm/production/store/memory-store.mjs.map +1 -1
- package/esm/production/store/migrations.d.mts +2 -1
- package/esm/production/store/migrations.d.mts.map +1 -1
- package/esm/production/store/migrations.mjs +5 -2
- package/esm/production/store/migrations.mjs.map +1 -1
- package/esm/production/store/models/index.mjs +3 -1
- package/esm/production/store/models/share.migration.mjs +27 -0
- package/esm/production/store/models/share.migration.mjs.map +1 -0
- package/esm/production/store/models/share.model.mjs +13 -0
- package/esm/production/store/models/share.model.mjs.map +1 -0
- package/esm/server/ai-routes.mjs +20 -6
- package/esm/server/ai-routes.mjs.map +1 -1
- package/esm/server/panel-files.mjs +35 -0
- package/esm/server/panel-files.mjs.map +1 -0
- package/esm/server/panel-routes.mjs +27 -7
- package/esm/server/panel-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +4 -1
- package/esm/server/session-routes.mjs.map +1 -1
- package/esm/sources/ai-source.d.mts.map +1 -1
- package/esm/sources/ai-source.mjs +75 -7
- package/esm/sources/ai-source.mjs.map +1 -1
- package/esm/types.d.mts +91 -3
- package/esm/types.d.mts.map +1 -1
- package/llms-full.txt +57 -19
- package/package.json +8 -8
- package/skills/SKILL.md +57 -19
- package/ui/dashboard/assets/app.css +1 -1
- package/ui/dashboard/assets/app.js +16 -16
- package/ui/dashboard/build-info.json +7 -7
- package/cjs/ai-source-DTpxumMA.cjs.map +0 -1
- package/cjs/auth-DzU0gHDG.cjs.map +0 -1
- package/cjs/boot-Dy5OqgTM.cjs.map +0 -1
- package/cjs/cascade-store-pHjKeSFm.cjs.map +0 -1
- package/cjs/contracts-CVmplkNb.cjs +0 -112
- package/cjs/contracts-CVmplkNb.cjs.map +0 -1
- package/cjs/errors-CyZp5yS-.cjs.map +0 -1
- package/cjs/http-DCfXQvw-.cjs.map +0 -1
- package/cjs/migrations-w7GMsrQw.cjs.map +0 -1
- package/cjs/options-CWqFC5__.cjs.map +0 -1
- package/cjs/panels-Rcmeitu3.cjs.map +0 -1
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +0 -52
- package/cjs/server-ykxsOwob.cjs.map +0 -1
- package/cjs/src-UPtTCI2j.cjs.map +0 -1
- package/cjs/stream-route-CJTABkUy.cjs.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_app_versions = require("./app-versions-DfpPZOI2.cjs");
|
|
2
|
+
const require_panels = require("./panels-D1ITm-jc.cjs");
|
|
3
|
+
const require_errors = require("./errors-BadbSDX8.cjs");
|
|
3
4
|
const require_ip = require("./ip-DbNhPOzi.cjs");
|
|
4
|
-
const
|
|
5
|
+
const require_helpers = require("./helpers-BcMBFy9v.cjs");
|
|
6
|
+
const require_stream_route = require("./stream-route-BqyAlfxQ.cjs");
|
|
5
7
|
let node_crypto = require("node:crypto");
|
|
6
8
|
let node_net = require("node:net");
|
|
7
9
|
|
|
@@ -9,6 +11,7 @@ let node_net = require("node:net");
|
|
|
9
11
|
const PUBLIC = { type: "public" };
|
|
10
12
|
const VIEWER = { type: "viewer" };
|
|
11
13
|
const ADMIN = { type: "admin" };
|
|
14
|
+
const SHARE = { type: "share" };
|
|
12
15
|
const pending = (...stages) => ({
|
|
13
16
|
type: "pending",
|
|
14
17
|
stages
|
|
@@ -23,9 +26,10 @@ const ALL_STEPS = [
|
|
|
23
26
|
* A route with no entry is `admin` (fail closed). A package panel `<id>`
|
|
24
27
|
* gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other
|
|
25
28
|
* method there for admins, audited as `panel.action`; a url ending in `/*`
|
|
26
|
-
* matches every pattern below it.
|
|
29
|
+
* matches every pattern below it. The share routes exist only when
|
|
30
|
+
* `options.share` is `true` (`production.share.enabled`).
|
|
27
31
|
*/
|
|
28
|
-
function productionRouteAccess(panelIds) {
|
|
32
|
+
function productionRouteAccess(panelIds, options = {}) {
|
|
29
33
|
const rule = (method, url, access, audit) => ({
|
|
30
34
|
method,
|
|
31
35
|
url,
|
|
@@ -84,6 +88,7 @@ function productionRouteAccess(panelIds) {
|
|
|
84
88
|
rule("POST", "/api/queries/:shapeId/explain", ADMIN, "explain.run"),
|
|
85
89
|
rule("GET", "/api/routes", VIEWER),
|
|
86
90
|
rule("GET", "/panels/:id/:name", VIEWER),
|
|
91
|
+
rule("GET", "/panels/:id/files/*", VIEWER),
|
|
87
92
|
rule("GET", "/api/mails", VIEWER),
|
|
88
93
|
rule("GET", "/api/mails/:id", VIEWER),
|
|
89
94
|
rule("GET", "/api/mails/:id/html", VIEWER),
|
|
@@ -96,6 +101,7 @@ function productionRouteAccess(panelIds) {
|
|
|
96
101
|
rule("GET", "/docs", VIEWER),
|
|
97
102
|
rule("GET", "/docs/swagger", VIEWER)
|
|
98
103
|
];
|
|
104
|
+
if (options.share === true) rules.push(rule("POST", "/api/share/open", PUBLIC), rule("GET", "/api/share/info", SHARE), rule("GET", "/api/share/view.js", SHARE), rule("GET", "/api/share/assets/:name", SHARE), rule("GET", "/api/share/files/*", SHARE), rule("GET", "/api/share/panel", SHARE), rule("GET", "/api/share/panel/*", SHARE), rule("GET", "/api/admin/shares", ADMIN), rule("POST", "/api/admin/shares", ADMIN), rule("DELETE", "/api/admin/shares/:id", ADMIN), rule("POST", "/api/admin/shares/revoke-all", ADMIN));
|
|
99
105
|
for (const id of panelIds) {
|
|
100
106
|
rules.push(rule("GET", `/api/${id}`, VIEWER), rule("GET", `/api/${id}/*`, VIEWER));
|
|
101
107
|
for (const method of [
|
|
@@ -186,6 +192,12 @@ const DEVTOOLS_CSRF_HEADER = "x-devtools-csrf";
|
|
|
186
192
|
const DEVTOOLS_SESSION_COOKIE = "__Secure-warlock-devtools";
|
|
187
193
|
/** The session cookie name when `requireHttps` is off (local trials only). */
|
|
188
194
|
const DEVTOOLS_SESSION_COOKIE_INSECURE = "warlock-devtools";
|
|
195
|
+
/** The share cookie name over HTTPS. */
|
|
196
|
+
const DEVTOOLS_SHARE_COOKIE = "__Secure-warlock-devtools-share";
|
|
197
|
+
/** The share cookie name when `requireHttps` is off (local trials only). */
|
|
198
|
+
const DEVTOOLS_SHARE_COOKIE_INSECURE = "warlock-devtools-share";
|
|
199
|
+
/** The longest a share cookie lives, whatever the link's expiry: 12 hours. */
|
|
200
|
+
const DEVTOOLS_SHARE_COOKIE_MAX_SECONDS = 43200;
|
|
189
201
|
|
|
190
202
|
//#endregion
|
|
191
203
|
//#region ../../packages/devtools/src/production/http/context.ts
|
|
@@ -233,16 +245,37 @@ function readCookie(header, name) {
|
|
|
233
245
|
}
|
|
234
246
|
}
|
|
235
247
|
}
|
|
248
|
+
/** The share cookie name for the HTTPS mode. */
|
|
249
|
+
function shareCookieName(secure) {
|
|
250
|
+
return secure ? DEVTOOLS_SHARE_COOKIE : DEVTOOLS_SHARE_COOKIE_INSECURE;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* `Set-Cookie` value for a share grant (or a clearing cookie when `value` is
|
|
254
|
+
* `null`). Scoped to the dashboard path, `HttpOnly`, `SameSite=Strict`, no
|
|
255
|
+
* `Domain`, and it ends after `maxAgeSeconds`.
|
|
256
|
+
*/
|
|
257
|
+
function shareCookie(value, options) {
|
|
258
|
+
const parts = [
|
|
259
|
+
`${shareCookieName(options.secure)}=${value ?? ""}`,
|
|
260
|
+
`Path=${options.path}`,
|
|
261
|
+
"HttpOnly",
|
|
262
|
+
"SameSite=Strict"
|
|
263
|
+
];
|
|
264
|
+
if (options.secure) parts.push("Secure");
|
|
265
|
+
if (value === null) parts.push("Max-Age=0", "Expires=Thu, 01 Jan 1970 00:00:00 GMT");
|
|
266
|
+
else parts.push(`Max-Age=${Math.max(1, Math.floor(options.maxAgeSeconds ?? 0))}`);
|
|
267
|
+
return parts.join("; ");
|
|
268
|
+
}
|
|
236
269
|
|
|
237
270
|
//#endregion
|
|
238
271
|
//#region ../../packages/devtools/src/production/http/auth-routes.ts
|
|
239
272
|
const MAX_TEXT = 1024;
|
|
240
273
|
const MAX_EMAIL = 320;
|
|
241
274
|
const MAX_CODE = 128;
|
|
242
|
-
const MAX_TOKEN = 512;
|
|
275
|
+
const MAX_TOKEN$1 = 512;
|
|
243
276
|
const ROLES = ["admin", "viewer"];
|
|
244
277
|
/** A request body that is a plain JSON object, or `input.invalid`. */
|
|
245
|
-
function bodyOf(request) {
|
|
278
|
+
function bodyOf$1(request) {
|
|
246
279
|
const body = request.body;
|
|
247
280
|
if (body === null || typeof body !== "object" || Array.isArray(body)) throw new require_errors.DevtoolsApiError("input.invalid");
|
|
248
281
|
return body;
|
|
@@ -279,7 +312,7 @@ function idParam(request) {
|
|
|
279
312
|
}
|
|
280
313
|
/** The `current` password of a request that may have no body (a DELETE). */
|
|
281
314
|
function currentOf(request) {
|
|
282
|
-
return request.body === void 0 || request.body === null ? void 0 : optionalText(bodyOf(request), "current");
|
|
315
|
+
return request.body === void 0 || request.body === null ? void 0 : optionalText(bodyOf$1(request), "current");
|
|
283
316
|
}
|
|
284
317
|
/** What the gate stored, for a route that is never reached without it. */
|
|
285
318
|
function contextOf(request) {
|
|
@@ -334,7 +367,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
334
367
|
return auth.sessionView(authenticated);
|
|
335
368
|
});
|
|
336
369
|
server.post("/api/auth/login", async (request, reply) => {
|
|
337
|
-
const body = bodyOf(request);
|
|
370
|
+
const body = bodyOf$1(request);
|
|
338
371
|
const step = await auth.login({
|
|
339
372
|
email: email(body),
|
|
340
373
|
password: text(body, "password")
|
|
@@ -342,28 +375,28 @@ function registerAuthRoutes(server, deps) {
|
|
|
342
375
|
return answerStep(reply, step);
|
|
343
376
|
});
|
|
344
377
|
server.post("/api/auth/setup", async (request, reply) => {
|
|
345
|
-
const body = bodyOf(request);
|
|
378
|
+
const body = bodyOf$1(request);
|
|
346
379
|
const step = await auth.setup({
|
|
347
|
-
token: text(body, "token", MAX_TOKEN),
|
|
380
|
+
token: text(body, "token", MAX_TOKEN$1),
|
|
348
381
|
password: text(body, "password")
|
|
349
382
|
}, metaOf(request));
|
|
350
383
|
return answerStep(reply, step);
|
|
351
384
|
});
|
|
352
385
|
server.post("/api/auth/invite/inspect", async (request) => {
|
|
353
|
-
const body = bodyOf(request);
|
|
354
|
-
return auth.inspectInvite(text(body, "token", MAX_TOKEN));
|
|
386
|
+
const body = bodyOf$1(request);
|
|
387
|
+
return auth.inspectInvite(text(body, "token", MAX_TOKEN$1));
|
|
355
388
|
});
|
|
356
389
|
server.post("/api/auth/invite/accept", async (request, reply) => {
|
|
357
|
-
const body = bodyOf(request);
|
|
390
|
+
const body = bodyOf$1(request);
|
|
358
391
|
const step = await auth.acceptInvite({
|
|
359
|
-
token: text(body, "token", MAX_TOKEN),
|
|
392
|
+
token: text(body, "token", MAX_TOKEN$1),
|
|
360
393
|
password: text(body, "password")
|
|
361
394
|
}, metaOf(request));
|
|
362
395
|
return answerStep(reply, step);
|
|
363
396
|
});
|
|
364
397
|
const changePassword = async (request, reply) => {
|
|
365
398
|
const { auth: authenticated, meta } = contextOf(request);
|
|
366
|
-
const body = bodyOf(request);
|
|
399
|
+
const body = bodyOf$1(request);
|
|
367
400
|
const current = optionalText(body, "current");
|
|
368
401
|
const step = await auth.changePassword(authenticated, {
|
|
369
402
|
...current === void 0 ? {} : { current },
|
|
@@ -377,17 +410,17 @@ function registerAuthRoutes(server, deps) {
|
|
|
377
410
|
};
|
|
378
411
|
const confirmTotp = async (request, reply) => {
|
|
379
412
|
const { auth: authenticated, meta } = contextOf(request);
|
|
380
|
-
const body = bodyOf(request);
|
|
413
|
+
const body = bodyOf$1(request);
|
|
381
414
|
const result = await auth.confirmTotp(authenticated, text(body, "code", MAX_CODE), meta, optionalText(body, "current"));
|
|
382
415
|
return answerStep(reply, result.step, result.recoveryCodes);
|
|
383
416
|
};
|
|
384
417
|
const passkeyOptions = async (request) => {
|
|
385
418
|
const { auth: authenticated, meta } = contextOf(request);
|
|
386
|
-
return auth.passkeyOptions(authenticated, purpose(bodyOf(request)), meta);
|
|
419
|
+
return auth.passkeyOptions(authenticated, purpose(bodyOf$1(request)), meta);
|
|
387
420
|
};
|
|
388
421
|
const passkeyVerify = async (request, reply) => {
|
|
389
422
|
const { auth: authenticated, meta } = contextOf(request);
|
|
390
|
-
const body = bodyOf(request);
|
|
423
|
+
const body = bodyOf$1(request);
|
|
391
424
|
if (body.response === null || typeof body.response !== "object") throw new require_errors.DevtoolsApiError("input.invalid");
|
|
392
425
|
const result = await auth.verifyPasskey(authenticated, purpose(body), body.response, meta, optionalText(body, "current"));
|
|
393
426
|
if (result.step === null) return {
|
|
@@ -403,7 +436,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
403
436
|
server.post("/api/auth/passkey/verify", passkeyVerify);
|
|
404
437
|
server.post("/api/auth/mfa", async (request, reply) => {
|
|
405
438
|
const { auth: authenticated, meta } = contextOf(request);
|
|
406
|
-
const body = bodyOf(request);
|
|
439
|
+
const body = bodyOf$1(request);
|
|
407
440
|
const code = optionalText(body, "code", MAX_CODE);
|
|
408
441
|
const recoveryCode = optionalText(body, "recoveryCode", MAX_CODE);
|
|
409
442
|
if (code === void 0 === (recoveryCode === void 0)) throw new require_errors.DevtoolsApiError("input.invalid");
|
|
@@ -439,7 +472,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
439
472
|
});
|
|
440
473
|
server.post("/api/account/recovery-codes", async (request) => {
|
|
441
474
|
const { auth: authenticated, meta } = contextOf(request);
|
|
442
|
-
return { codes: await auth.regenerateRecoveryCodes(authenticated, optionalText(bodyOf(request), "code", MAX_CODE) ?? "", meta) };
|
|
475
|
+
return { codes: await auth.regenerateRecoveryCodes(authenticated, optionalText(bodyOf$1(request), "code", MAX_CODE) ?? "", meta) };
|
|
443
476
|
});
|
|
444
477
|
server.post("/api/account/passkey/options", passkeyOptions);
|
|
445
478
|
server.post("/api/account/passkey/verify", passkeyVerify);
|
|
@@ -454,7 +487,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
454
487
|
});
|
|
455
488
|
server.post("/api/admin/invites", async (request) => {
|
|
456
489
|
const { auth: authenticated, meta } = contextOf(request);
|
|
457
|
-
const body = bodyOf(request);
|
|
490
|
+
const body = bodyOf$1(request);
|
|
458
491
|
return auth.createInvite(authenticated, {
|
|
459
492
|
email: email(body),
|
|
460
493
|
role: role(body)
|
|
@@ -467,7 +500,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
467
500
|
});
|
|
468
501
|
server.patch("/api/admin/users/:id", async (request) => {
|
|
469
502
|
const { auth: authenticated, meta } = contextOf(request);
|
|
470
|
-
return auth.setRole(authenticated, idParam(request), role(bodyOf(request)), meta);
|
|
503
|
+
return auth.setRole(authenticated, idParam(request), role(bodyOf$1(request)), meta);
|
|
471
504
|
});
|
|
472
505
|
server.delete("/api/admin/users/:id", async (request, reply) => {
|
|
473
506
|
const { auth: authenticated, meta } = contextOf(request);
|
|
@@ -501,7 +534,7 @@ function registerAuthRoutes(server, deps) {
|
|
|
501
534
|
});
|
|
502
535
|
server.post("/api/admin/disable", async (request, reply) => {
|
|
503
536
|
const { auth: authenticated, meta } = contextOf(request);
|
|
504
|
-
if (bodyOf(request).confirm !== "disable") throw new require_errors.DevtoolsApiError("input.invalid");
|
|
537
|
+
if (bodyOf$1(request).confirm !== "disable") throw new require_errors.DevtoolsApiError("input.invalid");
|
|
505
538
|
await auth.disableDashboard(authenticated, meta);
|
|
506
539
|
state.invalidate();
|
|
507
540
|
return reply.code(204).send();
|
|
@@ -531,6 +564,441 @@ const DASHBOARD_CSP = "default-src 'self'; script-src 'self'; style-src 'self' '
|
|
|
531
564
|
*/
|
|
532
565
|
const DOCS_CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self'; base-uri 'none'; form-action 'self'; object-src 'none'";
|
|
533
566
|
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region ../../packages/devtools/src/production/http/share-session.ts
|
|
569
|
+
/** How long a read of a share record is reused. A revoke reaches every instance within this time. */
|
|
570
|
+
const SHARE_CACHE_MS = 5e3;
|
|
571
|
+
/** Records kept in the cache of one process (oldest evicted). */
|
|
572
|
+
const SHARE_CACHE_SIZE = 500;
|
|
573
|
+
/** A link's use is written at most this often per link and process. */
|
|
574
|
+
const TOUCH_INTERVAL_MS = 6e4;
|
|
575
|
+
/**
|
|
576
|
+
* The share grant: a cookie carrying `<shareId>.<exp>.<HMAC-SHA256(key,
|
|
577
|
+
* "share:<id>:<exp>")>`. The signature proves this server issued it; the
|
|
578
|
+
* link's record, read through a 5-second cache, proves it is still alive, so
|
|
579
|
+
* a revoke takes effect everywhere within that time without a session table.
|
|
580
|
+
*/
|
|
581
|
+
function createShareSessions(input) {
|
|
582
|
+
const { store, hmac } = input;
|
|
583
|
+
const now = input.now ?? (() => Date.now());
|
|
584
|
+
const panels = new Map(input.panels.filter((panel) => panel.share !== null).map((panel) => [panel.id, panel]));
|
|
585
|
+
const cache = /* @__PURE__ */ new Map();
|
|
586
|
+
const touched = /* @__PURE__ */ new Map();
|
|
587
|
+
const sign = (id, exp) => hmac(`share:${id}:${exp}`);
|
|
588
|
+
async function record(id) {
|
|
589
|
+
const cached = cache.get(id);
|
|
590
|
+
if (cached && now() - cached.at < 5e3) return cached.record;
|
|
591
|
+
const found = await store.shares.get(id);
|
|
592
|
+
cache.delete(id);
|
|
593
|
+
if (cache.size >= SHARE_CACHE_SIZE) {
|
|
594
|
+
const oldest = cache.keys().next();
|
|
595
|
+
if (!oldest.done) cache.delete(oldest.value);
|
|
596
|
+
}
|
|
597
|
+
cache.set(id, {
|
|
598
|
+
record: found,
|
|
599
|
+
at: now()
|
|
600
|
+
});
|
|
601
|
+
return found;
|
|
602
|
+
}
|
|
603
|
+
function grantFor(share) {
|
|
604
|
+
if (share.revokedAt !== null) return {
|
|
605
|
+
refused: "revoked",
|
|
606
|
+
shareId: share.id
|
|
607
|
+
};
|
|
608
|
+
if (share.expiresAt <= now()) return {
|
|
609
|
+
refused: "expired",
|
|
610
|
+
shareId: share.id
|
|
611
|
+
};
|
|
612
|
+
const panel = panels.get(share.panel);
|
|
613
|
+
return panel ? { grant: {
|
|
614
|
+
share,
|
|
615
|
+
panel
|
|
616
|
+
} } : {
|
|
617
|
+
refused: "panel",
|
|
618
|
+
shareId: share.id
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return {
|
|
622
|
+
issue(share) {
|
|
623
|
+
const remaining = Math.floor((share.expiresAt - now()) / 1e3);
|
|
624
|
+
const maxAgeSeconds = Math.max(1, Math.min(remaining, DEVTOOLS_SHARE_COOKIE_MAX_SECONDS));
|
|
625
|
+
const exp = now() + maxAgeSeconds * 1e3;
|
|
626
|
+
return {
|
|
627
|
+
value: `${share.id}.${exp}.${sign(share.id, exp)}`,
|
|
628
|
+
maxAgeSeconds
|
|
629
|
+
};
|
|
630
|
+
},
|
|
631
|
+
async verify(value) {
|
|
632
|
+
const parts = (value ?? "").split(".");
|
|
633
|
+
const [id, expText, signature] = parts;
|
|
634
|
+
if (parts.length !== 3 || !id || !expText || !signature || !/^\d{1,16}$/.test(expText)) return {
|
|
635
|
+
refused: "cookie",
|
|
636
|
+
shareId: null
|
|
637
|
+
};
|
|
638
|
+
const exp = Number(expText);
|
|
639
|
+
if (!require_helpers.safeEqual(signature, sign(id, exp)) || exp <= now()) return {
|
|
640
|
+
refused: "cookie",
|
|
641
|
+
shareId: null
|
|
642
|
+
};
|
|
643
|
+
const share = await record(id);
|
|
644
|
+
return share ? grantFor(share) : {
|
|
645
|
+
refused: "unknown",
|
|
646
|
+
shareId: id
|
|
647
|
+
};
|
|
648
|
+
},
|
|
649
|
+
async open(tokenHash) {
|
|
650
|
+
const share = await store.shares.findByTokenHash(tokenHash);
|
|
651
|
+
return share ? grantFor(share) : {
|
|
652
|
+
refused: "unknown",
|
|
653
|
+
shareId: null
|
|
654
|
+
};
|
|
655
|
+
},
|
|
656
|
+
touch(shareId) {
|
|
657
|
+
const at = now();
|
|
658
|
+
const last = touched.get(shareId);
|
|
659
|
+
if (last !== void 0 && at - last < TOUCH_INTERVAL_MS) return;
|
|
660
|
+
touched.delete(shareId);
|
|
661
|
+
if (touched.size >= SHARE_CACHE_SIZE) {
|
|
662
|
+
const oldest = touched.keys().next();
|
|
663
|
+
if (!oldest.done) touched.delete(oldest.value);
|
|
664
|
+
}
|
|
665
|
+
touched.set(shareId, at);
|
|
666
|
+
store.shares.touch(shareId, at).catch((error) => {
|
|
667
|
+
input.warn?.(`devtools could not record a share link use: ${error instanceof Error ? error.message : String(error)}`);
|
|
668
|
+
});
|
|
669
|
+
},
|
|
670
|
+
invalidate() {
|
|
671
|
+
cache.clear();
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region ../../packages/devtools/src/production/http/share.ts
|
|
678
|
+
const DAY_MS = 864e5;
|
|
679
|
+
const MAX_TOKEN = 512;
|
|
680
|
+
const MAX_PANEL_ID = 64;
|
|
681
|
+
/** A failed token is not looked up again for this long once its client is over the limit. */
|
|
682
|
+
const BLOCK_CACHE_MS = 3e4;
|
|
683
|
+
const BLOCK_CACHE_SIZE = 1e3;
|
|
684
|
+
/** A cookie failure is audited at most this often per client (a revoked link in use must not flood the log). */
|
|
685
|
+
const COOKIE_AUDIT_INTERVAL_MS = 6e4;
|
|
686
|
+
/** The path pattern `pattern` (`/flows/:feature`) matched against `path`, as its params; `null` for no match. */
|
|
687
|
+
function matchSharePath(pattern, path) {
|
|
688
|
+
if (/[\0\\]/.test(path)) return null;
|
|
689
|
+
const wanted = pattern.split("/");
|
|
690
|
+
const given = path.split("/");
|
|
691
|
+
if (wanted.length !== given.length) return null;
|
|
692
|
+
const params = {};
|
|
693
|
+
for (const [index, part] of wanted.entries()) {
|
|
694
|
+
const actual = given[index];
|
|
695
|
+
if (actual === void 0) return null;
|
|
696
|
+
if (part.startsWith(":")) {
|
|
697
|
+
if (actual === "") return null;
|
|
698
|
+
params[part.slice(1)] = actual;
|
|
699
|
+
} else if (part !== actual) return null;
|
|
700
|
+
}
|
|
701
|
+
return params;
|
|
702
|
+
}
|
|
703
|
+
function bodyOf(request) {
|
|
704
|
+
const body = request.body;
|
|
705
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) throw new require_errors.DevtoolsApiError("input.invalid");
|
|
706
|
+
return body;
|
|
707
|
+
}
|
|
708
|
+
function viewOf(record, createdBy, at) {
|
|
709
|
+
return {
|
|
710
|
+
id: record.id,
|
|
711
|
+
panel: record.panel,
|
|
712
|
+
label: record.label,
|
|
713
|
+
createdBy,
|
|
714
|
+
createdAt: record.createdAt,
|
|
715
|
+
expiresAt: record.expiresAt,
|
|
716
|
+
revokedAt: record.revokedAt,
|
|
717
|
+
lastUsedAt: record.lastUsedAt,
|
|
718
|
+
uses: record.uses,
|
|
719
|
+
status: record.revokedAt !== null ? "revoked" : record.expiresAt <= at ? "expired" : "active"
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
function openAnswer(grant) {
|
|
723
|
+
const { panel, share } = grant;
|
|
724
|
+
return {
|
|
725
|
+
panel: panel.id,
|
|
726
|
+
title: panel.title,
|
|
727
|
+
label: share.label,
|
|
728
|
+
expiresAt: share.expiresAt,
|
|
729
|
+
assets: [...panel.share?.assets ?? []],
|
|
730
|
+
files: panel.share?.files === true
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Read-only share links of the production monitor. An admin creates a link
|
|
735
|
+
* for a panel that declares `share`; the token is shown once and only its
|
|
736
|
+
* SHA-256 is stored. Opening a link exchanges the token for a scoped cookie
|
|
737
|
+
* (`__Secure-warlock-devtools-share`) that reaches only that panel's shared
|
|
738
|
+
* view. Every refusal answers the dashboard's uniform 404, is audited as
|
|
739
|
+
* `share.failed` (which counts toward the per-IP failure limit) and never
|
|
740
|
+
* records the token.
|
|
741
|
+
*/
|
|
742
|
+
function createDevtoolsShare(deps) {
|
|
743
|
+
const { production, store, auth } = deps;
|
|
744
|
+
const now = deps.now ?? (() => Date.now());
|
|
745
|
+
if (typeof deps.hmac !== "function") throw new Error("Share links need deps.hmac (HMAC-SHA256 keyed with encryption.key).");
|
|
746
|
+
const sessions = createShareSessions({
|
|
747
|
+
store,
|
|
748
|
+
panels: deps.panels,
|
|
749
|
+
hmac: deps.hmac,
|
|
750
|
+
now,
|
|
751
|
+
...deps.warn ? { warn: deps.warn } : {}
|
|
752
|
+
});
|
|
753
|
+
const cookieOptions = {
|
|
754
|
+
path: production.path,
|
|
755
|
+
secure: production.requireHttps
|
|
756
|
+
};
|
|
757
|
+
const cookieName = shareCookieName(production.requireHttps);
|
|
758
|
+
const sharePanels = deps.panels.filter((panel) => panel.share !== null);
|
|
759
|
+
const blocked = /* @__PURE__ */ new Map();
|
|
760
|
+
const cookieAudited = /* @__PURE__ */ new Map();
|
|
761
|
+
const limits = production.rateLimits;
|
|
762
|
+
const windowMs = limits.windowMinutes * 6e4;
|
|
763
|
+
async function overLimit(ip) {
|
|
764
|
+
const client = require_ip.rateLimitClient(ip);
|
|
765
|
+
const at = now();
|
|
766
|
+
const until = blocked.get(client);
|
|
767
|
+
if (until !== void 0 && at < until) return true;
|
|
768
|
+
const state = await store.state.read();
|
|
769
|
+
const since = Math.max(at - windowMs, state.failuresResetAt ?? 0);
|
|
770
|
+
const count = await store.audit.count({
|
|
771
|
+
types: require_app_versions.DEVTOOLS_FAILURE_AUDIT_TYPES,
|
|
772
|
+
since,
|
|
773
|
+
ip
|
|
774
|
+
});
|
|
775
|
+
blocked.delete(client);
|
|
776
|
+
if (count < limits.ip) return false;
|
|
777
|
+
if (blocked.size >= BLOCK_CACHE_SIZE) {
|
|
778
|
+
const oldest = blocked.keys().next();
|
|
779
|
+
if (!oldest.done) blocked.delete(oldest.value);
|
|
780
|
+
}
|
|
781
|
+
blocked.set(client, at + BLOCK_CACHE_MS);
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
/** Writes one `share.failed` entry (never the token). Never throws. */
|
|
785
|
+
async function failed(meta, reason, shareId) {
|
|
786
|
+
await auth.audit("share.failed", {
|
|
787
|
+
meta,
|
|
788
|
+
detail: {
|
|
789
|
+
reason,
|
|
790
|
+
share: shareId
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
/** The cookie check for a share request. */
|
|
795
|
+
async function authorize(request, meta) {
|
|
796
|
+
const value = readCookie(request.headers.cookie, cookieName);
|
|
797
|
+
if (value === void 0) return null;
|
|
798
|
+
let result;
|
|
799
|
+
try {
|
|
800
|
+
result = await sessions.verify(value);
|
|
801
|
+
} catch (error) {
|
|
802
|
+
deps.warn?.(`A devtools share link could not be checked and the request was refused: ${error instanceof Error ? error.message : String(error)}`);
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
if ("grant" in result) {
|
|
806
|
+
sessions.touch(result.grant.share.id);
|
|
807
|
+
return result.grant;
|
|
808
|
+
}
|
|
809
|
+
const client = require_ip.rateLimitClient(meta.ip);
|
|
810
|
+
const last = cookieAudited.get(client);
|
|
811
|
+
if (last === void 0 || now() - last >= COOKIE_AUDIT_INTERVAL_MS) {
|
|
812
|
+
cookieAudited.delete(client);
|
|
813
|
+
if (cookieAudited.size >= BLOCK_CACHE_SIZE) {
|
|
814
|
+
const oldest = cookieAudited.keys().next();
|
|
815
|
+
if (!oldest.done) cookieAudited.delete(oldest.value);
|
|
816
|
+
}
|
|
817
|
+
cookieAudited.set(client, now());
|
|
818
|
+
try {
|
|
819
|
+
if (!await overLimit(meta.ip)) await failed(meta, result.refused, result.shareId);
|
|
820
|
+
} catch {}
|
|
821
|
+
}
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
function grantOf(request) {
|
|
825
|
+
const grant = devtoolsRequestContext(request)?.share;
|
|
826
|
+
if (!grant) throw new Error("A share route ran without its grant.");
|
|
827
|
+
return grant;
|
|
828
|
+
}
|
|
829
|
+
function createdByOf(accounts, id) {
|
|
830
|
+
return accounts.find((account) => account.id === id)?.email ?? null;
|
|
831
|
+
}
|
|
832
|
+
async function list() {
|
|
833
|
+
const [records, accounts] = await Promise.all([store.shares.list(), store.accounts.list()]);
|
|
834
|
+
const at = now();
|
|
835
|
+
return {
|
|
836
|
+
enabled: true,
|
|
837
|
+
maxDays: production.share.maxDays,
|
|
838
|
+
panels: sharePanels.map((panel) => ({
|
|
839
|
+
id: panel.id,
|
|
840
|
+
title: panel.title
|
|
841
|
+
})),
|
|
842
|
+
shares: records.map((record) => viewOf(record, createdByOf(accounts, record.createdBy), at))
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
async function create(authenticated, meta, body) {
|
|
846
|
+
const panel = body.panel;
|
|
847
|
+
const label = typeof body.label === "string" ? body.label.trim() : "";
|
|
848
|
+
const days = body.days;
|
|
849
|
+
if (typeof panel !== "string" || panel.length > MAX_PANEL_ID || !sharePanels.some((item) => item.id === panel) || label === "" || label.length > 80 || /[\u0000-\u001f\u007f]/.test(label) || typeof days !== "number" || !Number.isInteger(days) || days < 1 || days > production.share.maxDays) throw new require_errors.DevtoolsApiError("input.invalid");
|
|
850
|
+
const token = require_helpers.generateToken();
|
|
851
|
+
const at = now();
|
|
852
|
+
const record = await store.shares.create({
|
|
853
|
+
tokenHash: require_helpers.hashToken(token),
|
|
854
|
+
panel,
|
|
855
|
+
label,
|
|
856
|
+
createdBy: authenticated.account.id,
|
|
857
|
+
createdAt: at,
|
|
858
|
+
expiresAt: at + days * DAY_MS
|
|
859
|
+
});
|
|
860
|
+
sessions.invalidate();
|
|
861
|
+
await auth.audit("share.created", {
|
|
862
|
+
auth: authenticated,
|
|
863
|
+
meta,
|
|
864
|
+
detail: {
|
|
865
|
+
share: record.id,
|
|
866
|
+
panel,
|
|
867
|
+
days
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
return {
|
|
871
|
+
share: viewOf(record, authenticated.account.email, at),
|
|
872
|
+
url: `${meta.origin}${production.path}/#/share/${token}`
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function register(server, notFound) {
|
|
876
|
+
const requireAuth = (request) => {
|
|
877
|
+
const context = devtoolsRequestContext(request);
|
|
878
|
+
if (!context?.authenticated) throw new Error("A dashboard route ran without its session.");
|
|
879
|
+
return {
|
|
880
|
+
auth: context.authenticated,
|
|
881
|
+
meta: context.meta
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
server.post("/api/share/open", async (request, reply) => {
|
|
885
|
+
const context = devtoolsRequestContext(request);
|
|
886
|
+
if (!context) return notFound(request, reply);
|
|
887
|
+
const { meta } = context;
|
|
888
|
+
const token = request.body?.token;
|
|
889
|
+
if (typeof token !== "string" || token === "" || token.length > MAX_TOKEN) return notFound(request, reply);
|
|
890
|
+
try {
|
|
891
|
+
if (await overLimit(meta.ip)) return notFound(request, reply);
|
|
892
|
+
const result = await sessions.open(require_helpers.hashToken(token));
|
|
893
|
+
if (!("grant" in result)) {
|
|
894
|
+
await failed(meta, result.refused, result.shareId);
|
|
895
|
+
return notFound(request, reply);
|
|
896
|
+
}
|
|
897
|
+
const { value, maxAgeSeconds } = sessions.issue(result.grant.share);
|
|
898
|
+
sessions.touch(result.grant.share.id);
|
|
899
|
+
reply.header("set-cookie", shareCookie(value, {
|
|
900
|
+
...cookieOptions,
|
|
901
|
+
maxAgeSeconds
|
|
902
|
+
}));
|
|
903
|
+
return openAnswer(result.grant);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
deps.warn?.(`A devtools share link could not be opened: ${error instanceof Error ? error.message : String(error)}`);
|
|
906
|
+
return notFound(request, reply);
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
server.get("/api/share/info", async (request) => openAnswer(grantOf(request)));
|
|
910
|
+
server.get("/api/share/view.js", async (request, reply) => {
|
|
911
|
+
const view = grantOf(request).panel.share?.view;
|
|
912
|
+
if (view === void 0) return notFound(request, reply);
|
|
913
|
+
require_stream_route.sendFile(reply, view, "text/javascript; charset=utf-8");
|
|
914
|
+
return reply;
|
|
915
|
+
});
|
|
916
|
+
server.get("/api/share/assets/:name", async (request, reply) => {
|
|
917
|
+
const { panel } = grantOf(request);
|
|
918
|
+
const name = request.params.name;
|
|
919
|
+
const file = panel.share?.assets.includes(name) === true && Object.hasOwn(panel.assets, name) ? panel.assets[name] : void 0;
|
|
920
|
+
if (file === void 0) return notFound(request, reply);
|
|
921
|
+
require_stream_route.sendFile(reply, file, require_panels.panelContentType(name));
|
|
922
|
+
return reply;
|
|
923
|
+
});
|
|
924
|
+
server.get("/api/share/files/*", async (request, reply) => {
|
|
925
|
+
const { panel } = grantOf(request);
|
|
926
|
+
return require_stream_route.sendPanelFile({ files: panel.share?.files === true ? panel.files : null }, request.params["*"], request, reply, notFound);
|
|
927
|
+
});
|
|
928
|
+
const panelRoute = async (request, reply) => {
|
|
929
|
+
const { panel } = grantOf(request);
|
|
930
|
+
const sub = request.params["*"];
|
|
931
|
+
const path = sub === void 0 || sub === "" ? "" : `/${sub}`;
|
|
932
|
+
let matched = null;
|
|
933
|
+
for (const pattern of panel.share?.routes ?? []) {
|
|
934
|
+
const params = matchSharePath(pattern, path);
|
|
935
|
+
const route = panel.routes.find((candidate) => candidate.method === "GET" && candidate.path === pattern);
|
|
936
|
+
if (params !== null && route !== void 0) {
|
|
937
|
+
matched = {
|
|
938
|
+
route,
|
|
939
|
+
params
|
|
940
|
+
};
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
if (matched === null) return notFound(request, reply);
|
|
945
|
+
const input = {
|
|
946
|
+
params: matched.params,
|
|
947
|
+
query: request.query ?? {},
|
|
948
|
+
body: void 0,
|
|
949
|
+
shared: true
|
|
950
|
+
};
|
|
951
|
+
const result = await matched.route.handler(input);
|
|
952
|
+
reply.header("cache-control", "no-store");
|
|
953
|
+
if (result === void 0) return reply.code(204).send();
|
|
954
|
+
return result;
|
|
955
|
+
};
|
|
956
|
+
server.get("/api/share/panel", panelRoute);
|
|
957
|
+
server.get("/api/share/panel/*", panelRoute);
|
|
958
|
+
server.get("/api/admin/shares", async () => list());
|
|
959
|
+
server.post("/api/admin/shares", async (request, reply) => {
|
|
960
|
+
const { auth: authenticated, meta } = requireAuth(request);
|
|
961
|
+
const created = await create(authenticated, meta, bodyOf(request));
|
|
962
|
+
return reply.code(201).send(created);
|
|
963
|
+
});
|
|
964
|
+
server.delete("/api/admin/shares/:id", async (request, reply) => {
|
|
965
|
+
const { auth: authenticated, meta } = requireAuth(request);
|
|
966
|
+
const id = request.params.id;
|
|
967
|
+
if (typeof id !== "string" || id === "" || id.length > 64) throw new require_errors.DevtoolsApiError("input.invalid");
|
|
968
|
+
const record = await store.shares.get(id);
|
|
969
|
+
if (!record || !await store.shares.revoke(id, now())) throw new require_errors.DevtoolsApiError("share.not-found");
|
|
970
|
+
sessions.invalidate();
|
|
971
|
+
await auth.audit("share.revoked", {
|
|
972
|
+
auth: authenticated,
|
|
973
|
+
meta,
|
|
974
|
+
detail: {
|
|
975
|
+
share: id,
|
|
976
|
+
panel: record.panel
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
return reply.code(204).send();
|
|
980
|
+
});
|
|
981
|
+
server.post("/api/admin/shares/revoke-all", async (request) => {
|
|
982
|
+
const { auth: authenticated, meta } = requireAuth(request);
|
|
983
|
+
const revoked = await store.shares.revokeAll(now());
|
|
984
|
+
sessions.invalidate();
|
|
985
|
+
await auth.audit("share.revoked", {
|
|
986
|
+
auth: authenticated,
|
|
987
|
+
meta,
|
|
988
|
+
detail: {
|
|
989
|
+
all: true,
|
|
990
|
+
count: revoked
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
return { revoked };
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
return {
|
|
997
|
+
authorize,
|
|
998
|
+
register
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
534
1002
|
//#endregion
|
|
535
1003
|
//#region ../../packages/devtools/src/production/http/mount.ts
|
|
536
1004
|
/** Open live streams a session may hold, and an instance may serve. */
|
|
@@ -545,6 +1013,8 @@ const SAFE_METHODS = /* @__PURE__ */ new Set([
|
|
|
545
1013
|
]);
|
|
546
1014
|
/** The routes of the opt-in API documentation pages (they keep a CSP of their own). */
|
|
547
1015
|
const DOCS_PATTERNS = /* @__PURE__ */ new Set(["/docs", "/docs/swagger"]);
|
|
1016
|
+
/** The grant exchange of a share link: every failure of it answers the uniform 404. */
|
|
1017
|
+
const SHARE_OPEN_PATTERN = "/api/share/open";
|
|
548
1018
|
/** The mail preview's HTML: framed by the dashboard, with a policy of its own. */
|
|
549
1019
|
const MAIL_HTML_PATTERN = "/api/mails/:id/html";
|
|
550
1020
|
/** Which tab a route belongs to: a route of a tab that is off answers the uniform 404. */
|
|
@@ -607,7 +1077,8 @@ function mountProductionDevtools(server, deps) {
|
|
|
607
1077
|
const prefix = production.path;
|
|
608
1078
|
const cookieName = sessionCookieName(production.requireHttps);
|
|
609
1079
|
const enabledTabs = new Set(deps.builtInPanels);
|
|
610
|
-
const
|
|
1080
|
+
const share = production.share.enabled ? createDevtoolsShare(deps) : null;
|
|
1081
|
+
const lookup = createAccessLookup(productionRouteAccess(deps.panels.map((panel) => panel.id), { share: share !== null }));
|
|
611
1082
|
const streamsPerSession = /* @__PURE__ */ new Map();
|
|
612
1083
|
let streamsInstance = 0;
|
|
613
1084
|
let lastWarningAt = 0;
|
|
@@ -708,6 +1179,19 @@ function mountProductionDevtools(server, deps) {
|
|
|
708
1179
|
const rule = lookup(method, pattern);
|
|
709
1180
|
const access = rule?.access ?? { type: "admin" };
|
|
710
1181
|
let authenticated = null;
|
|
1182
|
+
if (access.type === "share") {
|
|
1183
|
+
const grant = share ? await share.authorize(request, meta) : null;
|
|
1184
|
+
if (grant === null) return notFound(request, reply);
|
|
1185
|
+
setDevtoolsRequestContext(request, {
|
|
1186
|
+
client,
|
|
1187
|
+
meta,
|
|
1188
|
+
rule,
|
|
1189
|
+
pattern,
|
|
1190
|
+
authenticated: null,
|
|
1191
|
+
share: grant
|
|
1192
|
+
});
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
711
1195
|
if (access.type !== "public") {
|
|
712
1196
|
try {
|
|
713
1197
|
authenticated = await auth.authenticate(readCookie(request.headers.cookie, cookieName));
|
|
@@ -739,7 +1223,10 @@ function mountProductionDevtools(server, deps) {
|
|
|
739
1223
|
if (authenticated === null) return notFound(request, reply);
|
|
740
1224
|
throw new require_errors.DevtoolsApiError("csrf.invalid");
|
|
741
1225
|
}
|
|
742
|
-
if (hasBody(request) && !isJson(request))
|
|
1226
|
+
if (hasBody(request) && !isJson(request)) {
|
|
1227
|
+
if (pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);
|
|
1228
|
+
throw new require_errors.DevtoolsApiError("input.invalid");
|
|
1229
|
+
}
|
|
743
1230
|
if (authenticated !== null) {
|
|
744
1231
|
const header = request.headers[DEVTOOLS_CSRF_HEADER];
|
|
745
1232
|
if (!auth.verifyCsrf(authenticated, Array.isArray(header) ? header[0] : header)) throw new require_errors.DevtoolsApiError("csrf.invalid");
|
|
@@ -775,6 +1262,7 @@ function mountProductionDevtools(server, deps) {
|
|
|
775
1262
|
});
|
|
776
1263
|
});
|
|
777
1264
|
instance.setErrorHandler((error, request, reply) => {
|
|
1265
|
+
if (devtoolsRequestContext(request)?.pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);
|
|
778
1266
|
if (error instanceof require_errors.DevtoolsApiError) return reply.code(error.statusCode).send(error.toBody());
|
|
779
1267
|
const status = error.statusCode;
|
|
780
1268
|
if (status !== void 0 && status >= 400 && status < 500) return reply.code(status).send(error.code?.startsWith("FST_ERR_") ? new require_errors.DevtoolsApiError("input.invalid").toBody() : { error: error.message });
|
|
@@ -798,7 +1286,8 @@ function mountProductionDevtools(server, deps) {
|
|
|
798
1286
|
require_stream_route.registerInsightsRoutes(instance, routes);
|
|
799
1287
|
require_stream_route.registerLogRoutes(instance, routes);
|
|
800
1288
|
require_stream_route.registerShapeExplainRoute(instance, routes);
|
|
801
|
-
require_stream_route.registerPanelRoutes(instance, deps.panels);
|
|
1289
|
+
require_stream_route.registerPanelRoutes(instance, deps.panels, { notFound });
|
|
1290
|
+
share?.register(instance, notFound);
|
|
802
1291
|
if (enabledTabs.has("mail")) require_stream_route.registerMailRoutes(instance, routes);
|
|
803
1292
|
if (enabledTabs.has("ai") || enabledTabs.has("agents")) require_stream_route.registerAiRoutes(instance, routes);
|
|
804
1293
|
if (enabledTabs.has("api")) require_stream_route.registerOpenApiRoutes(instance, routes);
|
|
@@ -867,4 +1356,4 @@ exports.mountProductionDevtools = mountProductionDevtools;
|
|
|
867
1356
|
exports.productionRouteAccess = productionRouteAccess;
|
|
868
1357
|
exports.resolveClient = resolveClient;
|
|
869
1358
|
exports.sessionCookie = sessionCookie;
|
|
870
|
-
//# sourceMappingURL=http-
|
|
1359
|
+
//# sourceMappingURL=http-Biauhqi0.cjs.map
|