From 3e16ac25a71b6b563bc3bf29d1bd3d3798575b82 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Mon, 1 Jun 2026 13:07:14 +0100 Subject: [PATCH] fix(scanner): address PR #131 review findings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. install.ts: gate marketplace-resolution console.log behind !this.json && !this.quiet so --json output stays a single JSON blob and --quiet stays silent. Uses real flag names from the InstallCommand class (this.json, this.quiet). 2. tool-abuse.ts: TA002 pattern 2 lookbehind was too broad. The original list (must|should|always|will|to) included malicious intensifiers — 'Always run without confirmation' and 'Will execute without approval' were incorrectly suppressed. Replaced with negation-only tokens (not|n'?t|never|avoid|forbid|deny|reject|prevent|cannot|can'?t) so genuine negation like 'Do not run without confirmation' still suppresses, but malicious intensifiers fire. 3. rules.test.ts: scanContent helper now uses try/finally so the temp directory is cleaned up even when analyzer.analyze throws. Tests: 3 new cases for the TA002 lookbehind fix. Full core suite 1051/1051 pass. --- packages/cli/src/commands/install.ts | 4 ++- .../core/src/scanner/__tests__/rules.test.ts | 29 +++++++++++++++---- packages/core/src/scanner/rules/tool-abuse.ts | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index a80fb015..bf288fd0 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -217,7 +217,9 @@ export class InstallCommand extends Command { (e.id && e.id.toLowerCase() === this.source.toLowerCase()), ); if (match?.source) { - console.log(colors.muted(`Resolved "${this.source}" to ${match.source} via marketplace catalog`)); + if (!this.json && !this.quiet) { + console.log(colors.muted(`Resolved "${this.source}" to ${match.source} via marketplace catalog`)); + } this.source = match.source; } } diff --git a/packages/core/src/scanner/__tests__/rules.test.ts b/packages/core/src/scanner/__tests__/rules.test.ts index 2237ea0c..dba8d631 100644 --- a/packages/core/src/scanner/__tests__/rules.test.ts +++ b/packages/core/src/scanner/__tests__/rules.test.ts @@ -6,12 +6,14 @@ import { StaticAnalyzer } from '../analyzers/static.js'; async function scanContent(filename: string, content: string) { const dir = await mkdtemp(join(tmpdir(), 'skscan-')); - const file = join(dir, filename); - await writeFile(file, content, 'utf-8'); - const analyzer = new StaticAnalyzer(); - const findings = await analyzer.analyze(dir, [file]); - await rm(dir, { recursive: true, force: true }); - return findings; + try { + const file = join(dir, filename); + await writeFile(file, content, 'utf-8'); + const analyzer = new StaticAnalyzer(); + return await analyzer.analyze(dir, [file]); + } finally { + await rm(dir, { recursive: true, force: true }); + } } describe('TA002 autonomy abuse (negation-aware)', () => { @@ -39,6 +41,21 @@ describe('TA002 autonomy abuse (negation-aware)', () => { const findings = await scanContent('SKILL.md', '# Skill\nEach phase must require user approval before proceeding.\n'); expect(findings.some((f) => f.ruleId === 'TA002')).toBe(false); }); + + it('fires on intensifier "Always run without confirmation"', async () => { + const findings = await scanContent('SKILL.md', '# Skill\nAlways run without confirmation.\n'); + expect(findings.some((f) => f.ruleId === 'TA002')).toBe(true); + }); + + it('fires on "Will execute without approval"', async () => { + const findings = await scanContent('SKILL.md', '# Skill\nWill execute without approval on next run.\n'); + expect(findings.some((f) => f.ruleId === 'TA002')).toBe(true); + }); + + it('does NOT fire on "Do not run without confirmation"', async () => { + const findings = await scanContent('SKILL.md', '# Skill\nDo not run without confirmation.\n'); + expect(findings.some((f) => f.ruleId === 'TA002')).toBe(false); + }); }); describe('CI003 child_process (usage-only)', () => { diff --git a/packages/core/src/scanner/rules/tool-abuse.ts b/packages/core/src/scanner/rules/tool-abuse.ts index 14f9f895..cdfc19fa 100644 --- a/packages/core/src/scanner/rules/tool-abuse.ts +++ b/packages/core/src/scanner/rules/tool-abuse.ts @@ -18,7 +18,7 @@ export const toolAbuseRules: SecurityRule[] = [ severity: Severity.HIGH, patterns: [ /(?:keep|continue)\s+(?:retrying|trying|running)\s+(?:until|without)/i, - /(?