mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 22:09:57 +00:00
Infra: tighten exec allowlist glob matching (#43798)
* Infra: tighten exec allowlist glob matching * Changelog: note GHSA-f8r2 exec allowlist fix
This commit is contained in:
14
src/infra/exec-allowlist-pattern.test.ts
Normal file
14
src/infra/exec-allowlist-pattern.test.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { matchesExecAllowlistPattern } from "./exec-allowlist-pattern.js";
|
||||
|
||||
describe("matchesExecAllowlistPattern", () => {
|
||||
it("does not let ? cross path separators", () => {
|
||||
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/a/b")).toBe(false);
|
||||
expect(matchesExecAllowlistPattern("/tmp/a?b", "/tmp/acb")).toBe(true);
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")("preserves case sensitivity on POSIX", () => {
|
||||
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/allowed-tool")).toBe(false);
|
||||
expect(matchesExecAllowlistPattern("/tmp/Allowed-Tool", "/tmp/Allowed-Tool")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -9,7 +9,7 @@ function normalizeMatchTarget(value: string): string {
|
||||
const stripped = value.replace(/^\\\\[?.]\\/, "");
|
||||
return stripped.replace(/\\/g, "/").toLowerCase();
|
||||
}
|
||||
return value.replace(/\\\\/g, "/").toLowerCase();
|
||||
return value.replace(/\\\\/g, "/");
|
||||
}
|
||||
|
||||
function tryRealpath(value: string): string | null {
|
||||
@@ -46,7 +46,7 @@ function compileGlobRegex(pattern: string): RegExp {
|
||||
continue;
|
||||
}
|
||||
if (ch === "?") {
|
||||
regex += ".";
|
||||
regex += "[^/]";
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ function compileGlobRegex(pattern: string): RegExp {
|
||||
}
|
||||
regex += "$";
|
||||
|
||||
const compiled = new RegExp(regex, "i");
|
||||
const compiled = new RegExp(regex, process.platform === "win32" ? "i" : "");
|
||||
if (globRegexCache.size >= GLOB_REGEX_CACHE_LIMIT) {
|
||||
globRegexCache.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user