



























@@ -62,7 +62,11 @@ import {
6262validateCliArgs,
6363waitForGatewayReady,
6464} from "../../scripts/e2e/kitchen-sink-rpc-walk.mjs";
65-import { resolveWindowsTaskkillPath } from "../../scripts/lib/windows-taskkill.mjs";
65+import {
66+resolveWindowsPowerShellPath,
67+resolveWindowsSystem32Path,
68+resolveWindowsTaskkillPath,
69+} from "../../scripts/lib/windows-taskkill.mjs";
6670import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
67716872const posixIt = process.platform === "win32" ? it.skip : it;
@@ -71,6 +75,14 @@ function expectedTaskkillPath(): string {
7175return resolveWindowsTaskkillPath();
7276}
737778+function expectedWindowsSystem32Path(executableName: string): string {
79+return resolveWindowsSystem32Path(executableName);
80+}
81+82+function expectedPowerShellPath(): string {
83+return resolveWindowsPowerShellPath();
84+}
85+7486afterEach(() => {
7587vi.restoreAllMocks();
7688vi.useRealTimers();
@@ -1694,6 +1706,15 @@ describe("kitchen-sink RPC health/status assertions", () => {
16941706});
1695170716961708describe("kitchen-sink RPC process sampling", () => {
1709+it("rejects unsafe Windows System32 executable names", () => {
1710+expect(() => resolveWindowsSystem32Path("..\\netstat.exe")).toThrow(
1711+/Invalid Windows System32 executable name/u,
1712+);
1713+expect(() => resolveWindowsSystem32Path("netstat")).toThrow(
1714+/Invalid Windows System32 executable name/u,
1715+);
1716+});
1717+16971718it("samples RSS on Windows instead of silently disabling the resource guard", async () => {
16981719const calls: Array<{ command: string; args: string[] }> = [];
16991720const sample = await sampleProcess(1234, {
@@ -1711,7 +1732,7 @@ describe("kitchen-sink RPC process sampling", () => {
17111732processId: 5678,
17121733rssMiB: 256,
17131734});
1714-expect(calls[0]?.command).toBe("powershell.exe");
1735+expect(calls[0]?.command).toBe(expectedPowerShellPath());
17151736expect(calls[0]?.args.join(" ")).toContain("$rootPid = 1234");
17161737expect(calls[0]?.args.join(" ")).toContain("ParentProcessId");
17171738});
@@ -1743,22 +1764,18 @@ describe("kitchen-sink RPC process sampling", () => {
17431764expect(command).toContain("Sort-Object WorkingSet64 -Descending");
17441765});
174517661746-it("falls back to the legacy powershell command name on Windows", async () => {
1767+it("does not fall back to a PATH-resolved powershell command on Windows", async () => {
17471768const commands: string[] = [];
17481769const sample = await sampleProcess(1234, {
17491770platform: "win32",
17501771runCommand: async (command: string) => {
17511772commands.push(command);
1752-if (command === "powershell.exe") {
1753-throw new Error("missing powershell.exe");
1754-}
1755-return { stdout: `${96 * 1024 * 1024} 0 1234`, stderr: "" };
1773+throw new Error("trusted powershell unavailable");
17561774},
17571775});
175817761759-expect(commands).toEqual(["powershell.exe", "powershell"]);
1760-expect(sample?.rssMiB).toBe(96);
1761-expect(sample?.aggregateRssMiB).toBe(96);
1777+expect(commands).toEqual([expectedPowerShellPath()]);
1778+expect(sample).toBeNull();
17621779});
1763178017641781it("does not truncate malformed Windows PowerShell CPU or id samples", async () => {
@@ -1841,7 +1858,7 @@ describe("kitchen-sink RPC process sampling", () => {
18411858const sample = await sampleWindowsProcessByPort(19675, {
18421859runCommand: async (command: string, args: string[]) => {
18431860calls.push({ command, args });
1844-if (command === "netstat.exe") {
1861+if (command === expectedWindowsSystem32Path("netstat.exe")) {
18451862return {
18461863stdout: [
18471864" Proto Local Address Foreign Address State PID",
@@ -1852,7 +1869,7 @@ describe("kitchen-sink RPC process sampling", () => {
18521869stderr: "",
18531870};
18541871}
1855-if (command === "powershell.exe") {
1872+if (command === expectedPowerShellPath()) {
18561873return { stdout: `${384 * 1024 * 1024} 2.25 6789 ${512 * 1024 * 1024}`, stderr: "" };
18571874}
18581875throw new Error(`unexpected command ${command}`);
@@ -1867,9 +1884,9 @@ describe("kitchen-sink RPC process sampling", () => {
18671884rssMiB: 384,
18681885});
18691886expect(calls).toEqual([
1870-{ command: "netstat.exe", args: ["-ano", "-p", "tcp"] },
1887+{ command: expectedWindowsSystem32Path("netstat.exe"), args: ["-ano", "-p", "tcp"] },
18711888{
1872-command: "powershell.exe",
1889+command: expectedPowerShellPath(),
18731890args: expect.arrayContaining(["-Command", expect.stringContaining("$rootPid = 6789")]),
18741891},
18751892]);
@@ -1880,7 +1897,7 @@ describe("kitchen-sink RPC process sampling", () => {
18801897const sample = await sampleWindowsProcessByPort(19675, {
18811898runCommand: async (command: string) => {
18821899calls.push(command);
1883-if (command === "netstat.exe") {
1900+if (command === expectedWindowsSystem32Path("netstat.exe")) {
18841901return {
18851902stdout: [
18861903" Proto Local Address Foreign Address State PID",
@@ -1889,10 +1906,10 @@ describe("kitchen-sink RPC process sampling", () => {
18891906stderr: "",
18901907};
18911908}
1892-if (command === "powershell.exe" || command === "powershell") {
1909+if (command === expectedPowerShellPath()) {
18931910throw new Error("powershell unavailable");
18941911}
1895-if (command === "tasklist.exe") {
1912+if (command === expectedWindowsSystem32Path("tasklist.exe")) {
18961913return {
18971914stdout: '"node.exe","6789","Console","1","262,144 K"',
18981915stderr: "",
@@ -1908,13 +1925,17 @@ describe("kitchen-sink RPC process sampling", () => {
19081925processId: 6789,
19091926rssMiB: 256,
19101927});
1911-expect(calls).toEqual(["netstat.exe", "powershell.exe", "powershell", "tasklist.exe"]);
1928+expect(calls).toEqual([
1929+expectedWindowsSystem32Path("netstat.exe"),
1930+expectedPowerShellPath(),
1931+expectedWindowsSystem32Path("tasklist.exe"),
1932+]);
19121933});
1913193419141935it("falls back to the known Windows pid when tasklist reports malformed pid text", async () => {
19151936const sample = await sampleWindowsProcessByPort(19675, {
19161937runCommand: async (command: string) => {
1917-if (command === "netstat.exe") {
1938+if (command === expectedWindowsSystem32Path("netstat.exe")) {
19181939return {
19191940stdout: [
19201941" Proto Local Address Foreign Address State PID",
@@ -1923,10 +1944,10 @@ describe("kitchen-sink RPC process sampling", () => {
19231944stderr: "",
19241945};
19251946}
1926-if (command === "powershell.exe" || command === "powershell") {
1947+if (command === expectedPowerShellPath()) {
19271948throw new Error("powershell unavailable");
19281949}
1929-if (command === "tasklist.exe") {
1950+if (command === expectedWindowsSystem32Path("tasklist.exe")) {
19301951return {
19311952stdout: '"node.exe","9999x","Console","1","262,144 K"',
19321953stderr: "",
@@ -1947,7 +1968,7 @@ describe("kitchen-sink RPC process sampling", () => {
19471968it("rejects malformed tasklist RSS instead of stripping digits", async () => {
19481969const sample = await sampleWindowsProcessByPort(19675, {
19491970runCommand: async (command: string) => {
1950-if (command === "netstat.exe") {
1971+if (command === expectedWindowsSystem32Path("netstat.exe")) {
19511972return {
19521973stdout: [
19531974" Proto Local Address Foreign Address State PID",
@@ -1956,10 +1977,10 @@ describe("kitchen-sink RPC process sampling", () => {
19561977stderr: "",
19571978};
19581979}
1959-if (command === "powershell.exe" || command === "powershell") {
1980+if (command === expectedPowerShellPath()) {
19601981throw new Error("powershell unavailable");
19611982}
1962-if (command === "tasklist.exe") {
1983+if (command === expectedWindowsSystem32Path("tasklist.exe")) {
19631984return {
19641985stdout: '"node.exe","6789","Console","1","262x144 K"',
19651986stderr: "",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。