mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-18 07:58:27 +00:00
fix(cli): trust only an exact list of valueless runtime flags in pid identity
Second CodeRabbit follow-up to I5 on #19191: isRuntimeFlag treated every --trace-*, --experimental-*, --no-*, --enable-* and --expose-* option as valueless, but Node takes a separate value for some of them. With `node --trace-event-file-pattern /tmp/omniroute /srv/other/server.js` the option's value was read as the script and the pid classified as ours (same for --trace-event-categories and --experimental-sea-config). The prefix rules are gone. A bare runtime option is skipped only when it is on an exact allowlist of documented valueless flags (--no-warnings and --enable-source-maps, which OmniRoute and common launchers use, a few deprecation/trace-warning flags, --expose-gc, bun --smol); --opt=value forms and the known value options (--import, --preload, --require, ...) are still skipped. Any other bare option makes the command line "unknown", so it is never signalled. OmniRoute's own spawns (--dns-result-order=, --max-old-space-size=, --import/--preload <path>, --no-warnings) stay ours.
This commit is contained in:
@@ -123,28 +123,23 @@ const RUNTIME_VALUE_OPTIONS = new Set([
|
||||
"--title",
|
||||
"--input-type",
|
||||
]);
|
||||
// Bare runtime options known to take no value. Any other bare option may take the next token as
|
||||
// its value (`--watch-path /x`), so what follows it cannot be proven to be the script.
|
||||
const RUNTIME_FLAG_PREFIXES = ["--no-", "--experimental-", "--enable-", "--expose-", "--trace-"];
|
||||
// Bare runtime options known to take no separate value. Exact names only: no prefix is safe
|
||||
// (--trace-event-file-pattern, --experimental-sea-config and --inspect-port all take one), and
|
||||
// any other bare option may take the next token as its value, so what follows it cannot be
|
||||
// proven to be the script. `--opt=value` forms carry their value and are always skipped.
|
||||
// OmniRoute spawns itself with --dns-result-order=, --max-old-space-size= (both `=` forms),
|
||||
// --import / --preload <path> (RUNTIME_VALUE_OPTIONS) and --no-warnings (plugins/loader.ts).
|
||||
const RUNTIME_FLAGS = new Set([
|
||||
"--inspect",
|
||||
"--inspect-brk",
|
||||
"--inspect-wait",
|
||||
"--watch",
|
||||
"--no-warnings",
|
||||
"--enable-source-maps",
|
||||
"--no-deprecation",
|
||||
"--trace-warnings",
|
||||
"--trace-deprecation",
|
||||
"--trace-uncaught",
|
||||
"--throw-deprecation",
|
||||
"--pending-deprecation",
|
||||
"--preserve-symlinks",
|
||||
"--preserve-symlinks-main",
|
||||
"--abort-on-uncaught-exception",
|
||||
"--frozen-intrinsics",
|
||||
"--zero-fill-buffers",
|
||||
"--use-openssl-ca",
|
||||
"--use-bundled-ca",
|
||||
"--permission",
|
||||
"--expose-gc",
|
||||
"--smol",
|
||||
]);
|
||||
const isRuntimeFlag = (arg) =>
|
||||
RUNTIME_FLAGS.has(arg) || RUNTIME_FLAG_PREFIXES.some((prefix) => arg.startsWith(prefix));
|
||||
const RUNTIME_INLINE_CODE = /^(?:-e|-p|-pe|-ep|--eval|--print)(?:=|$)/;
|
||||
|
||||
// macOS ps and Windows CommandLine give one string. Double quotes group an argument.
|
||||
@@ -198,7 +193,7 @@ function commandIdentity(rawTokens, joinable, isFile) {
|
||||
i++;
|
||||
} else if (arg.startsWith("-")) {
|
||||
if (RUNTIME_VALUE_OPTIONS.has(arg)) i++;
|
||||
else if (!arg.includes("=") && !isRuntimeFlag(arg)) return "unknown";
|
||||
else if (!arg.includes("=") && !RUNTIME_FLAGS.has(arg)) return "unknown";
|
||||
continue;
|
||||
}
|
||||
const script = joinPathTokens(tokens, i, (v) => SCRIPT_END.test(v), joinable, isFile);
|
||||
|
||||
@@ -145,16 +145,33 @@ test("classifyPidIdentity: an ambiguous re-join of unquoted tokens never proves
|
||||
// after a bare option the runtime does not know as a flag, the next token may be its value
|
||||
// rather than the script. Even with an exact argv that cannot be proven either way.
|
||||
test("classifyPidIdentity: a token after an unrecognised bare runtime option is not the script", () => {
|
||||
// No prefix makes an option valueless: --trace-*, --experimental-*, --no-* and --inspect-*
|
||||
// all have members that take a separate value. Only an exact allowlist is trusted.
|
||||
for (const cmdline of [
|
||||
"node --watch-path /home/me/omniroute /srv/other/server.js",
|
||||
"node --report-dir /var/omniroute /srv/other/server.js",
|
||||
"node --trace-event-file-pattern /tmp/omniroute /srv/other/server.js",
|
||||
"node --trace-event-categories omniroute /srv/other/server.js",
|
||||
"node --experimental-sea-config /tmp/omniroute.json /srv/other/server.js",
|
||||
"node --inspect-port /tmp/omniroute /srv/other/server.js",
|
||||
"node --no-warnings --trace-event-file-pattern /tmp/omniroute /srv/other/server.js",
|
||||
"bun --smol --config /tmp/omniroute.toml /srv/other/server.js",
|
||||
]) {
|
||||
assert.equal(classifyPidIdentity(1, linux(cmdline)), "unknown", cmdline);
|
||||
}
|
||||
// A known value option still has its value skipped, so the foreign script is what is judged.
|
||||
assert.equal(
|
||||
classifyPidIdentity(1, linux("node --experimental-loader /tmp/omniroute.mjs /srv/x.js")),
|
||||
"foreign"
|
||||
);
|
||||
for (const cmdline of [
|
||||
"node --no-warnings /opt/omniroute/app/server.js",
|
||||
"node --inspect --enable-source-maps /opt/omniroute/app/server.js",
|
||||
"node --experimental-vm-modules /opt/omniroute/app/server.js",
|
||||
"node --no-warnings --enable-source-maps /opt/omniroute/app/server.js",
|
||||
// How OmniRoute spawns itself (scripts/build/runtime-env.mjs, serve.mjs, plugins/loader.ts).
|
||||
"node --dns-result-order=ipv4first --max-old-space-size=512 /opt/omniroute/app/server.js",
|
||||
"node --import tsx/esm /opt/omniroute/bin/omniroute.mjs serve",
|
||||
"bun --preload /opt/omniroute/bin/polyfill.mjs /opt/omniroute/app/server.js",
|
||||
"bun --smol /opt/omniroute/app/server.js",
|
||||
]) {
|
||||
assert.equal(classifyPidIdentity(1, linux(cmdline)), "ours", cmdline);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user