@parhelia/capture 0.4.13062 → 0.4.13145

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.
Files changed (47) hide show
  1. package/README.md +23 -4
  2. package/dist/cli.js +101 -19
  3. package/dist/cmsJob.d.ts +9 -0
  4. package/dist/cmsJob.d.ts.map +1 -1
  5. package/dist/cmsJob.js +81 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/install/install.d.ts +4 -0
  10. package/dist/install/install.d.ts.map +1 -1
  11. package/dist/install/install.js +37 -10
  12. package/dist/install/layout.d.ts +9 -0
  13. package/dist/install/layout.d.ts.map +1 -1
  14. package/dist/install/layout.js +7 -1
  15. package/dist/install/manifestSignature.d.ts +30 -0
  16. package/dist/install/manifestSignature.d.ts.map +1 -0
  17. package/dist/install/manifestSignature.js +93 -0
  18. package/dist/install/releaseKeys.d.ts +2 -0
  19. package/dist/install/releaseKeys.d.ts.map +1 -0
  20. package/dist/install/releaseKeys.js +16 -0
  21. package/dist/install/services.d.ts +12 -0
  22. package/dist/install/services.d.ts.map +1 -1
  23. package/dist/install/services.js +45 -1
  24. package/dist/install/units.d.ts +8 -0
  25. package/dist/install/units.d.ts.map +1 -1
  26. package/dist/install/units.js +39 -3
  27. package/dist/install/updateLock.d.ts +14 -0
  28. package/dist/install/updateLock.d.ts.map +1 -0
  29. package/dist/install/updateLock.js +75 -0
  30. package/dist/install/updater.d.ts +28 -1
  31. package/dist/install/updater.d.ts.map +1 -1
  32. package/dist/install/updater.js +74 -2
  33. package/dist/install/versions.d.ts +11 -1
  34. package/dist/install/versions.d.ts.map +1 -1
  35. package/dist/install/versions.js +16 -2
  36. package/dist/isolation.d.ts +17 -1
  37. package/dist/isolation.d.ts.map +1 -1
  38. package/dist/isolation.js +21 -5
  39. package/dist/parheliaClient.d.ts +13 -0
  40. package/dist/parheliaClient.d.ts.map +1 -1
  41. package/dist/parheliaClient.js +7 -0
  42. package/dist/webIsolation.d.ts +2 -0
  43. package/dist/webIsolation.d.ts.map +1 -1
  44. package/dist/webIsolation.js +7 -5
  45. package/dist/worker.d.ts.map +1 -1
  46. package/dist/worker.js +3 -0
  47. package/package.json +2 -2
package/README.md CHANGED
@@ -25,14 +25,15 @@ What `install` sets up on Linux: the users `parhelia-capture` (the worker) and `
25
25
  whose only group is `parhelia-capture-ipc`); the code under `/opt/parhelia-capture/versions/<version>` with the `current`
26
26
  link, root-owned and read-only to both; the key `/etc/parhelia-capture/worker.key` (0600, the worker's); Chromium's libraries
27
27
  and an emoji font on apt systems; the units `parhelia-capture-worker`, `parhelia-capture-browser-host` (no network of its
28
- own, see below) and `parhelia-capture-updater` with its timer; and the command `/usr/local/sbin/parhelia-capture`. On Windows:
29
- the code under `%ProgramFiles%\Parhelia Capture`, the data and key under `%ProgramData%\Parhelia Capture` with inheritance
30
- off, the browser's outbound firewall rule, and three scheduled tasks.
28
+ own, see below), `parhelia-capture-updater` with its timer and `parhelia-capture-update-watch`; and the command
29
+ `/usr/local/sbin/parhelia-capture`. On Windows: the code under `%ProgramFiles%\Parhelia Capture`, the data and key under
30
+ `%ProgramData%\Parhelia Capture` with inheritance off, the browser's outbound firewall rule, and four scheduled tasks.
31
31
 
32
32
  ```bash
33
33
  parhelia-capture status # versions, services, last poll, public websites, the updater's last run
34
34
  parhelia-capture doctor # names what is wrong (Node, origin, SSO, key, permissions, sandbox, proxy or CA)
35
- parhelia-capture update # an update now (also for "Notify only" workers); --from <tarball> for air-gapped ones
35
+ parhelia-capture update # an update now (also for "Notify only" workers); --from <tarball> for air-gapped ones;
36
+ # --allow-downgrade to go back to an older version the host names
36
37
  parhelia-capture uninstall # removes everything; revoke the worker under Settings › Capture service
37
38
  ```
38
39
 
@@ -46,6 +47,19 @@ and waits for the new version's first poll, else it rolls back. Each worker's po
46
47
  default) or **Notify only**. Below the security minimum, or with a browser past its age, screenshots of public websites stay
47
48
  off by themselves; CMS captures continue.
48
49
 
50
+ Releases are signed: the pipeline signs each manifest with an Ed25519 release key, and a sidecar that trusts release keys
51
+ (`src/install/releaseKeys.ts`) installs nothing whose manifest carries no valid signature, so a host that is compromised or
52
+ impersonated cannot name a build of its own. No updater goes back to an older version by itself
53
+ (`parhelia-capture update --allow-downgrade` does, by hand). Each worker follows the **Stable** or the **Canary** channel:
54
+ canary workers are named a new release first, and a reviewed promotion makes it the stable one
55
+ (docs/capture-service.md § Releasing).
56
+
57
+ The updater checks on a timer (every six hours on Linux, daily on Windows). **Update now** under Settings › Capture service
58
+ does not wait for it: the update watch (`parhelia-capture update-watch`, its own unit or task, as root/SYSTEM) holds a long
59
+ poll against Parhelia with the worker key and runs the same update the moment an administrator asks, also for "Notify only"
60
+ workers. One update runs at a time on a machine. An install from before the update watch gets it at the first check its new
61
+ version makes.
62
+
49
63
  ## What each job gets
50
64
 
51
65
  - A browser of its own (the sidecar's Chromium build, sandbox on) whose every connection goes through the job's egress
@@ -80,5 +94,10 @@ socket but its own, D-Bus must be unreachable, and Chromium must run sandboxed.
80
94
  be refused. When Parhelia runs on the same machine, name a probe on another host with `--probe-url`. On Windows, a sidecar
81
95
  on the machine that runs Parhelia refuses `public-web` by name, because loopback is not filtered there.
82
96
 
97
+ An administrator can accept that on Windows with `install --accept-colocated-web --probe-url <a URL on another host>`. Only
98
+ the egress proxy then keeps a captured page from Parhelia and that machine's local services, so the self-test requires the
99
+ proxy's refusal of Parhelia's address, and the worker reports `capture-web-colocated-accepted` as a problem on every poll.
100
+ The option changes nothing on Linux or on a machine that does not run Parhelia.
101
+
83
102
  Local development: `npm run capture` (repository root) runs a worker from source against :5090 with a dev key;
84
103
  `scripts/run-scenario.ps1 <scenario> -Capture` starts one with the scenario and gives the host the matching key.
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  /*
3
3
  * Capture sidecar CS4-CS6: the command line.
4
4
  * install / uninstall / status / update the service on this machine (CS6: units or tasks, the updater, the hashes)
5
+ * update-watch the updater's long poll for "Update now" (its unit or task starts it)
5
6
  * start the worker (an installed one reads --config; with --web the public-web profile)
6
7
  * browser-host the isolated browser host (its unit starts it)
7
8
  * doctor names what is wrong; --profile public-web proves the isolation; --quick is the
@@ -18,9 +19,10 @@ import { runBrowserHost } from "./browserHost.js";
18
19
  import { generalChecks, printChecks, quickCapture } from "./install/doctor.js";
19
20
  import { install, statusLines, uninstall } from "./install/install.js";
20
21
  import { layoutFor } from "./install/layout.js";
21
- import { selfTest, services, windowsFirewall } from "./install/services.js";
22
+ import { ensureUpdateWatch, restartUpdateWatch, selfTest, services, windowsFirewall } from "./install/services.js";
22
23
  import { realSys } from "./install/sys.js";
23
- import { runUpdate } from "./install/updater.js";
24
+ import { acquireUpdateLock } from "./install/updateLock.js";
25
+ import { runUpdate, watchForUpdateRequests } from "./install/updater.js";
24
26
  import { browserOf, readRecord } from "./install/versions.js";
25
27
  import { browserHostUnitProperties, ownAddresses, parheliaIsColocated, socketDirectoriesOutsideHiddenTrees } from "./isolation.js";
26
28
  import { ParheliaClient, newWorkerKey } from "./parheliaClient.js";
@@ -34,17 +36,21 @@ Install (root on Linux, Administrator on Windows; Node 22 or later):
34
36
  npx @parhelia/capture install --origin <url> --pair <XXXXX-XXXXX-XXXXX-XXXXX> [--name <name>] [--no-web]
35
37
  [--probe-url <url>] [--public-url <url>] [--registry <url>] [--browser-mirror <url>]
36
38
  [--browser-path <chrome> | --from <tarball>] [--key-file <path>]
37
- parhelia-capture status | doctor [--profile public-web] | update [--from <tarball>] | uninstall [--keep-key]
39
+ [--accept-colocated-web]
40
+ parhelia-capture status | doctor [--profile public-web] | update [--from <tarball>] [--allow-downgrade] | uninstall [--keep-key]
38
41
 
39
42
  By hand:
40
43
  parhelia-capture pair --origin <url> --code <code> --key-file <path> [--name <name>]
41
44
  parhelia-capture start (--config <file> | --origin <url> (--key-file <path> | env PARHELIA_CAPTURE_KEY)) [--browser <chrome>]
42
- [--web [--socket-dir <dir>] [--probe-url <url>] [--public-url <url>]]
45
+ [--web [--socket-dir <dir>] [--probe-url <url>] [--public-url <url>] [--accept-colocated-web]]
43
46
  parhelia-capture browser-host [--socket-dir <dir>] [--install-dir <dir> | --browser <chrome>]
44
47
  parhelia-capture doctor --profile public-web (--config <file> | --origin <url> --key-file <path>) [--socket-dir <dir>]
48
+ [--probe-url <url>] [--public-url <url>] [--accept-colocated-web]
45
49
  parhelia-capture unit-properties [--socket-dir <dir>] [--read-only <path>]... [--user-unit]
46
50
 
47
- --origin is the address this machine reaches Parhelia at (often an internal one). The socket directory defaults to ${DEFAULT_SOCKET_DIR}.`;
51
+ --origin is the address this machine reaches Parhelia at (often an internal one). The socket directory defaults to ${DEFAULT_SOCKET_DIR}.
52
+ --accept-colocated-web (Windows, with --probe-url) takes screenshots of public websites on the machine that runs Parhelia although
53
+ loopback is not filtered there: only the egress proxy then keeps a captured page from Parhelia, and the worker reports that as a problem.`;
48
54
  function option(args, name) {
49
55
  const at = args.indexOf(name);
50
56
  return at >= 0 ? args[at + 1] : undefined;
@@ -78,6 +84,10 @@ function readConfig(args, fallback) {
78
84
  return undefined;
79
85
  }
80
86
  }
87
+ /** Windows: the administrator's acceptance of public-web on Parhelia's own machine: an install's own, or by hand the flag. */
88
+ function acceptsColocated(args, config) {
89
+ return config ? config.acceptColocatedWeb === true : args.includes("--accept-colocated-web");
90
+ }
81
91
  /** The running package and its playwright-core (a source build installs these as they are). */
82
92
  function self() {
83
93
  const require = createRequire(import.meta.url);
@@ -89,6 +99,24 @@ function self() {
89
99
  };
90
100
  }
91
101
  const log = (line) => console.log(JSON.stringify({ at: new Date().toISOString(), ...line }));
102
+ /** What the updater's commands (`update`, `update-watch`) run with: the installed configuration, as root or an Administrator. */
103
+ function updaterContext(sys, args) {
104
+ const layout = layoutFor(process.platform);
105
+ const config = readConfig(args, layout.configFile);
106
+ if (!config)
107
+ throw new Error("The capture service is not installed here (no configuration).");
108
+ if (!sys.isPrivileged())
109
+ throw new Error("The updater owns the code: run it as root (Linux) or from an Administrator shell (Windows).");
110
+ const client = new ParheliaClient({ origin: config.origin, key: readKey(args, config), version: SIDECAR_VERSION });
111
+ return { layout, config, client };
112
+ }
113
+ function updaterDeps(sys, layout, config, client) {
114
+ return {
115
+ sys, layout, config, fetchManifest: () => client.manifest(), selfTest: selfTest(sys, layout, config),
116
+ services: services(sys, layout, config.web), firewall: process.platform === "win32" && config.web ? windowsFirewall(sys) : undefined,
117
+ log: (line) => console.log(line),
118
+ };
119
+ }
92
120
  async function main(argv) {
93
121
  const [command, ...args] = argv;
94
122
  if (Number(process.versions.node.split(".")[0]) < 22)
@@ -101,6 +129,7 @@ async function main(argv) {
101
129
  const report = await install({
102
130
  sys, layout, origin, pairCode: option(args, "--pair"), keyFile: option(args, "--key-file"), name: option(args, "--name") ?? hostname(),
103
131
  web: args.includes("--no-web") ? false : undefined, probeUrl: option(args, "--probe-url"), publicUrl: option(args, "--public-url"),
132
+ acceptColocated: args.includes("--accept-colocated-web"),
104
133
  registry: option(args, "--registry"), browserMirror: option(args, "--browser-mirror"), browserPath: option(args, "--browser-path"),
105
134
  fromTarball: option(args, "--from"), self: self(), newKey: newWorkerKey,
106
135
  pair: (at, code, key, name) => ParheliaClient.pair(at, code, key, name),
@@ -128,22 +157,74 @@ async function main(argv) {
128
157
  console.log(line);
129
158
  return;
130
159
  case "update": {
131
- const layout = layoutFor(process.platform);
132
- const config = readConfig(args, layout.configFile);
133
- if (!config)
134
- throw new Error("The capture service is not installed here (no configuration).");
135
- if (!sys.isPrivileged())
136
- throw new Error("The updater owns the code: run it as root (Linux) or from an Administrator shell (Windows).");
137
- const client = new ParheliaClient({ origin: config.origin, key: readKey(args, config), version: SIDECAR_VERSION });
138
- const result = await runUpdate({
139
- sys, layout, config, fetchManifest: () => client.manifest(), selfTest: selfTest(sys, layout, config),
140
- services: services(sys, layout, config.web), firewall: process.platform === "win32" && config.web ? windowsFirewall(sys) : undefined,
141
- log: (line) => console.log(line),
142
- }, { auto: args.includes("--auto"), fromTarball: option(args, "--from") });
160
+ const { layout, config, client } = updaterContext(sys, args);
161
+ const auto = args.includes("--auto");
162
+ const release = acquireUpdateLock(layout.updateLockFile);
163
+ if (!release) {
164
+ // The update watch (or an update by hand) is at work: this check has nothing to add.
165
+ if (auto)
166
+ return void console.log("Another update is running on this machine; this check leaves it to it.");
167
+ throw new Error("Another update is running on this machine. 'parhelia-capture status' shows its outcome.");
168
+ }
169
+ let result;
170
+ try {
171
+ result = await runUpdate(updaterDeps(sys, layout, config, client), { auto, fromTarball: option(args, "--from"), allowDowngrade: !auto && args.includes("--allow-downgrade") });
172
+ }
173
+ finally {
174
+ release();
175
+ }
176
+ // An install from before "Update now" gets its update watch from the first check its new version makes.
177
+ try {
178
+ if (ensureUpdateWatch(sys, layout, config))
179
+ console.log("The update watch is installed: 'Update now' under Settings › Capture service reaches this machine.");
180
+ else if (result.result === "updated")
181
+ restartUpdateWatch(sys, layout);
182
+ }
183
+ catch (error) {
184
+ console.log(`The update watch could not be installed: ${error instanceof Error ? error.message : String(error)}`);
185
+ }
143
186
  if (result.result === "refused" || result.result === "rolled-back" || result.result === "unreachable")
144
187
  process.exitCode = 1;
145
188
  return;
146
189
  }
190
+ case "update-watch": {
191
+ const { layout, config, client } = updaterContext(sys, args);
192
+ const stopping = new AbortController();
193
+ process.once("SIGINT", () => stopping.abort());
194
+ process.once("SIGTERM", () => stopping.abort());
195
+ const sleep = (ms) => new Promise((resolve) => {
196
+ const timer = setTimeout(done, ms);
197
+ function done() {
198
+ clearTimeout(timer);
199
+ stopping.signal.removeEventListener("abort", done);
200
+ resolve();
201
+ }
202
+ stopping.signal.addEventListener("abort", done, { once: true });
203
+ });
204
+ const outcome = await watchForUpdateRequests({
205
+ wait: (waitMs) => client.updateWait(waitMs, AbortSignal.any([stopping.signal, AbortSignal.timeout(waitMs + 20_000)])),
206
+ update: async () => {
207
+ // The timer's check may be at work: wait for it, then look again (it may have installed the version already).
208
+ let release = acquireUpdateLock(layout.updateLockFile);
209
+ for (const until = Date.now() + 35 * 60_000; !release && Date.now() < until && !stopping.signal.aborted;) {
210
+ await sleep(5_000);
211
+ release = acquireUpdateLock(layout.updateLockFile);
212
+ }
213
+ if (!release)
214
+ throw new Error("another update on this machine did not finish");
215
+ try {
216
+ return await runUpdate(updaterDeps(sys, layout, config, client), { auto: false });
217
+ }
218
+ finally {
219
+ release();
220
+ }
221
+ },
222
+ sleep, now: Date.now, stopping: () => stopping.signal.aborted, log: (line) => console.log(line),
223
+ });
224
+ // After an update this process is the old version: it ends, and the service manager starts the new version's watch
225
+ // (systemd restarts it whatever the exit code; a Windows task restarts only one that failed).
226
+ process.exit(outcome === "updated" && process.platform === "win32" ? 1 : 0);
227
+ }
147
228
  case "pair": {
148
229
  const origin = required(args, "--origin");
149
230
  const keyFile = required(args, "--key-file");
@@ -164,7 +245,8 @@ async function main(argv) {
164
245
  const link = web ? await BrowserHostLink.listen(option(args, "--socket-dir") ?? config?.socketDir ?? DEFAULT_SOCKET_DIR, log, { groupAccess: config?.socketGroupAccess }) : undefined;
165
246
  const worker = startWorker({
166
247
  origin: config?.origin ?? required(args, "--origin"), key: readKey(args, config), version: SIDECAR_VERSION, launch: defaultLaunch(browser),
167
- web: link ? { link, isolation: { probeUrl: option(args, "--probe-url") ?? config?.probeUrl, publicUrl: option(args, "--public-url") ?? config?.publicUrl } } : undefined,
248
+ web: link ? { link, isolation: { probeUrl: option(args, "--probe-url") ?? config?.probeUrl, publicUrl: option(args, "--public-url") ?? config?.publicUrl,
249
+ acceptColocated: acceptsColocated(args, config) } } : undefined,
168
250
  install: config ? { record, statusFile: config.statusFile, updaterStatusFile: config.updaterStatusFile } : undefined,
169
251
  });
170
252
  const stop = () => void worker.stop();
@@ -203,7 +285,7 @@ async function main(argv) {
203
285
  if (!host)
204
286
  throw new Error(`No browser host connected within 30 s: start 'parhelia-capture browser-host --socket-dir ${link.socketDir}' in its unit.`);
205
287
  const report = await verifyWebIsolation({ client, link, probeUrl: option(args, "--probe-url") ?? config?.probeUrl,
206
- publicUrl: option(args, "--public-url") ?? config?.publicUrl });
288
+ publicUrl: option(args, "--public-url") ?? config?.publicUrl, acceptColocated: acceptsColocated(args, config) });
207
289
  printChecks(report.checks);
208
290
  console.log(report.ok ? "The public-web profile can run here." : `${report.code}: ${report.reason}`);
209
291
  if (!report.ok)
package/dist/cmsJob.d.ts CHANGED
@@ -13,6 +13,8 @@ export declare const PREVIEW_HANDLE_COOKIE = "parhelia-preview";
13
13
  export declare const PREVIEW_REFUSAL_HEADER = "parhelia-preview-refusal";
14
14
  /** Stops animations, transitions and the caret before measurement (plan CS-D4 step 1); applied through re-validation. */
15
15
  export declare const PRECONDITION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important;caret-color:transparent!important;scroll-behavior:auto!important}";
16
+ /** The version of a job's `originAliases` this worker reads; any other is ignored. */
17
+ export declare const ORIGIN_ALIASES_VERSION = 1;
16
18
  export type JobOutcome = {
17
19
  kind: "result";
18
20
  result: unknown;
@@ -38,6 +40,13 @@ export type CmsJobOptions = {
38
40
  };
39
41
  /** The `host:port` of an origin as the egress proxy sees it on CONNECT or in an absolute request URL. */
40
42
  export declare function hostPortOf(origin: string): string;
43
+ /**
44
+ * The origins a job names as its Parhelia's own (`originAliases`), as `scheme://host[:port]`, without the worker's own origin: none for a
45
+ * job without the field, of a version this worker does not know, or naming nothing that is an http(s) origin.
46
+ */
47
+ export declare function originAliasesOf(offer: Pick<CaptureJobOffer, "originAliases">, origin: string): string[];
48
+ /** Where the job's browser loads `url` from: on an alias, the same path and query on the worker's own origin; null for any other URL. */
49
+ export declare function aliasedUrl(url: string, aliases: readonly string[], origin: string): string | null;
41
50
  export declare function runCmsJob(offer: CaptureJobOffer, options: CmsJobOptions): Promise<JobOutcome>;
42
51
  /** The code a frame URL carries and the same URL without it (the rest of the query as spelled); null for a URL with none. */
43
52
  export declare function previewCodeOf(url: string): {
@@ -1 +1 @@
1
- {"version":3,"file":"cmsJob.d.ts","sourceRoot":"","sources":["../src/cmsJob.ts"],"names":[],"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C7H,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAOnF"}
package/dist/cmsJob.js CHANGED
@@ -11,6 +11,10 @@ export const PREVIEW_HANDLE_COOKIE = "parhelia-preview";
11
11
  export const PREVIEW_REFUSAL_HEADER = "parhelia-preview-refusal";
12
12
  /** Stops animations, transitions and the caret before measurement (plan CS-D4 step 1); applied through re-validation. */
13
13
  export const PRECONDITION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important;caret-color:transparent!important;scroll-behavior:auto!important}";
14
+ /** The version of a job's `originAliases` this worker reads; any other is ignored. */
15
+ export const ORIGIN_ALIASES_VERSION = 1;
16
+ /** The most aliases a job's browser routes. */
17
+ const MAX_ORIGIN_ALIASES = 8;
14
18
  const PREVIEW_REDEEM_TIMEOUT_MS = 15_000;
15
19
  const PREVIEW_SESSION_TIMEOUT_MS = 3_000;
16
20
  /** The `host:port` of an origin as the egress proxy sees it on CONNECT or in an absolute request URL. */
@@ -19,6 +23,80 @@ export function hostPortOf(origin) {
19
23
  const port = url.port || (url.protocol === "https:" ? "443" : "80");
20
24
  return `${url.hostname.toLowerCase()}:${port}`;
21
25
  }
26
+ /**
27
+ * The origins a job names as its Parhelia's own (`originAliases`), as `scheme://host[:port]`, without the worker's own origin: none for a
28
+ * job without the field, of a version this worker does not know, or naming nothing that is an http(s) origin.
29
+ */
30
+ export function originAliasesOf(offer, origin) {
31
+ const field = offer.originAliases;
32
+ if (!field || field.version !== ORIGIN_ALIASES_VERSION || !Array.isArray(field.origins))
33
+ return [];
34
+ const own = new URL(origin).origin;
35
+ const aliases = new Set();
36
+ for (const entry of field.origins) {
37
+ if (typeof entry !== "string")
38
+ continue;
39
+ let url;
40
+ try {
41
+ url = new URL(entry);
42
+ }
43
+ catch {
44
+ continue;
45
+ }
46
+ if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password || url.origin === own)
47
+ continue;
48
+ aliases.add(url.origin);
49
+ if (aliases.size >= MAX_ORIGIN_ALIASES)
50
+ break;
51
+ }
52
+ return [...aliases];
53
+ }
54
+ /** Where the job's browser loads `url` from: on an alias, the same path and query on the worker's own origin; null for any other URL. */
55
+ export function aliasedUrl(url, aliases, origin) {
56
+ let parsed;
57
+ try {
58
+ parsed = new URL(url);
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ if (!aliases.includes(parsed.origin))
64
+ return null;
65
+ return new URL(parsed.pathname + parsed.search, new URL(origin).origin).toString();
66
+ }
67
+ /**
68
+ * Routes the context's requests on an alias to the worker's own origin (`aliasedUrl`): fetched with the context's own cookies for that
69
+ * origin, redirects not followed (the browser follows them itself, through its egress proxy), and fulfilled as the answer of the URL the
70
+ * page asked for. Logs the first load per job and the count at the end (paths only: a query may carry a code).
71
+ */
72
+ async function routeOriginAliases(context, aliases, origin, jobId, log) {
73
+ if (aliases.length === 0)
74
+ return () => undefined;
75
+ let loads = 0;
76
+ let failures = 0;
77
+ await context.route((url) => aliases.includes(url.origin), async (route) => {
78
+ const target = aliasedUrl(route.request().url(), aliases, origin);
79
+ if (!target)
80
+ return route.continue();
81
+ try {
82
+ // The cookies are the context's own for the worker's origin (Playwright adds them where the request names none), never a
83
+ // header the page's request carried for the alias.
84
+ const headers = Object.fromEntries(Object.entries(route.request().headers()).filter(([name]) => !/^(cookie|host)$/i.test(name)));
85
+ const response = await route.fetch({ url: target, headers, maxRedirects: 0 });
86
+ if (loads++ === 0)
87
+ log({ event: "origin-alias-loaded", job: jobId, path: new URL(target).pathname, status: response.status() });
88
+ await route.fulfill({ response });
89
+ }
90
+ catch (error) {
91
+ failures++;
92
+ log({ event: "origin-alias-failed", job: jobId, path: new URL(target).pathname,
93
+ message: (error instanceof Error ? error.message : String(error)).slice(0, 300) });
94
+ await route.abort("failed").catch(() => undefined);
95
+ }
96
+ });
97
+ log({ event: "origin-aliases", job: jobId, aliases: aliases.length });
98
+ return () => log({ event: "origin-aliases-done", job: jobId, loads, failures });
99
+ }
22
100
  export async function runCmsJob(offer, options) {
23
101
  const log = options.log ?? (() => undefined);
24
102
  const now = options.now ?? Date.now;
@@ -30,6 +108,7 @@ export async function runCmsJob(offer, options) {
30
108
  const allow = [...new Set([hostPortOf(origin), ...offer.allowlist.map((entry) => entry.toLowerCase())])];
31
109
  const proxy = await startEgressProxy({ allow, log: options.egressLog });
32
110
  let browser;
111
+ let aliasesDone = () => { };
33
112
  try {
34
113
  browser = await options.launch(proxyLaunchArgs(proxy.url));
35
114
  const context = await browser.newContext({
@@ -43,6 +122,7 @@ export async function runCmsJob(offer, options) {
43
122
  permissions: ["local-network-access"],
44
123
  });
45
124
  await addCaptureCookie(context, origin, offer);
125
+ aliasesDone = await routeOriginAliases(context, originAliasesOf(offer, origin), origin, offer.jobId, log);
46
126
  return await drive(context, offer, { ...options, origin }, controllerUrl, targetUrl, log, now);
47
127
  }
48
128
  catch (error) {
@@ -51,6 +131,7 @@ export async function runCmsJob(offer, options) {
51
131
  return { kind: "failed", errorCode: "capture-worker-failed", message: error instanceof Error ? error.message : String(error) };
52
132
  }
53
133
  finally {
134
+ aliasesDone();
54
135
  await browser?.close().catch(() => undefined);
55
136
  await proxy.close();
56
137
  }
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { runCmsJob, hostPortOf, type CmsJobOptions, type JobOutcome } from "./cm
3
3
  export { runWebJob, normalizeWebParameters, type WebCaptureResult, type WebJobOutcome } from "./webJob.js";
4
4
  export { runBrowserHost, startForwarder, visibleSockets, type BrowserHostOptions } from "./browserHost.js";
5
5
  export { BrowserHostLink, type EgressPolicy } from "./browserHostLink.js";
6
- export { browserHostUnitProperties, socketDirectoriesOutsideHiddenTrees, judgeIsolation, webPreconditionRefusal, parheliaIsColocated, ownAddresses, type IsolationReport, type IsolationCheck, } from "./isolation.js";
6
+ export { browserHostUnitProperties, socketDirectoriesOutsideHiddenTrees, judgeIsolation, webPreconditionRefusal, parheliaIsColocated, ownAddresses, colocatedAccepted, COLOCATED_ACCEPTED_CODE, COLOCATED_ACCEPTED_NOTE, type IsolationReport, type IsolationCheck, } from "./isolation.js";
7
7
  export { verifyWebIsolation, webDenyAddresses } from "./webIsolation.js";
8
8
  export { startEgressProxy, decideEgress, isBlockedAddress, blockListOf, proxyLaunchArgs, BASELINE_BLOCKED_RANGES, type EgressLogEntry, } from "./egressProxy.js";
9
9
  export { ParheliaClient, ParheliaRefusedError, newWorkerKey, workerKeyHash, type CaptureJobOffer, type CapturePollAnswer } from "./parheliaClient.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3G,OAAO,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,yBAAyB,EAAE,mCAAmC,EAAE,cAAc,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,YAAY,EACzI,KAAK,eAAe,EAAE,KAAK,cAAc,GAC1C,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,eAAe,EAAE,uBAA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AAE,YAAY,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACtJ,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { runCmsJob, hostPortOf } from "./cmsJob.js";
3
3
  export { runWebJob, normalizeWebParameters } from "./webJob.js";
4
4
  export { runBrowserHost, startForwarder, visibleSockets } from "./browserHost.js";
5
5
  export { BrowserHostLink } from "./browserHostLink.js";
6
- export { browserHostUnitProperties, socketDirectoriesOutsideHiddenTrees, judgeIsolation, webPreconditionRefusal, parheliaIsColocated, ownAddresses, } from "./isolation.js";
6
+ export { browserHostUnitProperties, socketDirectoriesOutsideHiddenTrees, judgeIsolation, webPreconditionRefusal, parheliaIsColocated, ownAddresses, colocatedAccepted, COLOCATED_ACCEPTED_CODE, COLOCATED_ACCEPTED_NOTE, } from "./isolation.js";
7
7
  export { verifyWebIsolation, webDenyAddresses } from "./webIsolation.js";
8
8
  export { startEgressProxy, decideEgress, isBlockedAddress, blockListOf, proxyLaunchArgs, BASELINE_BLOCKED_RANGES, } from "./egressProxy.js";
9
9
  export { ParheliaClient, ParheliaRefusedError, newWorkerKey, workerKeyHash } from "./parheliaClient.js";
@@ -20,6 +20,8 @@ export type InstallInput = {
20
20
  web?: boolean;
21
21
  probeUrl?: string;
22
22
  publicUrl?: string;
23
+ /** Windows: run public-web on the machine that runs Parhelia all the same (`--accept-colocated-web`). */
24
+ acceptColocated?: boolean;
23
25
  registry?: string;
24
26
  browserMirror?: string;
25
27
  browserPath?: string;
@@ -41,6 +43,8 @@ export type InstallInput = {
41
43
  firewall?: Firewall;
42
44
  /** How long to wait for the worker's first good poll (0: do not wait). */
43
45
  waitMs?: number;
46
+ /** The release keys the host's manifest must be signed by (default: the ones this build ships). */
47
+ trustedKeys?: readonly string[];
44
48
  log?: (line: string) => void;
45
49
  };
46
50
  export type InstallReport = {
@@ -1 +1 @@
1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AAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CASxD;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAgLzE;AAED,MAAM,MAAM,cAAc,GAAG;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AAE3G,6GAA6G;AAC7G,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CA6BrD;AAED,4GAA4G;AAC5G,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAyB9D"}
@@ -4,13 +4,16 @@
4
4
  * Linux (root, systemd): the ipc group and two service users (the worker, and the browser user whose only group is the ipc
5
5
  * group); /opt/parhelia-capture root-owned and read-only to both; the key (0600, the worker's); the version the host names,
6
6
  * installed with every hash checked (a source build: the running package); Chromium's libraries and emoji fonts on apt systems;
7
- * the socket scan (A7); the worker, browser host and updater units and the timer; then it waits for the worker's first poll.
7
+ * the socket scan (A7); the worker, browser host, updater and update watch units and the timer; then it waits for the worker's
8
+ * first poll.
8
9
  * Windows (Administrator): the code under Program Files, the data directory and key with inheritance off (the service account,
9
- * Administrators, SYSTEM), the browser's outbound firewall rule installed and verified before it runs, and three scheduled tasks.
10
- * On a Windows machine that runs Parhelia itself, public-web is refused by name (plan §8) and CMS captures still install.
10
+ * Administrators, SYSTEM), the browser's outbound firewall rule installed and verified before it runs, and four scheduled tasks.
11
+ * On a Windows machine that runs Parhelia itself, public-web is refused by name (plan §8) and CMS captures still install;
12
+ * `--accept-colocated-web` lifts that refusal by the administrator's choice (a probe on another host is then required).
11
13
  */
12
- import { webPreconditionRefusal } from "../isolation.js";
14
+ import { COLOCATED_ACCEPTED_NOTE, webPreconditionRefusal } from "../isolation.js";
13
15
  import { BROWSER_USER, IPC_GROUP, TASK, UNIT, WORKER_USER, } from "./layout.js";
16
+ import { RELEASE_KEYS } from "./releaseKeys.js";
14
17
  import { services } from "./services.js";
15
18
  import { dataDirAclArgs, keyFileAclArgs, keyFileAclHolds, launcherScript, linuxUnits, windowsTasks } from "./units.js";
16
19
  import { readJson } from "./updater.js";
@@ -109,13 +112,25 @@ export async function install(input) {
109
112
  web = false;
110
113
  webNote = "The pairing does not allow screenshots of public websites.";
111
114
  }
115
+ // The acceptance is Windows' alone and recorded only where it applies: a machine Parhelia does not run on keeps both
116
+ // protections, and one Parhelia moves onto later is refused until the administrator installs again.
117
+ let acceptColocated = false;
112
118
  if (web && layout.platform === "win32") {
113
- const refusal = webPreconditionRefusal({ platform: "win32", colocated: await input.colocated(), probeUrl: input.probeUrl });
119
+ const colocated = await input.colocated();
120
+ const refusal = webPreconditionRefusal({ platform: "win32", colocated, probeUrl: input.probeUrl, acceptColocated: input.acceptColocated });
114
121
  if (refusal) {
115
122
  web = false;
116
123
  webNote = `${refusal.code}: ${refusal.message}`;
117
124
  }
125
+ else if (colocated && input.acceptColocated) {
126
+ acceptColocated = true;
127
+ warnings.push(COLOCATED_ACCEPTED_NOTE);
128
+ }
118
129
  }
130
+ if (input.acceptColocated && !acceptColocated && !webNote)
131
+ warnings.push(layout.platform === "win32"
132
+ ? "--accept-colocated-web was not needed: Parhelia does not run on this machine, or public websites are off."
133
+ : "--accept-colocated-web applies to Windows only; on Linux the browser host has no network of its own.");
119
134
  // 4. Chromium's libraries and fonts (apt systems; elsewhere named as a warning).
120
135
  if (layout.platform === "linux") {
121
136
  if (sys.exec("sh", ["-c", "command -v apt-get"]).status === 0) {
@@ -132,6 +147,7 @@ export async function install(input) {
132
147
  // 5. The code: the version the host names (hash-checked), or this running package for a source build.
133
148
  const config = {
134
149
  origin: new URL(input.origin).origin, keyFile: layout.keyFile, web, probeUrl: input.probeUrl, publicUrl: input.publicUrl,
150
+ ...(acceptColocated ? { acceptColocatedWeb: true } : {}),
135
151
  socketDir: layout.socketDir, installDir: layout.currentLink, versionsDir: layout.versionsDir, statusFile: layout.statusFile,
136
152
  updaterStatusFile: layout.updaterStatusFile, socketGroupAccess: layout.platform === "linux", registry: input.registry,
137
153
  browserMirror: input.browserMirror, browserPath: input.browserPath,
@@ -140,7 +156,7 @@ export async function install(input) {
140
156
  let versionDir;
141
157
  if (answer.release) {
142
158
  log(`Installing version ${answer.manifest.version} (named by Parhelia)`);
143
- versionDir = await installRelease(sys, layout, config, answer.manifest, { fromTarball: input.fromTarball, log });
159
+ versionDir = await installRelease(sys, layout, config, answer.manifest, { fromTarball: input.fromTarball, log, trustedKeys: input.trustedKeys });
144
160
  }
145
161
  else {
146
162
  log("Parhelia names no release (a source build): installing this package as it is, unchecked");
@@ -155,6 +171,7 @@ export async function install(input) {
155
171
  if (!held?.ok) {
156
172
  web = false;
157
173
  config.web = false;
174
+ delete config.acceptColocatedWeb;
158
175
  webNote = `capture-web-firewall: the browser's outbound rule could not be installed and verified${held ? ` (${held.detail})` : ""}; screenshots of public websites stay off.`;
159
176
  }
160
177
  }
@@ -174,9 +191,11 @@ export async function install(input) {
174
191
  if (!web)
175
192
  sys.remove(layout.join(layout.unitDir, UNIT.browserHost));
176
193
  must(sys.exec("systemctl", ["daemon-reload"]), "Reloading systemd");
177
- must(sys.exec("systemctl", ["enable", UNIT.worker, ...(web ? [UNIT.browserHost] : []), UNIT.updaterTimer]), "Enabling the units");
194
+ must(sys.exec("systemctl", ["enable", UNIT.worker, ...(web ? [UNIT.browserHost] : []), UNIT.updaterTimer, UNIT.updateWatch]), "Enabling the units");
178
195
  sys.exec("systemctl", ["stop", UNIT.worker]);
179
196
  must(sys.exec("systemctl", ["start", UNIT.updaterTimer]), "Starting the update timer");
197
+ // "Update now": the updater's long poll (restart: a reinstall runs the version just installed).
198
+ must(sys.exec("systemctl", ["restart", UNIT.updateWatch]), "Starting the update watch");
180
199
  }
181
200
  else {
182
201
  sys.mkdir(layout.unitDir);
@@ -187,6 +206,9 @@ export async function install(input) {
187
206
  }
188
207
  if (!web)
189
208
  sys.exec("schtasks", ["/Delete", "/TN", TASK.folder + TASK.browserHost, "/F"]);
209
+ // "Update now": the updater's long poll (ended first: a reinstall runs the version just installed).
210
+ sys.exec("schtasks", ["/End", "/TN", TASK.folder + TASK.updateWatch]);
211
+ must(sys.exec("schtasks", ["/Run", "/TN", TASK.folder + TASK.updateWatch]), "Starting the update watch");
190
212
  }
191
213
  services(sys, layout, web).start();
192
214
  // 8. The first good poll proves origin, key and code.
@@ -209,7 +231,7 @@ export function uninstall(input) {
209
231
  const { sys, layout } = input;
210
232
  preflight(sys, layout);
211
233
  if (layout.platform === "linux") {
212
- sys.exec("systemctl", ["disable", "--now", UNIT.updaterTimer, UNIT.browserHost, UNIT.worker]);
234
+ sys.exec("systemctl", ["disable", "--now", UNIT.updateWatch, UNIT.updaterTimer, UNIT.browserHost, UNIT.worker]);
213
235
  for (const unit of Object.values(UNIT))
214
236
  sys.remove(layout.join(layout.unitDir, unit));
215
237
  sys.exec("systemctl", ["daemon-reload"]);
@@ -226,7 +248,7 @@ export function uninstall(input) {
226
248
  sys.exec("groupdel", [IPC_GROUP]);
227
249
  return;
228
250
  }
229
- for (const task of [TASK.worker, TASK.browserHost, TASK.updater]) {
251
+ for (const task of [TASK.updateWatch, TASK.worker, TASK.browserHost, TASK.updater]) {
230
252
  sys.exec("schtasks", ["/End", "/TN", TASK.folder + task]);
231
253
  sys.exec("schtasks", ["/Delete", "/TN", TASK.folder + task, "/F"]);
232
254
  }
@@ -251,12 +273,17 @@ export function statusLines(sys, layout) {
251
273
  lines.push(`Parhelia: ${config.origin}`);
252
274
  lines.push(`Version: ${current ?? "none"}${record ? ` (${record.source === "release" ? "checked against Parhelia's hashes" : "source build, unchecked"}; browser ${record.browserRevision ?? "?"})` : ""}`);
253
275
  if (layout.platform === "linux") {
254
- for (const unit of [UNIT.worker, ...(config.web ? [UNIT.browserHost] : []), UNIT.updaterTimer])
276
+ for (const unit of [UNIT.worker, ...(config.web ? [UNIT.browserHost] : []), UNIT.updaterTimer, UNIT.updateWatch])
255
277
  lines.push(`${unit}: ${sys.exec("systemctl", ["is-active", unit]).stdout.trim() || "unknown"}`);
256
278
  }
257
279
  const status = readJson(sys, layout.statusFile);
258
280
  lines.push(status ? `Last poll: ${status.lastPollUtc ?? "never"} (${status.lastPollOk ? "ok" : status.lastPollError ?? "failed"})` : "Last poll: none yet");
259
281
  lines.push(`Screenshots of public websites: ${!config.web ? "not installed" : status?.web?.ok ? "on" : `off (${status?.web?.reason ?? "not verified yet"})`}`);
282
+ if (config.web && config.acceptColocatedWeb)
283
+ lines.push(` Accepted: ${COLOCATED_ACCEPTED_NOTE}`);
284
+ lines.push(RELEASE_KEYS.length > 0
285
+ ? `Release signatures: required (${RELEASE_KEYS.length} trusted key${RELEASE_KEYS.length === 1 ? "" : "s"})`
286
+ : "Release signatures: not checked (this build trusts no release key)");
260
287
  const updater = readJson(sys, layout.updaterStatusFile);
261
288
  if (updater) {
262
289
  lines.push(`Updater: ${updater.result} at ${updater.checkedUtc}${updater.wanted ? `, Parhelia names ${updater.wanted}` : ""}`);
@@ -9,12 +9,15 @@ export declare const UNIT: {
9
9
  readonly browserHost: "parhelia-capture-browser-host.service";
10
10
  readonly updater: "parhelia-capture-updater.service";
11
11
  readonly updaterTimer: "parhelia-capture-updater.timer";
12
+ /** "Update now": the updater's long poll for an administrator's update request (privileged, like the updater). */
13
+ readonly updateWatch: "parhelia-capture-update-watch.service";
12
14
  };
13
15
  export declare const TASK: {
14
16
  readonly folder: "\\Parhelia Capture\\";
15
17
  readonly worker: "Worker";
16
18
  readonly browserHost: "Browser host";
17
19
  readonly updater: "Updater";
20
+ readonly updateWatch: "Update watch";
18
21
  };
19
22
  export type Layout = {
20
23
  platform: "linux" | "win32";
@@ -29,6 +32,9 @@ export type Layout = {
29
32
  statusFile: string;
30
33
  /** The updater's last run (wanted version, outcome, problems), read by the worker into its poll report. */
31
34
  updaterStatusFile: string;
35
+ /** "Update now": held by the one update that runs (the timer's check, the update watch, or one by hand); beside the code, so
36
+ * only root (Linux) or Administrators and SYSTEM (Windows) can take it. */
37
+ updateLockFile: string;
32
38
  browserStateDir: string;
33
39
  socketDir: string;
34
40
  unitDir: string;
@@ -47,6 +53,9 @@ export type InstalledConfig = {
47
53
  web: boolean;
48
54
  probeUrl?: string;
49
55
  publicUrl?: string;
56
+ /** Windows: the administrator accepted `public-web` on the machine that runs Parhelia (`install --accept-colocated-web`):
57
+ * loopback is unfiltered there, so only the egress proxy keeps a page from Parhelia. The worker reports it as a problem. */
58
+ acceptColocatedWeb?: boolean;
50
59
  socketDir: string;
51
60
  /** The `current` link: each process reads its browser from `<installDir>/install.json`. */
52
61
  installDir: string;