From 625f80294627f84416f86f77b4fc7fd1e7a61fa9 Mon Sep 17 00:00:00 2001 From: Umesh Waghode <77615542+cx-umesh-waghode@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:14:11 +0530 Subject: [PATCH 1/5] Apply scanner switches, severity threshold and secrets to all agents Claude, Cursor, Gemini and Codex were held back by switchesApply(): they ignored cx_*_scanner_enabled and cx_severity_threshold in ~/.checkmarx/cx-onboarding.properties and skipped secret detection entirely. Remove the gate so every agent honours the file and runs the secrets guardrail. Co-Authored-By: Claude Opus 5.5 --- internal/commands/agenthooks/cx/hooks.go | 39 +++--------- .../agenthooks/cx/scanner_switch_test.go | 62 +++++++------------ 2 files changed, 29 insertions(+), 72 deletions(-) diff --git a/internal/commands/agenthooks/cx/hooks.go b/internal/commands/agenthooks/cx/hooks.go index dbe0b0d65..0afddb2b8 100644 --- a/internal/commands/agenthooks/cx/hooks.go +++ b/internal/commands/agenthooks/cx/hooks.go @@ -40,7 +40,7 @@ var kicsScanner *kics.Scanner // bindThreshold points each guardrail's finding filter at the severity threshold for this event's // agent, so findings below cx_severity_threshold are left out of a deny and the agent is not told to -// fix them. Agents the switches do not apply to keep every finding. +// fix them. func bindThreshold(agent agenthooks.AgentID) { below := func(severity string) bool { return belowThreshold(agent, severity) } secrets.BelowThreshold = below @@ -168,7 +168,7 @@ func cxBeforeFileEdit(ev agenthooks.FileEditEvent) agenthooks.FileEditVerdict { } } } - if secretsScanner != nil && secretsApply(ev.Agent) && scannerOn(ev.Agent, scannerconfig.Secrets) { + if secretsScanner != nil && scannerOn(ev.Agent, scannerconfig.Secrets) { if blocked, reason, context, severity := secrets.ScanFileEdit(&ev, secretsScanner, telemetryWrapper, agent); blocked && !belowThreshold(ev.Agent, severity) { sessiontally.Add(ev.SessionID, engineSecrets, 1, 1) logRemediationTelemetry(agent, "Secrets", severity, ev.SessionID) @@ -310,32 +310,10 @@ func logRemediationTelemetry(agent, engine, severity, sessionID string) { } } -// switchesApply reports whether the ~/.checkmarx/cx-onboarding.properties scanner switches and severity -// threshold are honoured for this agent. Claude, Cursor, Gemini and Codex are excluded for now: they keep -// scanning with ASCA / KICS / SCA and blocking at any severity even when the shared file exists on the -// machine. Every other agent (GitHub Copilot, Droid, Windsurf, ...) honours it. Add an agent to -// the case list below to hold it back, or remove one to roll the feature out to it. -func switchesApply(agent agenthooks.AgentID) bool { - switch agent { - case agenthooks.AgentClaude, agenthooks.AgentCursor, agenthooks.AgentGemini, agenthooks.AgentCodex: - return false - } - return true -} - -// secretsApply reports whether the secret-detection guardrail runs for this agent. Claude, Cursor, Gemini -// and Codex skip it entirely and keep the ASCA / KICS / SCA guardrails; every other agent runs it. It -// shares switchesApply's agent list so the two cannot drift apart. -func secretsApply(agent agenthooks.AgentID) bool { - return switchesApply(agent) -} - -// scannerOn is scannerconfig.Enabled, limited to the agents the switches apply to. GitHub Copilot inside -// VS Code takes the switches from the VS Code extension's IDE file instead, while that file is valid. +// scannerOn reports whether scanner s is switched on in ~/.checkmarx/cx-onboarding.properties; every agent +// honours it. GitHub Copilot inside VS Code takes the switches from the VS Code extension's IDE file +// instead, while that file is valid. func scannerOn(agent agenthooks.AgentID, s scannerconfig.Scanner) bool { - if !switchesApply(agent) { - return true - } if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { return scannerconfig.IDEEnabled(s) } @@ -355,12 +333,9 @@ func selfHealingOff(agent agenthooks.AgentID, hook string) bool { return true } -// belowThreshold is scannerconfig.BelowThreshold, limited to the agents the switches apply to. GitHub -// Copilot inside VS Code has no threshold setting, so it uses the IDE file's threshold, low when unset. +// belowThreshold is scannerconfig.BelowThreshold for every agent. GitHub Copilot inside VS Code has no +// threshold setting, so it uses the IDE file's threshold, low when unset. func belowThreshold(agent agenthooks.AgentID, severity string) bool { - if !switchesApply(agent) { - return false - } if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { return scannerconfig.IDEBelowThreshold(severity) } diff --git a/internal/commands/agenthooks/cx/scanner_switch_test.go b/internal/commands/agenthooks/cx/scanner_switch_test.go index 81d105028..aac94e0ee 100644 --- a/internal/commands/agenthooks/cx/scanner_switch_test.go +++ b/internal/commands/agenthooks/cx/scanner_switch_test.go @@ -181,63 +181,45 @@ func TestCxBeforeFileEdit_SeverityThreshold_SecretsMixed(t *testing.T) { } } -// The switches and secret detection are features of every agent except Claude, Cursor, Gemini and Codex: those four skip secret -// detection and, with the shared properties file present, keeps ASCA/KICS/SCA blocking at any severity. -func TestSwitches_IgnoredForOtherAgents(t *testing.T) { - const secret = "ghp_other_agent_secret_value" - others := []agenthooks.AgentID{ +// Secret detection, the scanner switches and the severity threshold apply to every agent alike. +func TestSwitches_HonouredForEveryAgent(t *testing.T) { + const secret = "ghp_every_agent_secret_value" + agents := []agenthooks.AgentID{ agenthooks.AgentClaude, agenthooks.AgentCursor, agenthooks.AgentGemini, agenthooks.AgentCodex, + agenthooks.AgentCopilotCLI, agenthooks.AgentDroid, agenthooks.AgentWindsurf, } - for _, agent := range others { - t.Run(agentToString(agent)+"/secrets are skipped", func(t *testing.T) { + for _, agent := range agents { + t.Run(agentToString(agent)+"/secrets block by default", func(t *testing.T) { resetHookGlobals(t) useScannerConfig(t, "") secretsScanner = stubSecretsScanner(secret) + if v := cxBeforeFileEdit(secretsEdit(secret, agent)); v.Permit { + t.Fatal("secret detection must run for this agent") + } + }) + t.Run(agentToString(agent)+"/secrets switch off allows", func(t *testing.T) { + resetHookGlobals(t) + useScannerConfig(t, "cx_secret_scanner_enabled=false\n") + secretsScanner = stubSecretsScanner(secret) if v := cxBeforeFileEdit(secretsEdit(secret, agent)); !v.Permit { - t.Fatal("secret detection must not run for this agent") + t.Fatal("secrets switch must apply to this agent") } }) - t.Run(agentToString(agent)+"/kics switch off still blocks", func(t *testing.T) { + t.Run(agentToString(agent)+"/kics switch off allows", func(t *testing.T) { resetHookGlobals(t) useScannerConfig(t, "cx_kics_scanner_enabled=false\n") kicsScanner = kicsFinding("HIGH") - if v := cxBeforeFileEdit(kicsEdit(agent)); v.Permit { - t.Fatal("kics switch must not apply to this agent") + if v := cxBeforeFileEdit(kicsEdit(agent)); !v.Permit { + t.Fatal("kics switch must apply to this agent") } }) - t.Run(agentToString(agent)+"/threshold does not relax", func(t *testing.T) { + t.Run(agentToString(agent)+"/threshold relaxes", func(t *testing.T) { resetHookGlobals(t) useScannerConfig(t, "cx_severity_threshold=critical\n") kicsScanner = kicsFinding("LOW") - if v := cxBeforeFileEdit(kicsEdit(agent)); v.Permit { - t.Fatal("severity threshold must not apply to this agent") + if v := cxBeforeFileEdit(kicsEdit(agent)); !v.Permit { + t.Fatal("severity threshold must apply to this agent") } }) } } - -func TestSwitchesApply_ExcludesFourAgents(t *testing.T) { - for agent, want := range map[agenthooks.AgentID]bool{ - agenthooks.AgentCopilotCLI: true, agenthooks.AgentCopilot: true, - agenthooks.AgentDroid: true, agenthooks.AgentWindsurf: true, - agenthooks.AgentClaude: false, agenthooks.AgentCursor: false, agenthooks.AgentGemini: false, - agenthooks.AgentCodex: false, - } { - if got := switchesApply(agent); got != want { - t.Errorf("%s: got %v, want %v", agentToString(agent), got, want) - } - } -} - -func TestSecretsApply_ExcludesFourAgents(t *testing.T) { - for agent, want := range map[agenthooks.AgentID]bool{ - agenthooks.AgentCopilotCLI: true, agenthooks.AgentCopilot: true, - agenthooks.AgentDroid: true, agenthooks.AgentWindsurf: true, - agenthooks.AgentClaude: false, agenthooks.AgentCursor: false, - agenthooks.AgentGemini: false, agenthooks.AgentCodex: false, - } { - if got := secretsApply(agent); got != want { - t.Errorf("%s: got %v, want %v", agentToString(agent), got, want) - } - } -} From 4bc1786ba1edaed17983ee6c0442770e5d8d90ee Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:06:08 +0530 Subject: [PATCH 2/5] Limit scanner switches, severity threshold and secrets to Claude and Copilot Restore the switchesApply/secretsApply allow-list for Cursor, Gemini and Codex, whose plugins do not yet ship the secrets skill or handle the settings. Claude Code and GitHub Copilot (and Droid/Windsurf) keep honouring secret detection, scanner switches and cx_severity_threshold. Co-Authored-By: Claude Sonnet 5.5 --- internal/commands/agenthooks/cx/hooks.go | 39 ++++++++-- .../agenthooks/cx/scanner_switch_test.go | 73 +++++++++++++++++-- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/internal/commands/agenthooks/cx/hooks.go b/internal/commands/agenthooks/cx/hooks.go index 0afddb2b8..3199026d1 100644 --- a/internal/commands/agenthooks/cx/hooks.go +++ b/internal/commands/agenthooks/cx/hooks.go @@ -40,7 +40,7 @@ var kicsScanner *kics.Scanner // bindThreshold points each guardrail's finding filter at the severity threshold for this event's // agent, so findings below cx_severity_threshold are left out of a deny and the agent is not told to -// fix them. +// fix them. Agents the switches do not apply to keep every finding. func bindThreshold(agent agenthooks.AgentID) { below := func(severity string) bool { return belowThreshold(agent, severity) } secrets.BelowThreshold = below @@ -168,7 +168,7 @@ func cxBeforeFileEdit(ev agenthooks.FileEditEvent) agenthooks.FileEditVerdict { } } } - if secretsScanner != nil && scannerOn(ev.Agent, scannerconfig.Secrets) { + if secretsScanner != nil && secretsApply(ev.Agent) && scannerOn(ev.Agent, scannerconfig.Secrets) { if blocked, reason, context, severity := secrets.ScanFileEdit(&ev, secretsScanner, telemetryWrapper, agent); blocked && !belowThreshold(ev.Agent, severity) { sessiontally.Add(ev.SessionID, engineSecrets, 1, 1) logRemediationTelemetry(agent, "Secrets", severity, ev.SessionID) @@ -310,10 +310,32 @@ func logRemediationTelemetry(agent, engine, severity, sessionID string) { } } -// scannerOn reports whether scanner s is switched on in ~/.checkmarx/cx-onboarding.properties; every agent -// honours it. GitHub Copilot inside VS Code takes the switches from the VS Code extension's IDE file -// instead, while that file is valid. +// switchesApply reports whether the ~/.checkmarx/cx-onboarding.properties scanner switches and severity +// threshold are honoured for this agent. Cursor, Gemini and Codex are excluded for now: they keep +// scanning with ASCA / KICS / SCA and blocking at any severity even when the shared file exists on the +// machine. Every other agent (Claude, GitHub Copilot, Droid, Windsurf, ...) honours it. Add an agent to +// the case list below to hold it back, or remove one to roll the feature out to it. +func switchesApply(agent agenthooks.AgentID) bool { + switch agent { + case agenthooks.AgentCursor, agenthooks.AgentGemini, agenthooks.AgentCodex: + return false + } + return true +} + +// secretsApply reports whether the secret-detection guardrail runs for this agent. Cursor, Gemini and +// Codex skip it entirely and keep the ASCA / KICS / SCA guardrails; every other agent runs it. It +// shares switchesApply's agent list so the two cannot drift apart. +func secretsApply(agent agenthooks.AgentID) bool { + return switchesApply(agent) +} + +// scannerOn is scannerconfig.Enabled, limited to the agents the switches apply to. GitHub Copilot inside +// VS Code takes the switches from the VS Code extension's IDE file instead, while that file is valid. func scannerOn(agent agenthooks.AgentID, s scannerconfig.Scanner) bool { + if !switchesApply(agent) { + return true + } if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { return scannerconfig.IDEEnabled(s) } @@ -333,9 +355,12 @@ func selfHealingOff(agent agenthooks.AgentID, hook string) bool { return true } -// belowThreshold is scannerconfig.BelowThreshold for every agent. GitHub Copilot inside VS Code has no -// threshold setting, so it uses the IDE file's threshold, low when unset. +// belowThreshold is scannerconfig.BelowThreshold, limited to the agents the switches apply to. GitHub +// Copilot inside VS Code has no threshold setting, so it uses the IDE file's threshold, low when unset. func belowThreshold(agent agenthooks.AgentID, severity string) bool { + if !switchesApply(agent) { + return false + } if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { return scannerconfig.IDEBelowThreshold(severity) } diff --git a/internal/commands/agenthooks/cx/scanner_switch_test.go b/internal/commands/agenthooks/cx/scanner_switch_test.go index aac94e0ee..30af9aaae 100644 --- a/internal/commands/agenthooks/cx/scanner_switch_test.go +++ b/internal/commands/agenthooks/cx/scanner_switch_test.go @@ -181,14 +181,71 @@ func TestCxBeforeFileEdit_SeverityThreshold_SecretsMixed(t *testing.T) { } } -// Secret detection, the scanner switches and the severity threshold apply to every agent alike. -func TestSwitches_HonouredForEveryAgent(t *testing.T) { - const secret = "ghp_every_agent_secret_value" - agents := []agenthooks.AgentID{ - agenthooks.AgentClaude, agenthooks.AgentCursor, agenthooks.AgentGemini, agenthooks.AgentCodex, - agenthooks.AgentCopilotCLI, agenthooks.AgentDroid, agenthooks.AgentWindsurf, - } - for _, agent := range agents { +// The switches and secret detection are features of every agent except Cursor, Gemini and Codex: those three skip secret +// detection and, with the shared properties file present, keeps ASCA/KICS/SCA blocking at any severity. +func TestSwitches_IgnoredForOtherAgents(t *testing.T) { + const secret = "ghp_other_agent_secret_value" + others := []agenthooks.AgentID{ + agenthooks.AgentCursor, agenthooks.AgentGemini, agenthooks.AgentCodex, + } + for _, agent := range others { + t.Run(agentToString(agent)+"/secrets are skipped", func(t *testing.T) { + resetHookGlobals(t) + useScannerConfig(t, "") + secretsScanner = stubSecretsScanner(secret) + if v := cxBeforeFileEdit(secretsEdit(secret, agent)); !v.Permit { + t.Fatal("secret detection must not run for this agent") + } + }) + t.Run(agentToString(agent)+"/kics switch off still blocks", func(t *testing.T) { + resetHookGlobals(t) + useScannerConfig(t, "cx_kics_scanner_enabled=false\n") + kicsScanner = kicsFinding("HIGH") + if v := cxBeforeFileEdit(kicsEdit(agent)); v.Permit { + t.Fatal("kics switch must not apply to this agent") + } + }) + t.Run(agentToString(agent)+"/threshold does not relax", func(t *testing.T) { + resetHookGlobals(t) + useScannerConfig(t, "cx_severity_threshold=critical\n") + kicsScanner = kicsFinding("LOW") + if v := cxBeforeFileEdit(kicsEdit(agent)); v.Permit { + t.Fatal("severity threshold must not apply to this agent") + } + }) + } +} + +func TestSwitchesApply_ExcludesThreeAgents(t *testing.T) { + for agent, want := range map[agenthooks.AgentID]bool{ + agenthooks.AgentCopilotCLI: true, agenthooks.AgentCopilot: true, + agenthooks.AgentDroid: true, agenthooks.AgentWindsurf: true, + agenthooks.AgentClaude: true, agenthooks.AgentCursor: false, agenthooks.AgentGemini: false, + agenthooks.AgentCodex: false, + } { + if got := switchesApply(agent); got != want { + t.Errorf("%s: got %v, want %v", agentToString(agent), got, want) + } + } +} + +func TestSecretsApply_ExcludesThreeAgents(t *testing.T) { + for agent, want := range map[agenthooks.AgentID]bool{ + agenthooks.AgentCopilotCLI: true, agenthooks.AgentCopilot: true, + agenthooks.AgentDroid: true, agenthooks.AgentWindsurf: true, + agenthooks.AgentClaude: true, agenthooks.AgentCursor: false, + agenthooks.AgentGemini: false, agenthooks.AgentCodex: false, + } { + if got := secretsApply(agent); got != want { + t.Errorf("%s: got %v, want %v", agentToString(agent), got, want) + } + } +} + +// Claude Code and GitHub Copilot CLI honour secret detection, the scanner switches and the severity threshold. +func TestSwitches_HonouredForClaudeAndCopilot(t *testing.T) { + const secret = "ghp_supported_agent_secret_value" + for _, agent := range []agenthooks.AgentID{agenthooks.AgentClaude, agenthooks.AgentCopilotCLI} { t.Run(agentToString(agent)+"/secrets block by default", func(t *testing.T) { resetHookGlobals(t) useScannerConfig(t, "") From 978acb1c04a284dd2fa468ef561638ed3919acdc Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:34:02 +0530 Subject: [PATCH 3/5] Default cx_severity_threshold to high for agents the switches apply to A blank, missing or invalid cx_severity_threshold previously meant low (nothing filtered). Default it to high instead for every agent switchesApply covers (Claude, Copilot, Droid, Windsurf), so only high/critical findings still block until the developer configures a lower threshold. An explicit value in the properties file always wins. Co-Authored-By: Claude Sonnet 5 --- internal/commands/agenthooks/cx/hooks.go | 18 ++++++-- .../agenthooks/cx/scanner_switch_test.go | 26 +++++++++-- .../agenthooks/cx/vscode_self_healing_test.go | 12 ++--- .../agenthooks/scannerconfig/scannerconfig.go | 45 +++++++++++-------- .../scannerconfig/scannerconfig_test.go | 29 +++++++----- 5 files changed, 89 insertions(+), 41 deletions(-) diff --git a/internal/commands/agenthooks/cx/hooks.go b/internal/commands/agenthooks/cx/hooks.go index 3199026d1..d15c15101 100644 --- a/internal/commands/agenthooks/cx/hooks.go +++ b/internal/commands/agenthooks/cx/hooks.go @@ -355,16 +355,28 @@ func selfHealingOff(agent agenthooks.AgentID, hook string) bool { return true } +// defaultThresholdRank is the severity rank cx_severity_threshold falls back to when it is blank, +// missing or invalid. Every agent switchesApply covers (Claude, Copilot, Droid, Windsurf) defaults to +// high, so only high/critical findings still block until the developer configures a lower threshold. +func defaultThresholdRank(agent agenthooks.AgentID) int { + if !switchesApply(agent) { + return scannerconfig.RankLow + } + return scannerconfig.RankHigh +} + // belowThreshold is scannerconfig.BelowThreshold, limited to the agents the switches apply to. GitHub -// Copilot inside VS Code has no threshold setting, so it uses the IDE file's threshold, low when unset. +// Copilot inside VS Code has no threshold setting, so it uses the IDE file's threshold, defaulting per +// defaultThresholdRank when unset. func belowThreshold(agent agenthooks.AgentID, severity string) bool { if !switchesApply(agent) { return false } + defaultRank := defaultThresholdRank(agent) if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { - return scannerconfig.IDEBelowThreshold(severity) + return scannerconfig.IDEBelowThreshold(severity, defaultRank) } - return scannerconfig.BelowThreshold(severity) + return scannerconfig.BelowThreshold(severity, defaultRank) } // agentToString converts agenthooks.AgentID enum to string representation for telemetry. diff --git a/internal/commands/agenthooks/cx/scanner_switch_test.go b/internal/commands/agenthooks/cx/scanner_switch_test.go index 30af9aaae..b24ae0966 100644 --- a/internal/commands/agenthooks/cx/scanner_switch_test.go +++ b/internal/commands/agenthooks/cx/scanner_switch_test.go @@ -13,6 +13,7 @@ import ( "github.com/checkmarx/ast-cli/internal/commands/agenthooks/guardrails/kics" "github.com/checkmarx/ast-cli/internal/commands/agenthooks/guardrails/secrets" + "github.com/checkmarx/ast-cli/internal/commands/agenthooks/scannerconfig" "github.com/checkmarx/ast-cli/internal/services/realtimeengine" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/iacrealtime" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/secretsrealtime" @@ -109,9 +110,10 @@ func TestCxBeforeFileEdit_SeverityThreshold(t *testing.T) { severity string wantBlock bool }{ - {"no config blocks low", "", "LOW", true}, - {"blank threshold blocks low", "cx_severity_threshold=\n", "LOW", true}, - {"invalid threshold blocks low", "cx_severity_threshold=hihg\n", "LOW", true}, + {"no config defaults to high, lets low through", "", "LOW", false}, + {"blank threshold defaults to high, lets low through", "cx_severity_threshold=\n", "LOW", false}, + {"invalid threshold defaults to high, lets low through", "cx_severity_threshold=hihg\n", "LOW", false}, + {"explicit low threshold blocks low", "cx_severity_threshold=low\n", "LOW", true}, {"high threshold lets low through", "cx_severity_threshold=high\n", "LOW", false}, {"high threshold lets medium through", "cx_severity_threshold=high\n", "MEDIUM", false}, {"high threshold blocks high", "cx_severity_threshold=high\n", "HIGH", true}, @@ -138,7 +140,7 @@ func TestCxBeforeFileEdit_SeverityThreshold_Secrets(t *testing.T) { severity string wantBlock bool }{ - {"no config blocks low", "", "Low", true}, + {"no config defaults to high, lets low through", "", "Low", false}, {"high threshold lets medium through", "cx_severity_threshold=high\n", "Medium", false}, {"high threshold blocks high", "cx_severity_threshold=high\n", "High", true}, {"critical threshold lets low through", "cx_severity_threshold=critical\n", "Low", false}, @@ -242,6 +244,22 @@ func TestSecretsApply_ExcludesThreeAgents(t *testing.T) { } } +// Every agent switchesApply covers defaults cx_severity_threshold to high when unset; the three +// excluded agents (Cursor, Gemini, Codex) never relax, so their default rank is immaterial but still low. +func TestDefaultThresholdRank_IsHighForSwitchesApplyAgents(t *testing.T) { + for agent, want := range map[agenthooks.AgentID]int{ + agenthooks.AgentClaude: scannerconfig.RankHigh, agenthooks.AgentCopilot: scannerconfig.RankHigh, + agenthooks.AgentCopilotCLI: scannerconfig.RankHigh, agenthooks.AgentDroid: scannerconfig.RankHigh, + agenthooks.AgentWindsurf: scannerconfig.RankHigh, + agenthooks.AgentCursor: scannerconfig.RankLow, agenthooks.AgentGemini: scannerconfig.RankLow, + agenthooks.AgentCodex: scannerconfig.RankLow, + } { + if got := defaultThresholdRank(agent); got != want { + t.Errorf("%s: got %d, want %d", agentToString(agent), got, want) + } + } +} + // Claude Code and GitHub Copilot CLI honour secret detection, the scanner switches and the severity threshold. func TestSwitches_HonouredForClaudeAndCopilot(t *testing.T) { const secret = "ghp_supported_agent_secret_value" diff --git a/internal/commands/agenthooks/cx/vscode_self_healing_test.go b/internal/commands/agenthooks/cx/vscode_self_healing_test.go index 61a15c9a9..e9cd7d875 100644 --- a/internal/commands/agenthooks/cx/vscode_self_healing_test.go +++ b/internal/commands/agenthooks/cx/vscode_self_healing_test.go @@ -102,18 +102,18 @@ func TestScannerOn_VSCodeUsesIDEFile(t *testing.T) { } } -func TestBelowThreshold_VSCodeDefaultsToLow(t *testing.T) { - const cliHigh = "cx_severity_threshold=high\n" +func TestBelowThreshold_VSCodeDefaultsToHigh(t *testing.T) { + const cliLow = "cx_severity_threshold=low\n" cases := []struct { name string root string ide, cli string want bool }{ - {"VS Code without a threshold blocks Medium (low)", rootVSCodeFromCLIInstall, "cx_schema_version=1\n", cliHigh, false}, - {"VS Code without an IDE file blocks Medium (low)", rootVSCodeFromMarketplace, "", cliHigh, false}, - {"VS Code honours a threshold in the IDE file", rootVSCodeFromCLIInstall, "cx_schema_version=1\n" + cliHigh, "", true}, - {"terminal keeps the terminal threshold", rootCLI, "cx_schema_version=1\n", cliHigh, true}, + {"VS Code without a threshold relaxes Medium (default high)", rootVSCodeFromCLIInstall, "cx_schema_version=1\n", "", true}, + {"VS Code without an IDE file relaxes Medium (default high)", rootVSCodeFromMarketplace, "", "", true}, + {"VS Code IDE file can still lower the threshold to low", rootVSCodeFromCLIInstall, "cx_schema_version=1\n" + cliLow, "", false}, + {"terminal file is ignored by VS Code even when it sets low", rootVSCodeFromCLIInstall, "cx_schema_version=1\n", cliLow, true}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig.go b/internal/commands/agenthooks/scannerconfig/scannerconfig.go index 2e96c3972..1ed008eee 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig.go @@ -173,49 +173,58 @@ const thresholdKey = "cx_severity_threshold" // package status such as "Malicious", an unexpected label) has no rank and is never relaxed. var severityRank = map[string]int{"low": 1, "medium": 2, "high": 3, "critical": 4} +// RankLow and RankHigh are the severity ranks callers pass as a default when cx_severity_threshold is +// blank, missing or invalid. RankLow filters nothing; RankHigh lets low/medium findings through. +const ( + RankLow = 1 + RankHigh = 3 +) + // Threshold returns the minimum severity rank (1 low … 4 critical) a finding needs to block. -// Blank, missing or invalid means low, so nothing is filtered. -func Threshold() int { - return thresholdIn(Path()) +// Blank, missing or invalid falls back to defaultRank (pass RankLow or RankHigh). +func Threshold(defaultRank int) int { + return thresholdIn(Path(), defaultRank) } -func thresholdIn(path string) int { +func thresholdIn(path string, defaultRank int) int { value, _ := valueIn(path, thresholdKey) - return thresholdRank(value) + return thresholdRank(value, defaultRank) } -// thresholdRank is the rank of a cx_severity_threshold value; blank or invalid means low (1). -func thresholdRank(value string) int { +// thresholdRank is the rank of a cx_severity_threshold value; blank or invalid falls back to defaultRank. +func thresholdRank(value string, defaultRank int) int { if rank, ok := severityRank[strings.ToLower(strings.TrimSpace(value))]; ok { return rank } - return 1 + return defaultRank } // IDEThreshold is Threshold for events from VS Code. The VS Code extension writes cx_severity_threshold=low // to the VS Code state file, so only that file's cx_severity_threshold counts; a missing file, key or invalid -// value is low (nothing filtered). The terminal's ~/.checkmarx/cx-onboarding.properties threshold never applies to VS Code. -func IDEThreshold() int { - return ideThresholdIn(IDEPath()) +// value falls back to defaultRank. The terminal's ~/.checkmarx/cx-onboarding.properties threshold never +// applies to VS Code. +func IDEThreshold(defaultRank int) int { + return ideThresholdIn(IDEPath(), defaultRank) } -func ideThresholdIn(path string) int { +func ideThresholdIn(path string, defaultRank int) int { props, ok := ideProps(path) if !ok { - return 1 + return defaultRank } - return thresholdRank(props[thresholdKey]) + return thresholdRank(props[thresholdKey], defaultRank) } // BelowThreshold reports whether a deny whose highest severity is `severity` should be let through // because it is under cx_severity_threshold. An unranked severity returns false (keep blocking). -func BelowThreshold(severity string) bool { - return belowRank(severity, Threshold()) +// defaultRank is used when the threshold is blank, missing or invalid. +func BelowThreshold(severity string, defaultRank int) bool { + return belowRank(severity, Threshold(defaultRank)) } // IDEBelowThreshold is BelowThreshold for events from VS Code, against IDEThreshold. -func IDEBelowThreshold(severity string) bool { - return belowRank(severity, IDEThreshold()) +func IDEBelowThreshold(severity string, defaultRank int) bool { + return belowRank(severity, IDEThreshold(defaultRank)) } func belowRank(severity string, threshold int) bool { diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go index 78aecd9cf..7e5582826 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go @@ -103,13 +103,16 @@ func TestThresholdIn(t *testing.T) { "cx_severity_threshold=high\ncx_severity_threshold=low\n": 1, // last wins } for body, want := range cases { - if got := thresholdIn(write(t, body)); got != want { + if got := thresholdIn(write(t, body), RankLow); got != want { t.Errorf("%q: got %d, want %d", body, got, want) } } - if thresholdIn(filepath.Join(t.TempDir(), "missing")) != 1 || thresholdIn("") != 1 { + if thresholdIn(filepath.Join(t.TempDir(), "missing"), RankLow) != 1 || thresholdIn("", RankLow) != 1 { t.Error("missing file / path must mean low") } + if got := thresholdIn(filepath.Join(t.TempDir(), "missing"), RankHigh); got != RankHigh { + t.Errorf("missing file with a high default must mean high: got %d", got) + } } func TestBelowThreshold(t *testing.T) { @@ -127,13 +130,19 @@ func TestBelowThreshold(t *testing.T) { "Low": true, "MEDIUM": true, "High": false, "Critical": false, "": false, "Malicious": false, "weird": false, // unranked is never relaxed } { - if got := BelowThreshold(sev); got != want { + if got := BelowThreshold(sev, RankLow); got != want { t.Errorf("high threshold, %q: got %v, want %v", sev, got, want) } } set("cx_severity_threshold=\n") - if BelowThreshold("Low") { - t.Error("blank threshold must filter nothing") + if BelowThreshold("Low", RankLow) { + t.Error("blank threshold must filter nothing with a low default") + } + if !BelowThreshold("Low", RankHigh) { + t.Error("blank threshold must filter Low with a high default") + } + if BelowThreshold("High", RankHigh) { + t.Error("blank threshold must not filter High with a high default") } } @@ -241,11 +250,11 @@ func TestIDEThresholdIn(t *testing.T) { "cx_schema_version=2\ncx_severity_threshold=high\n": 1, // unknown schema: file ignored } for body, want := range cases { - if got := ideThresholdIn(writeIDE(t, body)); got != want { + if got := ideThresholdIn(writeIDE(t, body), RankLow); got != want { t.Errorf("%q: got %d, want %d", body, got, want) } } - if ideThresholdIn(filepath.Join(t.TempDir(), "missing")) != 1 || ideThresholdIn("") != 1 { + if ideThresholdIn(filepath.Join(t.TempDir(), "missing"), RankLow) != 1 || ideThresholdIn("", RankLow) != 1 { t.Error("missing IDE file / path must mean low") } } @@ -257,10 +266,10 @@ func TestIDEBelowThresholdIgnoresTerminalThreshold(t *testing.T) { _ = os.MkdirAll(filepath.Join(dir, ".checkmarx"), 0o755) _ = os.WriteFile(Path(), []byte("cx_severity_threshold=critical\n"), 0o600) _ = os.WriteFile(IDEPath(), []byte("cx_schema_version=1\ncx_self_healing_enabled=true\n"), 0o600) - if !BelowThreshold("High") { + if !BelowThreshold("High", RankLow) { t.Error("terminal: a critical threshold must relax High") } - if IDEBelowThreshold("Low") || IDEBelowThreshold("High") { - t.Error("VS Code without a threshold must block at every severity (low)") + if IDEBelowThreshold("Low", RankLow) || IDEBelowThreshold("High", RankLow) { + t.Error("VS Code without a threshold must block at every severity (low default)") } } From eea88c0996de8cdfbc832e7ab7377a43faef3e66 Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:03:33 +0530 Subject: [PATCH 4/5] AST-196419 Fix gofmt alignment in scanner switch test Co-Authored-By: Claude Sonnet 5.5 --- internal/commands/agenthooks/cx/scanner_switch_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/agenthooks/cx/scanner_switch_test.go b/internal/commands/agenthooks/cx/scanner_switch_test.go index b24ae0966..d43fb00e4 100644 --- a/internal/commands/agenthooks/cx/scanner_switch_test.go +++ b/internal/commands/agenthooks/cx/scanner_switch_test.go @@ -252,7 +252,7 @@ func TestDefaultThresholdRank_IsHighForSwitchesApplyAgents(t *testing.T) { agenthooks.AgentCopilotCLI: scannerconfig.RankHigh, agenthooks.AgentDroid: scannerconfig.RankHigh, agenthooks.AgentWindsurf: scannerconfig.RankHigh, agenthooks.AgentCursor: scannerconfig.RankLow, agenthooks.AgentGemini: scannerconfig.RankLow, - agenthooks.AgentCodex: scannerconfig.RankLow, + agenthooks.AgentCodex: scannerconfig.RankLow, } { if got := defaultThresholdRank(agent); got != want { t.Errorf("%s: got %d, want %d", agentToString(agent), got, want) From e91a3a9afb35df3ec154e94df08fc9c391e23aa9 Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:05:26 +0530 Subject: [PATCH 5/5] AST-197643 Never block on an unrated (None/Unknown) severity at any threshold Co-Authored-By: Claude Sonnet 5.5 --- internal/commands/agenthooks/cx/hooks.go | 4 ++-- .../commands/agenthooks/cx/scanner_switch_test.go | 4 +++- internal/commands/agenthooks/sca/sca.go | 2 +- .../agenthooks/scannerconfig/scannerconfig.go | 13 +++++++++++-- .../agenthooks/scannerconfig/scannerconfig_test.go | 1 + 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/internal/commands/agenthooks/cx/hooks.go b/internal/commands/agenthooks/cx/hooks.go index d15c15101..91fa7a811 100644 --- a/internal/commands/agenthooks/cx/hooks.go +++ b/internal/commands/agenthooks/cx/hooks.go @@ -140,8 +140,8 @@ func cxBeforeFileEdit(ev agenthooks.FileEditEvent) agenthooks.FileEditVerdict { // Each engine below is skipped (not just its verdict ignored) when the developer switched it off in // ~/.checkmarx/cx-onboarding.properties; an unreadable config leaves every engine on. // cx_severity_threshold (same file): a deny whose highest severity is below the threshold is let - // through for ASCA, KICS, SCA and secrets. Malicious packages and an unknown severity - // are never relaxed. A blank or invalid threshold means low (nothing filtered). + // through for ASCA, KICS, SCA and secrets. Malicious packages and an empty or unexpected severity + // are never relaxed; an unrated (None/Unknown) severity is always let through, low threshold included. A blank or invalid threshold means low (nothing filtered). if scannerOn(ev.Agent, scannerconfig.ASCA) { if blocked, reason, context, severity := asca.ScanFileEdit(&ev, telemetryWrapper, agent); blocked && !belowThreshold(ev.Agent, severity) { sessiontally.Add(ev.SessionID, engineAsca, 1, 1) diff --git a/internal/commands/agenthooks/cx/scanner_switch_test.go b/internal/commands/agenthooks/cx/scanner_switch_test.go index d43fb00e4..2752de578 100644 --- a/internal/commands/agenthooks/cx/scanner_switch_test.go +++ b/internal/commands/agenthooks/cx/scanner_switch_test.go @@ -118,7 +118,9 @@ func TestCxBeforeFileEdit_SeverityThreshold(t *testing.T) { {"high threshold lets medium through", "cx_severity_threshold=high\n", "MEDIUM", false}, {"high threshold blocks high", "cx_severity_threshold=high\n", "HIGH", true}, {"high threshold blocks critical", "cx_severity_threshold=high\n", "CRITICAL", true}, - {"unknown severity is never relaxed", "cx_severity_threshold=critical\n", "", true}, + {"empty severity is never relaxed", "cx_severity_threshold=critical\n", "", true}, + {"unrated severity never blocks at low", "cx_severity_threshold=low\n", "None", false}, + {"unrated severity never blocks at critical", "cx_severity_threshold=critical\n", "None", false}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { diff --git a/internal/commands/agenthooks/sca/sca.go b/internal/commands/agenthooks/sca/sca.go index 641906fd4..9c566aa4e 100644 --- a/internal/commands/agenthooks/sca/sca.go +++ b/internal/commands/agenthooks/sca/sca.go @@ -87,7 +87,7 @@ func denyFrom(malicious, vulnerable []ossrealtime.OssPackage, workDir, agent, se } // aboveThreshold drops CVEs below the developer's severity threshold, and any package left with -// none. Malicious packages never go through here. A CVE with an unknown severity is kept. +// none. Malicious packages never go through here. A CVE with no severity rating (None/Unknown) is dropped at every threshold. func aboveThreshold(pkgs []ossrealtime.OssPackage) []ossrealtime.OssPackage { if BelowThreshold == nil { return pkgs diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig.go b/internal/commands/agenthooks/scannerconfig/scannerconfig.go index 1ed008eee..b36887344 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig.go @@ -173,6 +173,10 @@ const thresholdKey = "cx_severity_threshold" // package status such as "Malicious", an unexpected label) has no rank and is never relaxed. var severityRank = map[string]int{"low": 1, "medium": 2, "high": 3, "critical": 4} +// unratedSeverity lists the labels for a finding that has no severity rating (a CVE without a score). +// Such a finding is unknown, not dangerous, so it is below every threshold, low included, and never blocks. +var unratedSeverity = map[string]bool{"none": true, "unknown": true} + // RankLow and RankHigh are the severity ranks callers pass as a default when cx_severity_threshold is // blank, missing or invalid. RankLow filters nothing; RankHigh lets low/medium findings through. const ( @@ -216,7 +220,8 @@ func ideThresholdIn(path string, defaultRank int) int { } // BelowThreshold reports whether a deny whose highest severity is `severity` should be let through -// because it is under cx_severity_threshold. An unranked severity returns false (keep blocking). +// because it is under cx_severity_threshold. An unrated severity ("None", "Unknown") is under every +// threshold and returns true; any other unranked severity returns false (keep blocking). // defaultRank is used when the threshold is blank, missing or invalid. func BelowThreshold(severity string, defaultRank int) bool { return belowRank(severity, Threshold(defaultRank)) @@ -228,6 +233,10 @@ func IDEBelowThreshold(severity string, defaultRank int) bool { } func belowRank(severity string, threshold int) bool { - rank, ok := severityRank[strings.ToLower(strings.TrimSpace(severity))] + label := strings.ToLower(strings.TrimSpace(severity)) + if unratedSeverity[label] { + return true + } + rank, ok := severityRank[label] return ok && rank < threshold } diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go index 7e5582826..66089b4a3 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go @@ -129,6 +129,7 @@ func TestBelowThreshold(t *testing.T) { for sev, want := range map[string]bool{ "Low": true, "MEDIUM": true, "High": false, "Critical": false, "": false, "Malicious": false, "weird": false, // unranked is never relaxed + "None": true, "unknown": true, // unrated is below every threshold } { if got := BelowThreshold(sev, RankLow); got != want { t.Errorf("high threshold, %q: got %v, want %v", sev, got, want)