From d08abd8ce424415d1c1f7eaac2fb9bc21c62e8a5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 6 Apr 2026 23:36:00 +0100 Subject: [PATCH] refactor: dedupe security audit record helper --- src/security/audit.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/security/audit.ts b/src/security/audit.ts index 75937f5660d..3445c4a0977 100644 --- a/src/security/audit.ts +++ b/src/security/audit.ts @@ -18,6 +18,7 @@ import { listRiskyConfiguredSafeBins } from "../infra/exec-safe-bin-semantics.js import { normalizeTrustedSafeBinDirs } from "../infra/exec-safe-bin-trust.js"; import { getActivePluginRegistry } from "../plugins/runtime.js"; import { DEFAULT_AGENT_ID } from "../routing/session-key.js"; +import { asNullableRecord } from "../shared/record-coerce.js"; import { collectDeepCodeSafetyFindings } from "./audit-deep-code-safety.js"; import { collectDeepProbeFindings } from "./audit-deep-probe-findings.js"; import { @@ -196,13 +197,6 @@ function normalizeAllowFromList(list: Array | undefined | null) return list.map((v) => String(v).trim()).filter(Boolean); } -function asRecord(value: unknown): Record | undefined { - if (!value || typeof value !== "object" || Array.isArray(value)) { - return undefined; - } - return value as Record; -} - function hasNonEmptyString(value: unknown): boolean { return typeof value === "string" && value.trim().length > 0; } @@ -1135,14 +1129,14 @@ export function collectExecRuntimeFindings(cfg: OpenClawConfig): SecurityAuditFi } function collectOpenExecSurfacePaths(cfg: OpenClawConfig): string[] { - const channels = asRecord(cfg.channels); + const channels = asNullableRecord(cfg.channels); if (!channels) { return []; } const hits = new Set(); const seen = new WeakSet(); const visit = (value: unknown, scope: string) => { - const record = asRecord(value); + const record = asNullableRecord(value); if (!record || seen.has(record)) { return; } @@ -1158,7 +1152,7 @@ function collectOpenExecSurfacePaths(cfg: OpenClawConfig): string[] { visit(nested, `${scope}.${key}`); continue; } - if (asRecord(nested)) { + if (asNullableRecord(nested)) { visit(nested, `${scope}.${key}`); } }