@blockrun/franklin 3.49.18 → 3.49.19
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/panel/html.js +3 -1
- package/dist/panel/server.js +23 -4
- package/dist/session/storage.js +3 -3
- package/dist/storage/safe-id.d.ts +10 -0
- package/dist/storage/safe-id.js +24 -0
- package/dist/tasks/paths.js +4 -0
- package/package.json +1 -1
package/dist/panel/html.js
CHANGED
|
@@ -917,6 +917,8 @@ a:hover { text-decoration:underline; }
|
|
|
917
917
|
// refuses wallet, spend, and state-changing routes without it.
|
|
918
918
|
(() => {
|
|
919
919
|
const PANEL_TOKEN = ${JSON.stringify(panelToken)};
|
|
920
|
+
// EventSource cannot set headers; /api/events reads it from ?token=.
|
|
921
|
+
window.__FRANKLIN_PANEL_TOKEN = PANEL_TOKEN;
|
|
920
922
|
const nativeFetch = window.fetch.bind(window);
|
|
921
923
|
window.fetch = (input, init = {}) => {
|
|
922
924
|
const headers = new Headers(init.headers || {});
|
|
@@ -1425,7 +1427,7 @@ document.getElementById('wallet-import-btn').addEventListener('click', async ()
|
|
|
1425
1427
|
}
|
|
1426
1428
|
});
|
|
1427
1429
|
|
|
1428
|
-
const es = new EventSource('/api/events');
|
|
1430
|
+
const es = new EventSource('/api/events?token=' + encodeURIComponent(window.__FRANKLIN_PANEL_TOKEN));
|
|
1429
1431
|
const dot = document.getElementById('dot');
|
|
1430
1432
|
const statusEl = document.getElementById('status');
|
|
1431
1433
|
es.onopen = () => { dot.className = 'dot on'; statusEl.textContent = 'live'; };
|
package/dist/panel/server.js
CHANGED
|
@@ -21,6 +21,7 @@ import { describeWiring } from '../trading/providers/registry.js';
|
|
|
21
21
|
import { listTasks, readTaskMeta, readTaskEvents, } from '../tasks/store.js';
|
|
22
22
|
import { reconcileLostTasks } from '../tasks/lost-detection.js';
|
|
23
23
|
import { taskLogPath } from '../tasks/paths.js';
|
|
24
|
+
import { isSafePathSegment } from '../storage/safe-id.js';
|
|
24
25
|
import { isTerminalTaskStatus } from '../tasks/types.js';
|
|
25
26
|
import { readLiveAgents } from '../session/live-registry.js';
|
|
26
27
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
@@ -95,12 +96,14 @@ function isLocalHostHeader(req) {
|
|
|
95
96
|
*/
|
|
96
97
|
const PANEL_TOKEN = crypto.randomBytes(32).toString('hex');
|
|
97
98
|
const PANEL_TOKEN_HEADER = 'x-franklin-panel-token';
|
|
98
|
-
function
|
|
99
|
-
const got = req.headers[PANEL_TOKEN_HEADER];
|
|
99
|
+
function tokenMatches(got) {
|
|
100
100
|
if (typeof got !== 'string' || got.length !== PANEL_TOKEN.length)
|
|
101
101
|
return false;
|
|
102
102
|
return crypto.timingSafeEqual(Buffer.from(got), Buffer.from(PANEL_TOKEN));
|
|
103
103
|
}
|
|
104
|
+
function hasPanelToken(req) {
|
|
105
|
+
return tokenMatches(req.headers[PANEL_TOKEN_HEADER]);
|
|
106
|
+
}
|
|
104
107
|
function isLocalPanelRequest(req) {
|
|
105
108
|
return isLoopback(req) && isTrustedPanelOrigin(req) && hasPanelToken(req);
|
|
106
109
|
}
|
|
@@ -166,6 +169,17 @@ export function createPanelServer(port) {
|
|
|
166
169
|
res.end('Forbidden');
|
|
167
170
|
return;
|
|
168
171
|
}
|
|
172
|
+
// Every API route needs the page's token, read-only ones included.
|
|
173
|
+
// Loopback + local Host does not tell OS users apart: on a shared machine
|
|
174
|
+
// another account, or anyone reaching the port through an ssh -L tunnel,
|
|
175
|
+
// passes both and could read transcripts and the audit log
|
|
176
|
+
// (GHSA-jx74-262x-94p3). EventSource cannot set headers, so /api/events
|
|
177
|
+
// alone may carry the token as ?token=.
|
|
178
|
+
if (p.startsWith('/api/') && !hasPanelToken(req)
|
|
179
|
+
&& !(p === '/api/events' && tokenMatches(url.searchParams.get('token')))) {
|
|
180
|
+
json(res, { error: 'forbidden' }, 403);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
169
183
|
// Anything that changes state needs the page's token, including routes
|
|
170
184
|
// that only check loopback (task cancel).
|
|
171
185
|
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'OPTIONS' && !hasPanelToken(req)) {
|
|
@@ -768,9 +782,14 @@ export function createPanelServer(port) {
|
|
|
768
782
|
if (p.startsWith('/api/tasks/')) {
|
|
769
783
|
const rest = p.slice('/api/tasks/'.length);
|
|
770
784
|
const segments = rest.split('/');
|
|
771
|
-
|
|
785
|
+
let runId = '';
|
|
786
|
+
try {
|
|
787
|
+
runId = decodeURIComponent(segments[0] || '');
|
|
788
|
+
}
|
|
789
|
+
catch { /* malformed %-escape */ }
|
|
772
790
|
const sub = segments[1];
|
|
773
|
-
|
|
791
|
+
// getTaskDir also refuses these; answer 404 here instead of a 500.
|
|
792
|
+
if (!isSafePathSegment(runId)) {
|
|
774
793
|
res.writeHead(404);
|
|
775
794
|
res.end('Not found');
|
|
776
795
|
return;
|
package/dist/session/storage.js
CHANGED
|
@@ -7,6 +7,7 @@ import os from 'node:os';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { randomUUID } from 'node:crypto';
|
|
9
9
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
10
|
+
import { assertSafePathSegment } from '../storage/safe-id.js';
|
|
10
11
|
const MAX_SESSIONS = 20; // Keep last 20 sessions
|
|
11
12
|
let resolvedSessionsDir = null;
|
|
12
13
|
// When in-process tests run interactiveSession() with model="local/test*",
|
|
@@ -55,9 +56,7 @@ function getSessionsDir() {
|
|
|
55
56
|
}
|
|
56
57
|
function sessionPath(id) {
|
|
57
58
|
// Ids reach here from URLs (panel /api/sessions/:id); never let one escape the sessions dir.
|
|
58
|
-
|
|
59
|
-
throw new Error(`Invalid session id: ${JSON.stringify(id)}`);
|
|
60
|
-
}
|
|
59
|
+
assertSafePathSegment(id, 'session id');
|
|
61
60
|
return path.join(getSessionsDir(), `${id}.jsonl`);
|
|
62
61
|
}
|
|
63
62
|
/** Get the absolute path to a session's JSONL file (for external readers like search). */
|
|
@@ -65,6 +64,7 @@ export function getSessionFilePath(id) {
|
|
|
65
64
|
return sessionPath(id);
|
|
66
65
|
}
|
|
67
66
|
function metaPath(id) {
|
|
67
|
+
assertSafePathSegment(id, 'session id');
|
|
68
68
|
return path.join(getSessionsDir(), `${id}.meta.json`);
|
|
69
69
|
}
|
|
70
70
|
function withWritableSessionDir(action) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ids that become a single path segment (session ids, task run ids).
|
|
3
|
+
*
|
|
4
|
+
* These ids reach the filesystem helpers from URLs (panel /api/sessions/:id,
|
|
5
|
+
* /api/tasks/:runId) after decodeURIComponent, so `..%2F` arrives as `../`.
|
|
6
|
+
* Validate in the shared path helper, not in each route: GHSA-jx74-262x-94p3
|
|
7
|
+
* fixed the sessions route while the tasks route kept the same hole.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isSafePathSegment(id: unknown): id is string;
|
|
10
|
+
export declare function assertSafePathSegment(id: unknown, kind: string): asserts id is string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ids that become a single path segment (session ids, task run ids).
|
|
3
|
+
*
|
|
4
|
+
* These ids reach the filesystem helpers from URLs (panel /api/sessions/:id,
|
|
5
|
+
* /api/tasks/:runId) after decodeURIComponent, so `..%2F` arrives as `../`.
|
|
6
|
+
* Validate in the shared path helper, not in each route: GHSA-jx74-262x-94p3
|
|
7
|
+
* fixed the sessions route while the tasks route kept the same hole.
|
|
8
|
+
*/
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
export function isSafePathSegment(id) {
|
|
11
|
+
return (typeof id === 'string' &&
|
|
12
|
+
id.length > 0 &&
|
|
13
|
+
id !== '.' &&
|
|
14
|
+
!id.includes('..') &&
|
|
15
|
+
!id.includes('/') &&
|
|
16
|
+
!id.includes('\\') &&
|
|
17
|
+
!id.includes('\0') &&
|
|
18
|
+
id === path.basename(id));
|
|
19
|
+
}
|
|
20
|
+
export function assertSafePathSegment(id, kind) {
|
|
21
|
+
if (!isSafePathSegment(id)) {
|
|
22
|
+
throw new Error(`Invalid ${kind}: ${JSON.stringify(id)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/tasks/paths.js
CHANGED
|
@@ -23,6 +23,7 @@ import fs from 'node:fs';
|
|
|
23
23
|
import os from 'node:os';
|
|
24
24
|
import path from 'node:path';
|
|
25
25
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
26
|
+
import { assertSafePathSegment } from '../storage/safe-id.js';
|
|
26
27
|
const LEGACY_FRANKLIN_HOME = path.join(os.homedir(), '.franklin');
|
|
27
28
|
function franklinHome() {
|
|
28
29
|
return process.env.FRANKLIN_HOME || BLOCKRUN_DIR;
|
|
@@ -34,6 +35,9 @@ export function getLegacyTasksDir() {
|
|
|
34
35
|
return path.join(LEGACY_FRANKLIN_HOME, 'tasks');
|
|
35
36
|
}
|
|
36
37
|
export function getTaskDir(runId) {
|
|
38
|
+
// Run ids reach here from URLs (panel /api/tasks/:runId); never let one
|
|
39
|
+
// escape the tasks dir. Every task path helper routes through here.
|
|
40
|
+
assertSafePathSegment(runId, 'task run id');
|
|
37
41
|
// Prefer the primary location. If a task already exists in the
|
|
38
42
|
// legacy ~/.franklin/tasks/ — either created by an older release or
|
|
39
43
|
// by a runner subprocess started before this version was installed —
|
package/package.json
CHANGED