mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:01:23 +00:00
fix(security): harden regex compilation for filters and redaction
This commit is contained in:
@@ -309,6 +309,15 @@ describe("DiscordExecApprovalHandler.shouldHandle", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects unsafe nested-repetition regex in session filter", () => {
|
||||
const handler = createHandler({
|
||||
enabled: true,
|
||||
approvers: ["123"],
|
||||
sessionFilter: ["(a+)+$"],
|
||||
});
|
||||
expect(handler.shouldHandle(createRequest({ sessionKey: `${"a".repeat(28)}!` }))).toBe(false);
|
||||
});
|
||||
|
||||
it("filters by discord account when session store includes account", () => {
|
||||
writeStore({
|
||||
"agent:test-agent:discord:channel:999888777": {
|
||||
|
||||
@@ -24,6 +24,7 @@ import type {
|
||||
import { logDebug, logError } from "../../logger.js";
|
||||
import { normalizeAccountId, resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import { compileSafeRegex } from "../../security/safe-regex.js";
|
||||
import {
|
||||
GATEWAY_CLIENT_MODES,
|
||||
GATEWAY_CLIENT_NAMES,
|
||||
@@ -364,11 +365,11 @@ export class DiscordExecApprovalHandler {
|
||||
return false;
|
||||
}
|
||||
const matches = config.sessionFilter.some((p) => {
|
||||
try {
|
||||
return session.includes(p) || new RegExp(p).test(session);
|
||||
} catch {
|
||||
return session.includes(p);
|
||||
if (session.includes(p)) {
|
||||
return true;
|
||||
}
|
||||
const regex = compileSafeRegex(p);
|
||||
return regex ? regex.test(session) : false;
|
||||
});
|
||||
if (!matches) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user