mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(plugins): make the permission-model child load from the real plugin path
The prod data dir is a symlink (server/data -> volume), so resolving the plugin
under it tripped the permission model, and Node's module-type lookup walked up
into the (denied) data dir. Fork the child from the plugin's realpath and drop a
{"type":"commonjs"} package.json at its root so resolution stops there — trek.db
and the secret files stay unreadable, verified against Koffi.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { fork, type ChildProcess } from 'node:child_process';
|
||||
import { resolveChildEntry, pluginCodeDir, pluginPermissionArgs } from '../paths';
|
||||
import { resolveChildEntry, pluginCodeDir, pluginRealCodeDir, pluginPermissionArgs, ensurePluginModuleType } from '../paths';
|
||||
import type { Envelope, RpcError, RpcRequest } from '../protocol/envelope';
|
||||
import type { PluginRpcHost } from '../host/rpc-host';
|
||||
|
||||
@@ -177,9 +177,13 @@ export class PluginSupervisor {
|
||||
const { entry, execArgv, forkCwd, jsMode } = resolveChildEntry();
|
||||
// Prod (compiled) children get the OS permission model — a real kernel-level
|
||||
// fs/child_process/native jail on top of the env scrub and RPC boundary.
|
||||
// Use the plugin's REAL path + ensure it has a package.json so the sandboxed
|
||||
// child can resolve its own module type without a broad read grant.
|
||||
const codeDir = jsMode ? pluginRealCodeDir(sup.id) : pluginCodeDir(sup.id);
|
||||
if (jsMode) ensurePluginModuleType(codeDir);
|
||||
const argv = jsMode ? [...execArgv, ...pluginPermissionArgs(sup.id)] : execArgv;
|
||||
const child = fork(entry, [sup.id, pluginCodeDir(sup.id)], {
|
||||
cwd: forkCwd ?? pluginCodeDir(sup.id),
|
||||
const child = fork(entry, [sup.id, codeDir], {
|
||||
cwd: forkCwd ?? codeDir,
|
||||
execArgv: argv,
|
||||
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
||||
// Whitelist env — nothing inherited. No JWT_SECRET, no DB creds, no PATH-leaked secrets.
|
||||
|
||||
Reference in New Issue
Block a user