mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 12:20:22 +00:00
fix(security): harden regex compilation for filters and redaction
This commit is contained in:
@@ -93,6 +93,15 @@ describe("redactSensitiveText", () => {
|
||||
expect(output).toBe("token=abcdef…ghij");
|
||||
});
|
||||
|
||||
it("ignores unsafe nested-repetition custom patterns", () => {
|
||||
const input = `${"a".repeat(28)}!`;
|
||||
const output = redactSensitiveText(input, {
|
||||
mode: "tools",
|
||||
patterns: ["(a+)+$"],
|
||||
});
|
||||
expect(output).toBe(input);
|
||||
});
|
||||
|
||||
it("skips redaction when mode is off", () => {
|
||||
const input = "OPENAI_API_KEY=sk-1234567890abcdef";
|
||||
const output = redactSensitiveText(input, {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { compileSafeRegex } from "../security/safe-regex.js";
|
||||
import { resolveNodeRequireFromMeta } from "./node-require.js";
|
||||
|
||||
const requireConfig = resolveNodeRequireFromMeta(import.meta.url);
|
||||
@@ -51,15 +52,11 @@ function parsePattern(raw: string): RegExp | null {
|
||||
return null;
|
||||
}
|
||||
const match = raw.match(/^\/(.+)\/([gimsuy]*)$/);
|
||||
try {
|
||||
if (match) {
|
||||
const flags = match[2].includes("g") ? match[2] : `${match[2]}g`;
|
||||
return new RegExp(match[1], flags);
|
||||
}
|
||||
return new RegExp(raw, "gi");
|
||||
} catch {
|
||||
return null;
|
||||
if (match) {
|
||||
const flags = match[2].includes("g") ? match[2] : `${match[2]}g`;
|
||||
return compileSafeRegex(match[1], flags);
|
||||
}
|
||||
return compileSafeRegex(raw, "gi");
|
||||
}
|
||||
|
||||
function resolvePatterns(value?: string[]): RegExp[] {
|
||||
|
||||
Reference in New Issue
Block a user