Skip to content

Commit c4eb4d5

Browse files
committed
fix(security): bound scanner match evidence
1 parent 3ed4bd6 commit c4eb4d5

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Docs: https://docs.openclaw.ai
5656

5757
### Fixes
5858

59-
- **Plugin security scan coverage:** report every matching executable call in a file instead of stopping after the first, preventing later process-execution sites from hiding behind an already-reviewed finding.
6059
- **Control UI dynamic deep links:** reuse the initial route loader result when publishing real agent, session, dashboard, Workboard, Memory, and Plugins paths, avoiding redundant route-loader work during startup. Thanks @shakkernerd.
6160
- **Linux gateway service ownership:** refuse user-scope systemd publication and activation when the same gateway unit name is already owned or cannot be verified in the system scope, including `--force`, with actionable recovery guidance instead of creating restart-looping dual managers. Fixes #116129.
6261
- **macOS remote tunnel lifecycle:** prevent cancelled or superseded restart backoffs from recreating SSH tunnels, and join a tunnel create that another caller started while the actor was suspended.

‎src/skills/security/scanner.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ spawn("node", ["second.js"]); execFile("node", ["third.js"]);
163163
expect(findings.map((finding) => finding.line)).toEqual([3, 4, 4]);
164164
});
165165

166+
it("bounds dense line-rule findings and reports truncation", () => {
167+
const source = [
168+
`import { spawn } from "node:child_process";`,
169+
...Array.from({ length: 40 }, (_, index) => `spawn("node", ["${index}.js"]);`),
170+
].join("\n");
171+
172+
const findings = scanSource(source, "plugin.ts").filter((candidate) =>
173+
candidate.ruleId.startsWith("dangerous-exec"),
174+
);
175+
176+
expect(findings).toHaveLength(33);
177+
expect(findings.slice(0, -1).every((finding) => finding.ruleId === "dangerous-exec")).toBe(
178+
true,
179+
);
180+
expect(findings.at(-1)).toMatchObject({
181+
ruleId: "dangerous-exec-truncated",
182+
severity: "critical",
183+
line: 41,
184+
message: "8 additional dangerous-exec matches omitted after 32 findings",
185+
evidence: "[8 additional matches omitted after 32 findings]",
186+
});
187+
});
188+
166189
it("keeps bounded evidence free of lone surrogates", () => {
167190
const source = `${"a".repeat(119)}😀 child_process.exec("echo unsafe")`;
168191
const finding = scanSource(source, "plugin.ts").find(

‎src/skills/security/scanner.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const SCANNABLE_EXTENSIONS = new Set([
5959

6060
const DEFAULT_MAX_SCAN_FILES = 500;
6161
const DEFAULT_MAX_FILE_BYTES = 1024 * 1024;
62+
const MAX_LINE_RULE_FINDINGS_PER_RULE = 32;
6263
const FILE_SCAN_CACHE_MAX = 5000;
6364
const DIR_ENTRY_CACHE_MAX = 5000;
6465
const TEST_DIRECTORY_NAMES = new Set(["__fixtures__", "__mocks__", "__tests__", "test", "tests"]);
@@ -400,6 +401,9 @@ export function scanSource(source: string, filePath: string): SkillScanFinding[]
400401
continue;
401402
}
402403

404+
let acceptedMatches = 0;
405+
let omittedMatches = 0;
406+
let lastOmittedLine: number | undefined;
403407
for (const [i, line] of lines.entries()) {
404408
const matches = line.matchAll(
405409
new RegExp(
@@ -420,8 +424,14 @@ export function scanSource(source: string, filePath: string): SkillScanFinding[]
420424
}
421425
}
422426

423-
// Every call is independently reviewable. Stopping after the first match
424-
// lets later execution sites hide behind an already-approved finding.
427+
if (acceptedMatches >= MAX_LINE_RULE_FINDINGS_PER_RULE) {
428+
omittedMatches += 1;
429+
lastOmittedLine = i + 1;
430+
continue;
431+
}
432+
433+
// Retain distinct calls up to the cap, then aggregate every remaining match.
434+
// This keeps hostile output bounded without hiding that later sites exist.
425435
findings.push({
426436
ruleId: rule.ruleId,
427437
severity: rule.severity,
@@ -430,8 +440,19 @@ export function scanSource(source: string, filePath: string): SkillScanFinding[]
430440
message: rule.message,
431441
evidence: formatScanEvidence(line),
432442
});
443+
acceptedMatches += 1;
433444
}
434445
}
446+
if (lastOmittedLine !== undefined) {
447+
findings.push({
448+
ruleId: `${rule.ruleId}-truncated`,
449+
severity: rule.severity,
450+
file: filePath,
451+
line: lastOmittedLine,
452+
message: `${omittedMatches} additional ${rule.ruleId} matches omitted after ${MAX_LINE_RULE_FINDINGS_PER_RULE} findings`,
453+
evidence: `[${omittedMatches} additional matches omitted after ${MAX_LINE_RULE_FINDINGS_PER_RULE} findings]`,
454+
});
455+
}
435456
}
436457

437458
// --- Source rules ---

0 commit comments

Comments
 (0)