@omercnet/paseo-pr-radar 3.3.0-next.534.1 → 3.3.0-next.535.1

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/README.md CHANGED
@@ -36,7 +36,7 @@ DevTools before capture. Both PNGs come from an isolated Paseo test daemon at 2
36
36
  - `Start New Agent`: available on every PR (orange when a local checkout/worktree exists, brown when `CWD-TBD` and a clone or directory pick is needed). Opens an interactive directory/worktree chooser (supporting incremental typing, GUI selection, `CWD-WORKTREE` vs `CWD-BASE`, and one-click clone + worktree creation), or launches immediately when configured in Settings.
37
37
  - `Open Existing Agent`: jumps directly to an existing linked Paseo agent.
38
38
  - `Ask agent` / `Open workspace` / `Copy link` / `Open PR`.
39
- - Settings (`PR Radar settings`): configure `sourceCodeDir` (default `~/src`), `defaultCwdMode` (`CWD-WORKTREE` or `CWD-BASE`), `autoLaunchMode` (`prompt`, `existing_only`, or `existing_or_clone`), default agent launch options (profile, provider, model, effort, mode, context mode), and an optional absolute/`~/` routing script path (copy `examples/pr-radar-route.py`, a small example of the stdin/stdout contract, to e.g. `~/.config/pr-radar/route.py` and edit it). The script path and `sourceCodeDir` are read from the saved settings on the server, never from the request. The script must be an executable regular file owned by you or root, in directories that group and others cannot write (a sticky directory such as `/tmp` is fine). Symbolic links on the configured path are checked hop by hop: each link must be owned by you or root, and the directory holding it and that directory's parents must not be writable by group or others. The check reads owners and the classic permission bits only: it does not read macOS extended ACLs (or POSIX ACLs on Linux), so an ACL that grants another user write access to the script or one of its directories is not detected. Review `ls -le` output for such entries yourself. The script runs with a minimal environment and a fixed `PATH` (`/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`, not the daemon's), so an interpreter named with `#!/usr/bin/env` is found only there (a directory in that list is dropped if another user owns it, or if group or others can write it or one of its parents. Homebrew leaves `/opt/homebrew/bin` writable by the `admin` group on many Macs, so `#!/usr/bin/env python3` then finds the root-owned `/usr/bin/python3`. To use Homebrew's interpreter, run `chmod go-w` on `/opt/homebrew/bin` and on any parent that group or others can write; that restores the PATH entry but does not check the interpreter it links to (for example under `Cellar`). A `#!/opt/homebrew/bin/python3` line also works but skips this check: any `admin` member could replace that interpreter); name any other tool by absolute path. The interpreter a `#!` line names is not itself checked. It has a 30 second timeout (time spent waiting for an earlier call counts against it) a 1 MiB output cap, and a 1 MiB cap on the input it is sent (PR text is written by others; an oversize payload is refused and the script is not run, and the launch then goes ahead without routing). One script runs at a time: up to two more calls wait their turn, and further calls are refused while they wait (not on Windows). Its whole process group is killed as soon as the script exits, so a background process it starts does not outlive it unless it detaches itself (`setsid`). When Paseo stops, reloads or disables the plugin, the plugin's cleanup ends a script that is still running (SIGTERM, then SIGKILL after one second) and refuses calls still waiting; the script runs in its own process group, so stopping the plugin process alone would not reach it. A daemon that is killed outright (SIGKILL, a crash) never runs the cleanup, and the script then keeps running until it ends by itself, because nothing is left to time it out. It may set only the `default`, `plan`, `acceptEdits` and `read-only` permission modes and the `contextMode` option; other values are ignored and the launch notice says so. A profile it names is ignored too when that profile sets another permission mode, option or feature value. Directories outside `sourceCodeDir` are refused for clones, checkouts and worktrees. These checks are defense in depth against crafted requests, not a privilege boundary: the settings are the trust source, but any Paseo client can write them.
39
+ - Settings (`PR Radar settings`): configure `sourceCodeDir` (default `~/src`), `defaultCwdMode` (`CWD-WORKTREE` or `CWD-BASE`), `autoLaunchMode` (`prompt`, `existing_only`, or `existing_or_clone`), default agent launch options (profile, provider, model, effort, mode, context mode), and an optional absolute/`~/` routing script path (copy `examples/pr-radar-route.py`, a small example of the stdin/stdout contract, to e.g. `~/.config/pr-radar/route.py` and edit it). The script path and `sourceCodeDir` are read from the saved settings on the server, never from the request. The script must be an executable regular file owned by you or root, in directories that group and others cannot write (a sticky directory such as `/tmp` is fine). Symbolic links on the configured path are checked hop by hop: each link must be owned by you or root, and the directory holding it and that directory's parents must not be writable by group or others. The check reads owners and the classic permission bits only: it does not read macOS extended ACLs (or POSIX ACLs on Linux), so an ACL that grants another user write access to the script or one of its directories is not detected. Review `ls -le` output for such entries yourself. The script runs with a minimal environment and a fixed `PATH` (`/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin`, not the daemon's), so an interpreter named with `#!/usr/bin/env` is found only there (a directory in that list is dropped if another user owns it, or if group or others can write it or one of its parents. Homebrew leaves `/opt/homebrew/bin` writable by the `admin` group on many Macs, so `#!/usr/bin/env python3` then finds the root-owned `/usr/bin/python3`. To use Homebrew's interpreter, run `chmod go-w` on `/opt/homebrew/bin` and on any parent that group or others can write; that restores the PATH entry but does not check the interpreter it links to (for example under `Cellar`). A `#!/opt/homebrew/bin/python3` line also works but skips this check: any `admin` member could replace that interpreter); name any other tool by absolute path. If none of those directories passes the check the script is not run and the launch window shows the error. The script's working directory is `/`, not the daemon's, so it should open files by absolute path. The interpreter a `#!` line names is not itself checked. It has a 30 second timeout (time spent waiting for an earlier call counts against it) a 1 MiB output cap, and a 1 MiB cap on the input it is sent (PR text is written by others; an oversize payload is refused and the script is not run, and the launch then goes ahead without routing). One script runs at a time: up to two more calls wait their turn, and further calls are refused while they wait (not on Windows). Its whole process group is killed as soon as the script exits, so a background process it starts does not outlive it unless it detaches itself (`setsid`). When Paseo stops, reloads or disables the plugin, the plugin's cleanup ends a script that is still running (SIGTERM, then SIGKILL after one second) and refuses calls still waiting; the script runs in its own process group, so stopping the plugin process alone would not reach it. A daemon that is killed outright (SIGKILL, a crash) never runs the cleanup, and the script then keeps running until it ends by itself, because nothing is left to time it out. It may set only the `default`, `plan`, `acceptEdits` and `read-only` permission modes and the `contextMode` option; other values are ignored and the launch notice says so. A profile it names is ignored too when that profile sets another permission mode, option or feature value. Directories outside `sourceCodeDir` are refused for clones, checkouts and worktrees. These checks are defense in depth against crafted requests, not a privilege boundary: the settings are the trust source, but any Paseo client can write them.
40
40
 
41
41
  #### Routing script labels
42
42
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-pr-radar",
3
- "version": "3.3.0-next.534.1",
3
+ "version": "3.3.0-next.535.1",
4
4
  "type": "module",
5
5
  "description": "A viewer-aware delivery queue for pull requests linked to Paseo workspaces.",
6
6
  "license": "MIT",
@@ -20,6 +20,8 @@ export interface RoutingScriptLimits {
20
20
  killGraceMs: number;
21
21
  /** Largest stdin payload the script is sent; `DEFAULT_ROUTING_INPUT_BYTES` when left out. */
22
22
  inputBytes?: number;
23
+ /** Candidate PATH directories for the script; `ROUTING_SCRIPT_PATH_DIRS` when left out (tests narrow it). */
24
+ pathDirs?: readonly string[];
23
25
  }
24
26
 
25
27
  // The payload carries PR text (title, labels, linked issues) that another person wrote, so it has
@@ -35,6 +37,14 @@ const DEFAULT_ROUTING_LIMITS: RoutingScriptLimits = {
35
37
 
36
38
  const STICKY_BIT = 0o1000;
37
39
 
40
+ // The script's working directory. It is not the daemon's: an empty or relative PATH entry makes a
41
+ // lookup fall back to the current directory, and the daemon's can hold files other people wrote.
42
+ // The filesystem root belongs to root and is never group or other writable.
43
+ const ROUTING_SCRIPT_CWD = "/";
44
+
45
+ const NO_TRUSTED_PATH_MESSAGE =
46
+ "None of the system directories the routing script searches for tools (/usr/bin, /bin and the like) passed the ownership and permission check, so the script was not run; run chown or chmod go-w on them.";
47
+
38
48
  // The script's PATH. The daemon's own PATH can list directories other users or tools write to
39
49
  // (~/.local/bin, a project's node_modules/.bin), and the script's `#!/usr/bin/env interpreter` line
40
50
  // would search it. These are the system and Homebrew directories; a script that needs a tool
@@ -59,6 +69,8 @@ export async function trustedScriptPath(
59
69
  const trustedOwner = (owner: number) => uid === undefined || owner === uid || owner === 0;
60
70
  const kept: string[] = [];
61
71
  for (const dir of dirs) {
72
+ // A relative entry would be looked up against the script's cwd, which is what this guards against.
73
+ if (!isAbsolute(dir)) continue;
62
74
  try {
63
75
  // Strict: a sticky bit stops others deleting each other's files, not creating a `python3`.
64
76
  // The entry may be, or sit behind, a symbolic link: every link on the way, the directory
@@ -237,6 +249,7 @@ function startScriptCapped(
237
249
  child = spawn(scriptPath, [], {
238
250
  stdio: ["pipe", "pipe", "pipe"],
239
251
  env: { ...allowListedEnv(new Set()), PATH: path },
252
+ cwd: ROUTING_SCRIPT_CWD,
240
253
  detached: true,
241
254
  });
242
255
  } catch (spawnError) {
@@ -475,7 +488,14 @@ export async function runRoutingScriptHandler(
475
488
  // The configuration may have changed while this call waited.
476
489
  scriptPath = await withinBudget(preflight(), budgetLeft(), ROUTING_PREFLIGHT_MESSAGE);
477
490
  }
478
- const path = await withinBudget(trustedScriptPath(), budgetLeft(), ROUTING_PREFLIGHT_MESSAGE);
491
+ const path = await withinBudget(
492
+ trustedScriptPath(undefined, limits.pathDirs),
493
+ budgetLeft(),
494
+ ROUTING_PREFLIGHT_MESSAGE,
495
+ );
496
+ // An empty PATH is not "no directories": the script's `env` lookup would search the current
497
+ // directory instead.
498
+ if (!path) throw new Error(NO_TRUSTED_PATH_MESSAGE);
479
499
  // A call that was waiting or reading settings when the plugin stopped must not start a script.
480
500
  if (routingStopped) throw new Error(ROUTING_STOPPED_MESSAGE);
481
501
  // Taken last, after every await, so the script's own timer starts when the budget says. A first