wherever-dev 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/drafts.d.ts +7 -0
- package/dist/drafts.d.ts.map +1 -1
- package/dist/drafts.js +10 -3
- package/dist/drafts.js.map +1 -1
- package/dist/index.js +199 -15
- package/dist/index.js.map +1 -1
- package/dist/session-pool.d.ts +23 -0
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +33 -1
- package/dist/session-pool.js.map +1 -1
- package/package.json +1 -1
- package/public/_app/immutable/chunks/{55QXfSWV.js → CyQq9q8L.js} +2 -2
- package/public/_app/immutable/chunks/{55QXfSWV.js.map → CyQq9q8L.js.map} +1 -1
- package/public/_app/immutable/chunks/DdFruy3e.js +2 -0
- package/public/_app/immutable/chunks/{CuGyzHtA.js.map → DdFruy3e.js.map} +1 -1
- package/public/_app/immutable/chunks/{sERBGsNa.js → vSWNc7VF.js} +2 -2
- package/public/_app/immutable/chunks/{sERBGsNa.js.map → vSWNc7VF.js.map} +1 -1
- package/public/_app/immutable/entry/{app.DN0r_HfQ.js → app.BzMua2z6.js} +3 -3
- package/public/_app/immutable/entry/{app.DN0r_HfQ.js.map → app.BzMua2z6.js.map} +1 -1
- package/public/_app/immutable/entry/start.B0ap2dTz.js +2 -0
- package/public/_app/immutable/entry/start.B0ap2dTz.js.map +1 -0
- package/public/_app/immutable/nodes/{0.BhHgt5Z6.js → 0.BDXduH3G.js} +2 -2
- package/public/_app/immutable/nodes/{0.BhHgt5Z6.js.map → 0.BDXduH3G.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.B9mDAaoD.js → 1.CqJo-807.js} +2 -2
- package/public/_app/immutable/nodes/{1.B9mDAaoD.js.map → 1.CqJo-807.js.map} +1 -1
- package/public/_app/immutable/nodes/{2.BjlQDhkN.js → 2.C6-6KHYk.js} +2 -2
- package/public/_app/immutable/nodes/{2.BjlQDhkN.js.map → 2.C6-6KHYk.js.map} +1 -1
- package/public/_app/version.json +1 -1
- package/public/index.html +10 -10
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/chunks/CuGyzHtA.js +0 -2
- package/public/_app/immutable/entry/start.CSyfkZFS.js +0 -2
- package/public/_app/immutable/entry/start.CSyfkZFS.js.map +0 -1
package/dist/drafts.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export interface Draft {
|
|
|
38
38
|
export declare class DraftsUnavailableError extends Error {
|
|
39
39
|
constructor(reason: string);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Drafts live in the STATE dir, not the config dir. They are the canonical
|
|
43
|
+
* example of the split: the config directory can be read-only (rendered by the
|
|
44
|
+
* deployment), while this file is written on every save. `WHEREVER_STATE_DIR`
|
|
45
|
+
* defaults to the config dir, so an install that sets neither variable (or only
|
|
46
|
+
* `WHEREVER_CONFIG_DIR`) keeps the exact path it has today.
|
|
47
|
+
*/
|
|
41
48
|
export declare function getDraftsPath(): string;
|
|
42
49
|
/** Newest-updated first, ties broken by id so the order is deterministic. */
|
|
43
50
|
export declare function sortDrafts(drafts: Draft[]): Draft[];
|
package/dist/drafts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drafts.d.ts","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH,eAAO,MAAM,UAAU,MAAM,CAAC;AAE9B,8EAA8E;AAC9E,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAKzC,MAAM,WAAW,KAAK;IACpB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,SAAS,CAAC,EAAE,MAAM,C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//
|
|
3
|
-
// The store lives on the SERVER (`<
|
|
3
|
+
// The store lives on the SERVER (`<state dir>/drafts.json`), not in a browser,
|
|
4
4
|
// because that is the whole point of wherever: the machine holds the state and
|
|
5
5
|
// any device picks it up. A draft written on a phone has to be there on the
|
|
6
6
|
// laptop, and clearing site data must not destroy it. (The composer's per-session
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// client adopts verbatim.
|
|
20
20
|
import fs from 'node:fs';
|
|
21
21
|
import path from 'node:path';
|
|
22
|
-
import {
|
|
22
|
+
import { getWhereverStateDir } from './session-pool.js';
|
|
23
23
|
/**
|
|
24
24
|
* Hard cap on retained drafts, dropping the least recently touched. A draft is
|
|
25
25
|
* kept forever by definition, so without a cap this file is the one thing here
|
|
@@ -51,8 +51,15 @@ export class DraftsUnavailableError extends Error {
|
|
|
51
51
|
this.name = 'DraftsUnavailableError';
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Drafts live in the STATE dir, not the config dir. They are the canonical
|
|
56
|
+
* example of the split: the config directory can be read-only (rendered by the
|
|
57
|
+
* deployment), while this file is written on every save. `WHEREVER_STATE_DIR`
|
|
58
|
+
* defaults to the config dir, so an install that sets neither variable (or only
|
|
59
|
+
* `WHEREVER_CONFIG_DIR`) keeps the exact path it has today.
|
|
60
|
+
*/
|
|
54
61
|
export function getDraftsPath() {
|
|
55
|
-
return path.join(
|
|
62
|
+
return path.join(getWhereverStateDir(), 'drafts.json');
|
|
56
63
|
}
|
|
57
64
|
/** Newest-updated first, ties broken by id so the order is deterministic. */
|
|
58
65
|
export function sortDrafts(drafts) {
|
package/dist/drafts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drafts.js","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF
|
|
1
|
+
{"version":3,"file":"drafts.js","sourceRoot":"","sources":["../src/drafts.ts"],"names":[],"mappings":"AA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AI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IACpE,CAAC;AACH,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,QAAQ,CAAC,KAAuF;IAC9G,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,EAAE,EAAE;QACnC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,UAAU,EAAE;QAC5B,GAAG,EAAE,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE;QAC5B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,GAAG,EAAE,KAAK,CAAC,GAAG;KACf,CAAC,CAAC;IACH,WAAW,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;IAC3C,WAAW,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createServer as createHttpServer } from 'node:http';
|
|
3
3
|
import { createServer as createHttpsServer, request as httpRequest } from 'node:https';
|
|
4
4
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
5
|
-
import { SessionPool, getWhereverConfig, detectRemoteRepo } from './session-pool.js';
|
|
5
|
+
import { SessionPool, getWhereverConfig, getWhereverCertsDir, detectRemoteRepo } from './session-pool.js';
|
|
6
6
|
import { readDrafts, addDraft, deleteDraft, validateDraftInput } from './drafts.js';
|
|
7
7
|
import { searchConversations } from './conversation-search.js';
|
|
8
8
|
import { INITIAL_HISTORY_LIMIT, HISTORY_PAGE_SIZE } from './protocol.js';
|
|
@@ -312,19 +312,123 @@ function evictPreviousConnection(clientKey, clients, pool, onSessionsUpdated) {
|
|
|
312
312
|
function generateId() {
|
|
313
313
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
314
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Resolve the auth token WITHOUT requiring it on the command line.
|
|
317
|
+
*
|
|
318
|
+
* Anything in argv is world-readable: `ps -ef` (and /proc/<pid>/cmdline, which
|
|
319
|
+
* is mode 0444) shows the full command line of every process on the machine to
|
|
320
|
+
* every local user, so `--token <secret>` leaks the secret to any account on
|
|
321
|
+
* the box. That is fine for a laptop and NOT fine for a shared/bare-metal host,
|
|
322
|
+
* which is why the environment is the preferred channel for real deployments.
|
|
323
|
+
*
|
|
324
|
+
* Precedence, highest first:
|
|
325
|
+
* 1. `--token <value>` - explicit argv, kept for compatibility. LEAKS via ps.
|
|
326
|
+
* 2. `WHEREVER_TOKEN` - preferred for deployments.
|
|
327
|
+
* 3. `WHEREVER_TOKEN_FILE` - path to a file whose (trimmed) CONTENT is the
|
|
328
|
+
* token. The natural shape for a secret manager
|
|
329
|
+
* (sops-nix, systemd `LoadCredential`) which
|
|
330
|
+
* renders a root-owned 0400 file; nothing
|
|
331
|
+
* secret then exists in argv OR in the
|
|
332
|
+
* environment block.
|
|
333
|
+
* 4. `PI_REMOTE_TOKEN` - the pre-existing variable, still honoured.
|
|
334
|
+
*
|
|
335
|
+
* TRIMMING IS ASYMMETRIC ON PURPOSE, and the asymmetry is a compatibility rule,
|
|
336
|
+
* not an oversight. The two NEW sources are trimmed, because a secret manager
|
|
337
|
+
* renders a file with a trailing newline and `WHEREVER_TOKEN=$(cat ...)` is the
|
|
338
|
+
* obvious thing to write. The two PRE-EXISTING sources (`--token`,
|
|
339
|
+
* `PI_REMOTE_TOKEN`) are taken VERBATIM, exactly as before, because
|
|
340
|
+
* `authenticate()` compares the raw query parameter with `===`: trimming them
|
|
341
|
+
* would silently change WHICH string authenticates on an install that already
|
|
342
|
+
* has whitespace in its token, locking out every saved client URL. Likewise
|
|
343
|
+
* `--token` wins whenever the FLAG WAS GIVEN, even with an empty or missing
|
|
344
|
+
* value, because that is what the old `case '--token': token = args[++i]`
|
|
345
|
+
* did -- it overwrote whatever the environment had.
|
|
346
|
+
*
|
|
347
|
+
* An unreadable or empty `WHEREVER_TOKEN_FILE` is FATAL rather than "fall
|
|
348
|
+
* through to no token": silently starting an UNAUTHENTICATED server because a
|
|
349
|
+
* secret failed to mount is the one failure mode that must never happen
|
|
350
|
+
* quietly. Note this only fires when the file is the source actually being
|
|
351
|
+
* consulted: an explicit `--token`/`WHEREVER_TOKEN` above it still wins, and
|
|
352
|
+
* the server is authenticated either way.
|
|
353
|
+
*/
|
|
354
|
+
function resolveToken(cliToken, cliTokenGiven) {
|
|
355
|
+
// `cliTokenGiven`, not `cliToken`, so that `--token ''` (and a trailing
|
|
356
|
+
// `--token` with no value) still SUPPRESSES the environment, as it did before.
|
|
357
|
+
if (cliTokenGiven)
|
|
358
|
+
return { token: cliToken || undefined, source: '--token' };
|
|
359
|
+
const envToken = process.env.WHEREVER_TOKEN;
|
|
360
|
+
if (envToken && envToken.trim())
|
|
361
|
+
return { token: envToken.trim(), source: 'WHEREVER_TOKEN' };
|
|
362
|
+
warnIfSetButBlank('WHEREVER_TOKEN', envToken);
|
|
363
|
+
const tokenFile = process.env.WHEREVER_TOKEN_FILE;
|
|
364
|
+
if (tokenFile && tokenFile.trim()) {
|
|
365
|
+
const resolvedPath = expandTilde(tokenFile.trim());
|
|
366
|
+
let contents;
|
|
367
|
+
try {
|
|
368
|
+
contents = fs.readFileSync(resolvedPath, 'utf8');
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
console.error(`FATAL: WHEREVER_TOKEN_FILE is set to ${resolvedPath} but it could not be read ` +
|
|
372
|
+
`(${err.message}). Refusing to start: continuing would silently run an ` +
|
|
373
|
+
`UNAUTHENTICATED server.`);
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
const trimmed = contents.trim();
|
|
377
|
+
if (!trimmed) {
|
|
378
|
+
console.error(`FATAL: WHEREVER_TOKEN_FILE (${resolvedPath}) is empty. Refusing to start: continuing ` +
|
|
379
|
+
`would silently run an UNAUTHENTICATED server.`);
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
return { token: trimmed, source: `WHEREVER_TOKEN_FILE (${resolvedPath})` };
|
|
383
|
+
}
|
|
384
|
+
warnIfSetButBlank('WHEREVER_TOKEN_FILE', tokenFile);
|
|
385
|
+
// VERBATIM, including surrounding whitespace: see the trimming note above.
|
|
386
|
+
// `' '` is truthy and therefore enforced, exactly as it was before.
|
|
387
|
+
const legacy = process.env.PI_REMOTE_TOKEN;
|
|
388
|
+
if (legacy)
|
|
389
|
+
return { token: legacy, source: 'PI_REMOTE_TOKEN' };
|
|
390
|
+
return { token: undefined, source: 'none' };
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* A token variable that is SET but blank is almost always a secret that failed
|
|
394
|
+
* to render (a truncated file, a `$(cat ...)` that errored, a half-landed
|
|
395
|
+
* activation), and the consequence is an UNAUTHENTICATED server that looks
|
|
396
|
+
* perfectly healthy. It cannot be fatal -- `VAR=` is also the ordinary way to
|
|
397
|
+
* neutralise an inherited variable, which the test harness relies on -- so it
|
|
398
|
+
* is made LOUD instead. Silence is the only unacceptable outcome here.
|
|
399
|
+
*/
|
|
400
|
+
function warnIfSetButBlank(name, value) {
|
|
401
|
+
if (value === undefined || value.length === 0)
|
|
402
|
+
return; // unset, or explicitly neutralised
|
|
403
|
+
if (value.trim().length > 0)
|
|
404
|
+
return;
|
|
405
|
+
console.warn(`[wherever] ${name} is set but contains only whitespace. Treating it as NOT SET. ` +
|
|
406
|
+
`If a secret was meant to be rendered here, it did not arrive, and this server may ` +
|
|
407
|
+
`be starting WITHOUT AUTHENTICATION.`);
|
|
408
|
+
}
|
|
315
409
|
function parseArgs() {
|
|
316
410
|
const args = process.argv.slice(2);
|
|
317
411
|
let port = parseInt(process.env.PI_REMOTE_PORT || '31415', 10);
|
|
318
412
|
let host = process.env.PI_REMOTE_HOST || '127.0.0.1';
|
|
319
|
-
|
|
413
|
+
// Kept separate from the env-derived token so `resolveToken` below can apply
|
|
414
|
+
// one documented precedence chain instead of "whoever assigned last wins".
|
|
415
|
+
// `cliTokenGiven` tracks the FLAG's presence separately from its VALUE, so
|
|
416
|
+
// `--token ''` still suppresses the environment the way it always did.
|
|
417
|
+
let cliToken = undefined;
|
|
418
|
+
let cliTokenGiven = false;
|
|
320
419
|
// Idle eviction window. Longer than the old 5 min so a dip-in/dip-out mobile
|
|
321
420
|
// user returns to a still-WARM session (no agent rebuild) most of the time.
|
|
322
421
|
// With fast-first load a cold return is no longer slow to READ, but a warm
|
|
323
422
|
// session also avoids the async agent build entirely. Override via
|
|
324
423
|
// PI_IDLE_TIMEOUT (ms). See docs/plan-speed-up-long-session-load.md.
|
|
325
424
|
let idleTimeout = parseInt(process.env.PI_IDLE_TIMEOUT || '1200000', 10);
|
|
326
|
-
|
|
327
|
-
|
|
425
|
+
// TLS material is addressed by PATH, and each half is resolved INDEPENDENTLY
|
|
426
|
+
// (flag > WHEREVER_* > PI_REMOTE_*). On a declaratively-managed host the key
|
|
427
|
+
// arrives from a secret manager at an arbitrary root-owned path (e.g.
|
|
428
|
+
// /run/secrets/wherever-key.pem) while the certificate is a world-readable
|
|
429
|
+
// file somewhere else entirely, so neither may be tied to a home directory.
|
|
430
|
+
let sslKey = process.env.WHEREVER_SSL_KEY || process.env.PI_REMOTE_SSL_KEY || undefined;
|
|
431
|
+
let sslCert = process.env.WHEREVER_SSL_CERT || process.env.PI_REMOTE_SSL_CERT || undefined;
|
|
328
432
|
let noSsl = process.env.PI_REMOTE_NO_SSL === 'true' || process.env.PI_REMOTE_HTTP === 'true';
|
|
329
433
|
let httpLocalhostFallbackPort = undefined;
|
|
330
434
|
// Enables the eruda custom-plugin loader in the served dashboard (local
|
|
@@ -350,7 +454,8 @@ function parseArgs() {
|
|
|
350
454
|
host = args[++i] || '127.0.0.1';
|
|
351
455
|
break;
|
|
352
456
|
case '--token':
|
|
353
|
-
|
|
457
|
+
cliToken = args[++i];
|
|
458
|
+
cliTokenGiven = true;
|
|
354
459
|
break;
|
|
355
460
|
case '--idle-timeout':
|
|
356
461
|
idleTimeout = parseInt(args[++i] || '300000', 10);
|
|
@@ -387,7 +492,22 @@ function parseArgs() {
|
|
|
387
492
|
}
|
|
388
493
|
}
|
|
389
494
|
}
|
|
390
|
-
|
|
495
|
+
const { token, source: tokenSource } = resolveToken(cliToken, cliTokenGiven);
|
|
496
|
+
// Scrub the token out of our own environment once it is resolved. Node builds
|
|
497
|
+
// a child's environment from `process.env`, and this server spawns children
|
|
498
|
+
// that are not ours to trust with it: the agent's own `bash` tool
|
|
499
|
+
// (session-pool.ts) and the memonaut indexer (conversation-search.ts) both
|
|
500
|
+
// inherit it, so `!env` typed in the dashboard -- or a prompt-injected agent
|
|
501
|
+
// running `echo $WHEREVER_TOKEN` -- would print the server's auth token into a
|
|
502
|
+
// transcript that is then indexed to disk. The value is already captured in
|
|
503
|
+
// `token` above; nothing reads these variables again.
|
|
504
|
+
delete process.env.WHEREVER_TOKEN;
|
|
505
|
+
delete process.env.PI_REMOTE_TOKEN;
|
|
506
|
+
return { port, host, token, tokenSource, idleTimeout, sslKey, sslCert, noSsl, httpLocalhostFallbackPort, debug };
|
|
507
|
+
}
|
|
508
|
+
/** Loopback-only binds are the safe default; everything else is reachable by others. */
|
|
509
|
+
function isLoopbackHost(host) {
|
|
510
|
+
return host === '127.0.0.1' || host === 'localhost' || host === '::1' || host.startsWith('127.');
|
|
391
511
|
}
|
|
392
512
|
function authenticate(req, token) {
|
|
393
513
|
if (!token)
|
|
@@ -482,30 +602,64 @@ function sendThenTerminate(ws, msg, flushTimeoutMs = 1_000) {
|
|
|
482
602
|
}
|
|
483
603
|
}
|
|
484
604
|
async function main() {
|
|
485
|
-
const { port, host, token, idleTimeout, sslKey, sslCert, noSsl, httpLocalhostFallbackPort, debug } = parseArgs();
|
|
605
|
+
const { port, host, token, tokenSource, idleTimeout, sslKey, sslCert, noSsl, httpLocalhostFallbackPort, debug } = parseArgs();
|
|
486
606
|
debugEnabled = debug;
|
|
487
607
|
const sessionPool = new SessionPool(idleTimeout);
|
|
488
608
|
await sessionPool.initialize();
|
|
489
609
|
const clients = new Map();
|
|
490
|
-
|
|
491
|
-
|
|
610
|
+
// expandTilde so `~/certs/...` works from a systemd `Environment=` line or an
|
|
611
|
+
// EnvironmentFile, neither of which is shell-expanded. Without it the read
|
|
612
|
+
// below fails and (before the explicit-TLS check further down) the server
|
|
613
|
+
// quietly served plaintext instead.
|
|
614
|
+
let actualSslKey = sslKey ? expandTilde(sslKey) : sslKey;
|
|
615
|
+
let actualSslCert = sslCert ? expandTilde(sslCert) : sslCert;
|
|
492
616
|
let isSecure = !noSsl;
|
|
617
|
+
let tlsExplicitlyConfigured = false;
|
|
493
618
|
if (isSecure) {
|
|
619
|
+
// A key and a certificate only work as a PAIR, so "exactly one supplied" is a
|
|
620
|
+
// misconfiguration. It used to be silent: the `!key || !cert` test threw away
|
|
621
|
+
// the half that WAS supplied and used the self-signed pair, so an operator who
|
|
622
|
+
// pointed --ssl-key at a real key and forgot the cert got a working server
|
|
623
|
+
// presenting a completely different certificate, with nothing in the log. Say
|
|
624
|
+
// so, loudly; the behaviour (fall back to the self-signed pair) is unchanged.
|
|
625
|
+
if (!!actualSslKey !== !!actualSslCert) {
|
|
626
|
+
const supplied = actualSslKey ? '--ssl-key / WHEREVER_SSL_KEY' : '--ssl-cert / WHEREVER_SSL_CERT';
|
|
627
|
+
const missing = actualSslKey ? '--ssl-cert / WHEREVER_SSL_CERT' : '--ssl-key / WHEREVER_SSL_KEY';
|
|
628
|
+
console.warn(`[wherever] ${supplied} was supplied but ${missing} was not. A key and a certificate ` +
|
|
629
|
+
`must be given together; IGNORING the one supplied and using the self-signed pair instead.`);
|
|
630
|
+
actualSslKey = undefined;
|
|
631
|
+
actualSslCert = undefined;
|
|
632
|
+
}
|
|
633
|
+
// Whether the operator POINTED AT specific TLS material, as opposed to
|
|
634
|
+
// letting the server mint its own. It decides what happens if that material
|
|
635
|
+
// cannot be loaded further down: see the `tlsExplicitlyConfigured` branch.
|
|
636
|
+
tlsExplicitlyConfigured = !!(actualSslKey && actualSslCert);
|
|
494
637
|
if (!actualSslKey || !actualSslCert) {
|
|
495
|
-
// Automatic self-signed certificate generation
|
|
496
|
-
|
|
497
|
-
|
|
638
|
+
// Automatic self-signed certificate generation. These files are WRITTEN, so
|
|
639
|
+
// they belong to the state dir (WHEREVER_STATE_DIR, defaulting to the config
|
|
640
|
+
// dir, itself defaulting to ~/.wherever) -- with both unset this is exactly
|
|
641
|
+
// the ~/.wherever/certs it has always been.
|
|
642
|
+
const certsDir = getWhereverCertsDir();
|
|
643
|
+
// 0700 on creation: the state dir can now be pointed at a shared location
|
|
644
|
+
// (/var/lib/...), and a world-writable certs dir would let a local user
|
|
645
|
+
// swap in their own key/cert pair. An existing directory keeps its mode.
|
|
498
646
|
const defaultKeyPath = path.join(certsDir, 'localhost.key');
|
|
499
647
|
const defaultCertPath = path.join(certsDir, 'localhost.crt');
|
|
500
648
|
if (!fs.existsSync(defaultKeyPath) || !fs.existsSync(defaultCertPath)) {
|
|
501
649
|
console.log('Generating self-signed SSL certificates for secure HTTPS/WSS...');
|
|
502
650
|
try {
|
|
503
|
-
fs.mkdirSync(certsDir, { recursive: true });
|
|
651
|
+
fs.mkdirSync(certsDir, { recursive: true, mode: 0o700 });
|
|
504
652
|
execFileSync('openssl', ['req', '-x509', '-newkey', 'rsa:2048', '-keyout', defaultKeyPath, '-out', defaultCertPath, '-sha256', '-days', '3650', '-nodes', '-subj', '/CN=localhost'], { stdio: 'ignore' });
|
|
653
|
+
// Assert 0600 ourselves rather than trusting openssl's default: it is
|
|
654
|
+
// a private key, and the mode it lands with has varied by version.
|
|
655
|
+
try {
|
|
656
|
+
fs.chmodSync(defaultKeyPath, 0o600);
|
|
657
|
+
}
|
|
658
|
+
catch { }
|
|
505
659
|
console.log(`Self-signed certificates generated successfully in ${certsDir}`);
|
|
506
660
|
}
|
|
507
661
|
catch (err) {
|
|
508
|
-
console.warn(
|
|
662
|
+
console.warn(`Failed to generate self-signed certificates in ${certsDir} using OpenSSL. Falling back to HTTP.`, err.message);
|
|
509
663
|
isSecure = false;
|
|
510
664
|
}
|
|
511
665
|
}
|
|
@@ -1508,6 +1662,20 @@ async function main() {
|
|
|
1508
1662
|
}
|
|
1509
1663
|
}
|
|
1510
1664
|
catch (err) {
|
|
1665
|
+
// Falling back to plaintext is only acceptable for material the server
|
|
1666
|
+
// chose for itself. When the operator EXPLICITLY pointed at a key and a
|
|
1667
|
+
// certificate, silently serving HTTP on the same (possibly 0.0.0.0)
|
|
1668
|
+
// address is the same fail-open ADR 0007 rules out for the token file:
|
|
1669
|
+
// it is the exact shape of a secret that has not been decrypted yet, and
|
|
1670
|
+
// clients would then send their token in cleartext to a server that looks
|
|
1671
|
+
// healthy. Refuse to start instead.
|
|
1672
|
+
if (tlsExplicitlyConfigured) {
|
|
1673
|
+
console.error(`FATAL: TLS was explicitly configured (key ${actualSslKey}, cert ${actualSslCert}) but ` +
|
|
1674
|
+
`could not be loaded: ${err.message}. Refusing to start: falling back to ` +
|
|
1675
|
+
`plaintext HTTP would silently expose traffic (and the auth token) on ${host}:${port}. ` +
|
|
1676
|
+
`Pass --no-ssl if plaintext is genuinely what you want.`);
|
|
1677
|
+
process.exit(1);
|
|
1678
|
+
}
|
|
1511
1679
|
console.error(`Failed to load SSL certificates from ${actualSslKey} and ${actualSslCert}. Falling back to HTTP.`, err.message);
|
|
1512
1680
|
server = createHttpServer(requestHandler);
|
|
1513
1681
|
}
|
|
@@ -1687,8 +1855,24 @@ async function main() {
|
|
|
1687
1855
|
wss.on('close', () => clearInterval(heartbeat));
|
|
1688
1856
|
server.listen(port, host, () => {
|
|
1689
1857
|
const protocol = isSecureServer ? 'https' : 'http';
|
|
1690
|
-
|
|
1858
|
+
// The SOURCE, never the token itself: this line goes to the journal, which
|
|
1859
|
+
// is readable by more people than the secret is.
|
|
1860
|
+
const authInfo = token ? ` (token-protected via ${tokenSource})` : ' (no authentication)';
|
|
1691
1861
|
console.log(`\n🔐 Wherever Server: ${protocol}://${host}:${port}${authInfo}`);
|
|
1862
|
+
if (token && tokenSource === '--token') {
|
|
1863
|
+
console.warn('[wherever] the token came from the command line, which is visible to every user on this ' +
|
|
1864
|
+
'machine via `ps`. For a real deployment set WHEREVER_TOKEN (or WHEREVER_TOKEN_FILE) instead.');
|
|
1865
|
+
}
|
|
1866
|
+
// Binding off-loopback with no token is a valid, long-supported choice (it
|
|
1867
|
+
// is how a trusted mesh/VPN setup runs), so it stays permitted. But it is
|
|
1868
|
+
// also exactly what a failed secret render looks like, and the two are
|
|
1869
|
+
// indistinguishable from the outside, so it must not slip by as one
|
|
1870
|
+
// parenthetical word in an otherwise cheerful startup line.
|
|
1871
|
+
if (!token && !isLoopbackHost(host)) {
|
|
1872
|
+
console.warn(`[wherever] WARNING: listening on ${host} with NO AUTHENTICATION. Anyone who can reach ` +
|
|
1873
|
+
`this address has full agent and filesystem access. If you meant to configure a token, ` +
|
|
1874
|
+
`it did not arrive: check WHEREVER_TOKEN / WHEREVER_TOKEN_FILE.`);
|
|
1875
|
+
}
|
|
1692
1876
|
if (isSecureServer) {
|
|
1693
1877
|
console.log(`
|
|
1694
1878
|
👉 FIRST TIME CONNECTING?
|