From 5b1e1ebf279e9aa84e15751b6d63c86053983abb Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Wed, 28 Oct 2026 20:07:30 +0530 Subject: [PATCH 1/9] Honour the VS Code Checkmarx Self-Healing setting in Copilot agent hooks (AST-180812) (#1603) --- internal/commands/agenthooks/cx/hooks.go | 42 +++++- .../agenthooks/cx/vscode_self_healing_test.go | 127 +++++++++++++++++ .../agenthooks/guardrails/asca/asca.go | 3 +- .../agenthooks/guardrails/kics/kics.go | 3 +- .../agenthooks/guardrails/secrets/secrets.go | 3 +- .../commands/agenthooks/hostenv/hostenv.go | 64 +++++++++ .../agenthooks/hostenv/hostenv_test.go | 72 ++++++++++ .../agenthooks/scannerconfig/scannerconfig.go | 129 ++++++++++++++++-- .../scannerconfig/scannerconfig_test.go | 128 +++++++++++++++++ 9 files changed, 550 insertions(+), 21 deletions(-) create mode 100644 internal/commands/agenthooks/cx/vscode_self_healing_test.go create mode 100644 internal/commands/agenthooks/hostenv/hostenv.go create mode 100644 internal/commands/agenthooks/hostenv/hostenv_test.go diff --git a/internal/commands/agenthooks/cx/hooks.go b/internal/commands/agenthooks/cx/hooks.go index 9fb7e331..dbe0b0d6 100644 --- a/internal/commands/agenthooks/cx/hooks.go +++ b/internal/commands/agenthooks/cx/hooks.go @@ -12,9 +12,11 @@ import ( "github.com/checkmarx/ast-cli/internal/commands/agenthooks/guardrails/asca" "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/hostenv" "github.com/checkmarx/ast-cli/internal/commands/agenthooks/sca" "github.com/checkmarx/ast-cli/internal/commands/agenthooks/scannerconfig" "github.com/checkmarx/ast-cli/internal/commands/agenthooks/sessiontally" + "github.com/checkmarx/ast-cli/internal/logger" "github.com/checkmarx/ast-cli/internal/wrappers" ) @@ -113,6 +115,9 @@ func cxBeforeToolCall(ev agenthooks.ToolCallEvent) agenthooks.ToolVerdict { // or if the file exceeds the policy size cap. Reads do NOT count toward // the blast-radius budget (that limit is about writes). func cxBeforeFileEdit(ev agenthooks.FileEditEvent) agenthooks.FileEditVerdict { + if selfHealingOff(ev.Agent, "pre-file-write") { + return agenthooks.AcceptEdit() + } bindThreshold(ev.Agent) if ev.Agent == agenthooks.AgentCursor && len(ev.Changes) == 0 { if reason := guardrails.ScanFileForSecrets(ev.FilePath); reason != "" { @@ -290,7 +295,7 @@ func logRemediationTelemetry(agent, engine, severity, sessionID string) { telemetryData := &wrappers.DataForAITelemetry{ AIProvider: agent, - Agent: agent + "-cli", + Agent: hostenv.TelemetryAgent(agent), Engine: engine, ScanType: strings.ToLower(engine), UniqueID: wrappers.GetUniqueID(), @@ -325,14 +330,41 @@ func secretsApply(agent agenthooks.AgentID) bool { return switchesApply(agent) } -// scannerOn is scannerconfig.Enabled, limited to the agents the switches apply to. +// 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 { - return !switchesApply(agent) || scannerconfig.Enabled(s) + if !switchesApply(agent) { + return true + } + if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { + return scannerconfig.IDEEnabled(s) + } + return scannerconfig.Enabled(s) +} + +// selfHealingOff reports whether this GitHub Copilot hook runs inside VS Code with the VS Code extension's +// "Checkmarx Self-Healing" setting unticked (a valid IDE file saying cx_self_healing_enabled=false). The +// file-write scans then stand down without telemetry; shell commands and prompts are handled as before. +// The plugin's own hook scripts already stop before running cx in that case; this covers hooks that +// call cx directly. A missing or invalid IDE file means on, and the terminal Copilot CLI never reads it. +func selfHealingOff(agent agenthooks.AgentID, hook string) bool { + if agent != agenthooks.AgentCopilotCLI || !hostenv.InVSCode() || scannerconfig.SelfHealingEnabled() { + return false + } + logger.PrintfIfVerbose("hooks: copilot-cli %s allowed without scanning host=vscode skip_reason=self_healing_disabled", hook) + return true } -// belowThreshold is scannerconfig.BelowThreshold, limited to the agents the switches apply to. +// 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 { - return switchesApply(agent) && scannerconfig.BelowThreshold(severity) + if !switchesApply(agent) { + return false + } + if agent == agenthooks.AgentCopilotCLI && hostenv.InVSCode() { + return scannerconfig.IDEBelowThreshold(severity) + } + return scannerconfig.BelowThreshold(severity) } // agentToString converts agenthooks.AgentID enum to string representation for telemetry. diff --git a/internal/commands/agenthooks/cx/vscode_self_healing_test.go b/internal/commands/agenthooks/cx/vscode_self_healing_test.go new file mode 100644 index 00000000..61a15c9a --- /dev/null +++ b/internal/commands/agenthooks/cx/vscode_self_healing_test.go @@ -0,0 +1,127 @@ +//go:build !integration + +package cx + +import ( + "os" + "path/filepath" + "testing" + + agenthooks "github.com/Checkmarx/ast-cx-hooks" + + "github.com/checkmarx/ast-cli/internal/commands/agenthooks/scannerconfig" +) + +// PLUGIN_ROOT values as the hosts set them (AST-186850 PoC; Windows paths, any user name). +const ( + rootVSCodeFromCLIInstall = `C:\Users\u\AppData\Roaming\Code\agentPlugins\file-c-3A-Users-u-copilot-installed-plugins-cx-devassist-marketplace-cx-devassist\1a15407167c` + rootVSCodeFromMarketplace = `C:\Users\u\AppData\Roaming\Code\agentPlugins\file-c-3A-Users-u-vscode-agent-plugins-marketplace-repositories-github-com-Checkmarx-cx-agentic-ai\1a1542d091b` + rootCLI = `C:\Users\u\.copilot\installed-plugins\cx-devassist-marketplace\cx-devassist` +) + +// useHost sets the hook environment the host would inject. +func useHost(t *testing.T, pluginRoot, integrationID string) { + t.Helper() + t.Setenv("PLUGIN_ROOT", pluginRoot) + t.Setenv("GITHUB_COPILOT_INTEGRATION_ID", integrationID) +} + +// useIDEConfig points the user's home at a temp dir holding ~/.checkmarx/cx-onboarding-ide.properties +// (and optionally cx-onboarding.properties); an empty body means no file at all. +func useIDEConfig(t *testing.T, ideBody, cliBody string) { + t.Helper() + dir := t.TempDir() + t.Cleanup(setHomeDir(dir)) + cxDir := filepath.Join(dir, ".checkmarx") + if err := os.MkdirAll(cxDir, 0o755); err != nil { + t.Fatal(err) + } + for name, body := range map[string]string{"cx-onboarding-ide.properties": ideBody, "cx-onboarding.properties": cliBody} { + if body == "" { + continue + } + if err := os.WriteFile(filepath.Join(cxDir, name), []byte(body), 0o600); err != nil { + t.Fatal(err) + } + } +} + +func TestCxBeforeFileEdit_SelfHealingOff(t *testing.T) { + const secret = "ghp_self_healing_test_secret_value" + const off = "cx_schema_version=1\ncx_self_healing_enabled=false\n" + cases := []struct { + name string + agent agenthooks.AgentID + root string + ide string + wantBlock bool + }{ + {"VS Code + OFF allows without scanning", agenthooks.AgentCopilotCLI, rootVSCodeFromMarketplace, off, false}, + {"VS Code + ON scans", agenthooks.AgentCopilotCLI, rootVSCodeFromCLIInstall, "cx_self_healing_enabled=true\n", true}, + {"VS Code + no IDE file scans (default ON)", agenthooks.AgentCopilotCLI, rootVSCodeFromCLIInstall, "", true}, + {"VS Code + unknown schema scans", agenthooks.AgentCopilotCLI, rootVSCodeFromCLIInstall, "cx_schema_version=2\ncx_self_healing_enabled=false\n", true}, + {"terminal ignores the IDE file", agenthooks.AgentCopilotCLI, rootCLI, off, true}, + {"other agents ignore it", agenthooks.AgentWindsurf, rootVSCodeFromCLIInstall, off, true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + resetHookGlobals(t) + useIDEConfig(t, tc.ide, "") + useHost(t, tc.root, "") + secretsScanner = stubSecretsScanner(secret) + v := cxBeforeFileEdit(secretsEdit(secret, tc.agent)) + if v.Permit == tc.wantBlock { + t.Fatalf("Permit=%v, wantBlock=%v", v.Permit, tc.wantBlock) + } + }) + } +} + +func TestScannerOn_VSCodeUsesIDEFile(t *testing.T) { + const ideSecretsOff = "cx_schema_version=1\ncx_secret_scanner_enabled=false\n" + const cliSecretsOff = "cx_secret_scanner_enabled=false\n" + cases := []struct { + name string + root string + ide, cli string + want bool + }{ + {"VS Code follows the IDE file", rootVSCodeFromCLIInstall, ideSecretsOff, "", false}, + {"VS Code IDE file missing key is on, even if the terminal file is off", rootVSCodeFromCLIInstall, "cx_schema_version=1\n", cliSecretsOff, true}, + {"VS Code without a valid IDE file falls back to the terminal file", rootVSCodeFromCLIInstall, "", cliSecretsOff, false}, + {"terminal never reads the IDE file", rootCLI, ideSecretsOff, "", true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + useIDEConfig(t, tc.ide, tc.cli) + useHost(t, tc.root, "") + if got := scannerOn(agenthooks.AgentCopilotCLI, scannerconfig.Secrets); got != tc.want { + t.Fatalf("scannerOn = %v, want %v", got, tc.want) + } + }) + } +} + +func TestBelowThreshold_VSCodeDefaultsToLow(t *testing.T) { + const cliHigh = "cx_severity_threshold=high\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}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + useIDEConfig(t, tc.ide, tc.cli) + useHost(t, tc.root, "") + if got := belowThreshold(agenthooks.AgentCopilotCLI, "Medium"); got != tc.want { + t.Fatalf("belowThreshold = %v, want %v", got, tc.want) + } + }) + } +} diff --git a/internal/commands/agenthooks/guardrails/asca/asca.go b/internal/commands/agenthooks/guardrails/asca/asca.go index 09f10301..2427913e 100644 --- a/internal/commands/agenthooks/guardrails/asca/asca.go +++ b/internal/commands/agenthooks/guardrails/asca/asca.go @@ -6,6 +6,7 @@ import ( "strings" agenthooks "github.com/Checkmarx/ast-cx-hooks" + "github.com/checkmarx/ast-cli/internal/commands/agenthooks/hostenv" "github.com/checkmarx/ast-cli/internal/params" "github.com/checkmarx/ast-cli/internal/services" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/ignore" @@ -192,7 +193,7 @@ func logASCATelemetry(telemetryWrapper wrappers.TelemetryWrapper, agent, session } telemetryData := &wrappers.DataForAITelemetry{ - Agent: agent + "-cli", + Agent: hostenv.TelemetryAgent(agent), AIProvider: agent, Engine: "Asca", TotalCount: totalCount, diff --git a/internal/commands/agenthooks/guardrails/kics/kics.go b/internal/commands/agenthooks/guardrails/kics/kics.go index 17f63032..684f4ee0 100644 --- a/internal/commands/agenthooks/guardrails/kics/kics.go +++ b/internal/commands/agenthooks/guardrails/kics/kics.go @@ -7,6 +7,7 @@ import ( "strings" agenthooks "github.com/Checkmarx/ast-cx-hooks" + "github.com/checkmarx/ast-cli/internal/commands/agenthooks/hostenv" "github.com/checkmarx/ast-cli/internal/logger" "github.com/checkmarx/ast-cli/internal/params" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/iacrealtime" @@ -170,7 +171,7 @@ func logKicsTelemetry(telemetryWrapper wrappers.TelemetryWrapper, agent, session } telemetryData := &wrappers.DataForAITelemetry{ - Agent: agent + "-cli", + Agent: hostenv.TelemetryAgent(agent), AIProvider: agent, Engine: "IaC", TotalCount: totalCount, diff --git a/internal/commands/agenthooks/guardrails/secrets/secrets.go b/internal/commands/agenthooks/guardrails/secrets/secrets.go index b5a73c85..b4c3bbd8 100644 --- a/internal/commands/agenthooks/guardrails/secrets/secrets.go +++ b/internal/commands/agenthooks/guardrails/secrets/secrets.go @@ -4,6 +4,7 @@ import ( "os" agenthooks "github.com/Checkmarx/ast-cx-hooks" + "github.com/checkmarx/ast-cli/internal/commands/agenthooks/hostenv" "github.com/checkmarx/ast-cli/internal/logger" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/ignore" "github.com/checkmarx/ast-cli/internal/services/realtimeengine/secretsrealtime" @@ -121,7 +122,7 @@ func logSecretsTelemetry(telemetryWrapper wrappers.TelemetryWrapper, agent, sess } telemetryData := &wrappers.DataForAITelemetry{ - Agent: agent + "-cli", + Agent: hostenv.TelemetryAgent(agent), AIProvider: agent, Engine: "Secrets", TotalCount: totalCount, diff --git a/internal/commands/agenthooks/hostenv/hostenv.go b/internal/commands/agenthooks/hostenv/hostenv.go new file mode 100644 index 00000000..301af4d1 --- /dev/null +++ b/internal/commands/agenthooks/hostenv/hostenv.go @@ -0,0 +1,64 @@ +// Package hostenv tells where a GitHub Copilot hook runs — the terminal Copilot CLI or GitHub Copilot +// inside VS Code — and derives the telemetry agent label from it. Shared by the cx hook handlers and the +// guardrail packages so they cannot drift apart. Mirrors the cx-devassist Copilot plugin's +// _in_vscode / cx_in_vscode. +package hostenv + +import ( + "os" + "strings" +) + +// Where a Copilot hook runs. +const ( + HostUnknown = "" + HostCLI = "cli" + HostVSCode = "vscode" + HostOther = "other" // a VS Code fork (Cursor, Windsurf, Kiro, Devin, ...): never treated as VS Code +) + +// copilotAgent is the agent name the hook handlers use for GitHub Copilot (see cx.agentToString). +const copilotAgent = "Copilot" + +// agentVSCode is the telemetry agent label for GitHub Copilot inside VS Code. The terminal keeps "-cli". +const agentVSCode = "Copilot-VSCode" + +// PluginHost reports where this hook runs, from the PLUGIN_ROOT the host injected into the hook's +// environment (cx inherits it from the plugin's hook script). VS Code always runs its own copy of the +// plugin under /agentPlugins/ (Windows %APPDATA%\Code\agentPlugins, macOS +// ~/Library/Application Support/Code/agentPlugins, Linux ~/.config/Code/agentPlugins, Insiders +// likewise), whether the plugin was installed by the Copilot CLI or from VS Code's marketplace; the +// terminal Copilot CLI (also when started in VS Code's integrated terminal) runs it from +// ~/.copilot/installed-plugins/. Hashes and user names in the path are ignored. Any other PLUGIN_ROOT +// (a VS Code fork, JetBrains, Visual Studio, ...) is HostOther; no PLUGIN_ROOT is HostUnknown. +func PluginHost() string { + root := strings.ToLower(strings.ReplaceAll(os.Getenv("PLUGIN_ROOT"), `\`, "/")) + // The terminal marker is checked first: VS Code's folder names encode the source path with dashes + // (…-copilot-installed-plugins-…), so they never contain it, while a terminal path could contain + // "agentPlugins" by chance (a user or folder name). Only VS Code's own user-data folder ("Code", + // "Code - Insiders") counts: VS Code forks keep their agentPlugins copies under their own folder. + switch { + case strings.Contains(root, "/.copilot/installed-plugins/"): + return HostCLI + case strings.Contains(root, "/code/agentplugins/"), strings.Contains(root, "/code - insiders/agentplugins/"): + return HostVSCode + case strings.TrimSpace(root) != "": + // Any other plugin folder (a VS Code fork's agentPlugins, JetBrains, Visual Studio, ...) is not VS Code. + return HostOther + } + return HostUnknown +} + +// InVSCode reports whether this hook runs inside VS Code. +func InVSCode() bool { + return PluginHost() == HostVSCode +} + +// TelemetryAgent is the telemetry `agent` value for an event from the given agent name: GitHub Copilot +// inside VS Code is "Copilot-VSCode"; everything else keeps "-cli". +func TelemetryAgent(agent string) string { + if agent != copilotAgent || !InVSCode() { + return agent + "-cli" + } + return agentVSCode +} diff --git a/internal/commands/agenthooks/hostenv/hostenv_test.go b/internal/commands/agenthooks/hostenv/hostenv_test.go new file mode 100644 index 00000000..d45d8a2a --- /dev/null +++ b/internal/commands/agenthooks/hostenv/hostenv_test.go @@ -0,0 +1,72 @@ +//go:build !integration + +package hostenv + +import ( + "testing" +) + +// PLUGIN_ROOT values as the hosts set them (AST-186850 PoC; Windows paths, any user name). +const ( + rootVSCodeFromCLIInstall = `C:\Users\u\AppData\Roaming\Code\agentPlugins\file-c-3A-Users-u-copilot-installed-plugins-cx-devassist-marketplace-cx-devassist\1a15407167c` + rootVSCodeFromMarketplace = `C:\Users\u\AppData\Roaming\Code\agentPlugins\file-c-3A-Users-u-vscode-agent-plugins-marketplace-repositories-github-com-Checkmarx-cx-agentic-ai\1a1542d091b` + rootCLI = `C:\Users\u\.copilot\installed-plugins\cx-devassist-marketplace\cx-devassist` +) + +func useHost(t *testing.T, pluginRoot, integrationID string) { + t.Helper() + t.Setenv("PLUGIN_ROOT", pluginRoot) + t.Setenv("GITHUB_COPILOT_INTEGRATION_ID", integrationID) +} + +func TestPluginHost(t *testing.T) { + cases := []struct { + name, root, integrationID, want string + }{ + {"VS Code copy of a Copilot CLI install", rootVSCodeFromCLIInstall, "", HostVSCode}, + {"VS Code marketplace install", rootVSCodeFromMarketplace, "", HostVSCode}, + {"Linux VS Code", "/home/u/.config/Code/agentPlugins/x/1a", "", HostVSCode}, + {"macOS VS Code Insiders", "/Users/u/Library/Application Support/Code - Insiders/agentPlugins/x/1a", "", HostVSCode}, + {"terminal Copilot CLI", rootCLI, "", HostCLI}, + {"terminal path with the VS Code integration id", rootCLI, "vscode-chat", HostCLI}, + {"Windsurf copy is not VS Code", `C:\Users\u\AppData\Roaming\Windsurf\agentPlugins\x\1a`, "vscode-chat", HostOther}, + {"Cursor copy is not VS Code", "/Users/u/Library/Application Support/Cursor/agentPlugins/x/1a", "", HostOther}, + {"Kiro copy is not VS Code", "/home/u/.config/Kiro/agentPlugins/x/1a", "", HostOther}, + {"terminal path containing agentPlugins by chance", `C:\Users\agentPlugins\.copilot\installed-plugins\m\cx-devassist`, "", HostCLI}, + {"terminal path under an agentPlugins folder", `/home/u/agentPlugins/.copilot/installed-plugins/m/cx-devassist`, "", HostCLI}, + {"other plugin folder (JetBrains, Visual Studio, ...) is not VS Code", `D:\other\plugin`, "vscode-chat", HostOther}, + {"integration id alone is not VS Code", "", "vscode-chat", HostUnknown}, + {"nothing set", "", "", HostUnknown}, + {"other integration id", "", "copilot-developer-cli", HostUnknown}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + useHost(t, tc.root, tc.integrationID) + if got := PluginHost(); got != tc.want { + t.Fatalf("PluginHost() = %q, want %q", got, tc.want) + } + }) + } +} + +func TestTelemetryAgent(t *testing.T) { + cases := []struct { + name, agent, root, want string + }{ + {"terminal Copilot", "Copilot", rootCLI, "Copilot-cli"}, + {"VS Code copy of a Copilot CLI install", "Copilot", rootVSCodeFromCLIInstall, "Copilot-VSCode"}, + {"VS Code marketplace install", "Copilot", rootVSCodeFromMarketplace, "Copilot-VSCode"}, + {"VS Code fork stays -cli", "Copilot", `C:\Users\u\AppData\Roaming\Windsurf\agentPlugins\x\1a`, "Copilot-cli"}, + {"no host signal stays -cli", "Copilot", "", "Copilot-cli"}, + {"other agents unchanged in VS Code", "Claude", rootVSCodeFromCLIInstall, "Claude-cli"}, + {"other agents unchanged", "Cursor", "", "Cursor-cli"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + useHost(t, tc.root, "") + if got := TelemetryAgent(tc.agent); got != tc.want { + t.Fatalf("TelemetryAgent(%q) = %q, want %q", tc.agent, got, tc.want) + } + }) + } +} diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig.go b/internal/commands/agenthooks/scannerconfig/scannerconfig.go index aafaf7b2..2e96c397 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig.go @@ -2,6 +2,11 @@ // ~/.checkmarx/cx-onboarding.properties (seeded by the agent plugins). Every scanner is ENABLED // unless its key is explicitly set to a false-like value, and any read problem also means enabled: // the switches can only narrow what the hooks do, never make them block. +// +// GitHub Copilot agent mode in VS Code has its own state file, +// ~/.checkmarx/cx-onboarding-ide.properties, written by the VS Code extension: the Self-Healing +// switch (cx_self_healing_enabled) and the scanner switches the VS Code settings set. It is read +// only for events from VS Code; the terminal hosts never read it. package scannerconfig import ( @@ -28,18 +33,33 @@ const ( const ( fileName = "cx-onboarding.properties" + // ideFileName is the VS Code extension's state file (see IDEPath). + ideFileName = "cx-onboarding-ide.properties" // maxBytes mirrors the plugins' reader: an oversized file is treated as unreadable (all enabled). maxBytes = 8192 utf8BOM = "\xef\xbb\xbf" + + ideSchemaKey = "cx_schema_version" + ideSchemaVersion = "1" + ideSelfHealingKey = "cx_self_healing_enabled" ) // Path returns ~/.checkmarx/cx-onboarding.properties, or "" when the home directory is unknown. func Path() string { + return homeFile(fileName) +} + +// IDEPath returns ~/.checkmarx/cx-onboarding-ide.properties, or "" when the home directory is unknown. +func IDEPath() string { + return homeFile(ideFileName) +} + +func homeFile(name string) string { home, err := os.UserHomeDir() if err != nil || home == "" { return "" } - return filepath.Join(home, ".checkmarx", fileName) + return filepath.Join(home, ".checkmarx", name) } // Enabled reports whether the scanner is switched on in the user's config file. @@ -55,31 +75,88 @@ func enabledIn(path string, s Scanner) bool { // valueIn returns the last `key=value` for key in the file, or found=false when the file is missing, // unreadable, oversized or does not set the key. Same parsing rules as the plugins' readers. func valueIn(path, key string) (value string, found bool) { - if path == "" { + props, ok := readProps(path) + if !ok { return "", false } + value, found = props[key] + return value, found +} + +// readProps parses the file's `key=value` lines (last occurrence wins, # comments, BOM stripped). +// ok is false when the file is missing, unreadable or oversized. +func readProps(path string) (props map[string]string, ok bool) { + if path == "" { + return nil, false + } f, err := os.Open(path) if err != nil { - return "", false + return nil, false } defer func() { _ = f.Close() }() raw, err := io.ReadAll(io.LimitReader(f, maxBytes+1)) if err != nil || len(raw) > maxBytes { - return "", false + return nil, false } + props = map[string]string{} sc := bufio.NewScanner(strings.NewReader(strings.TrimPrefix(string(raw), utf8BOM))) for sc.Scan() { // last occurrence wins line := strings.TrimSpace(sc.Text()) if line == "" || strings.HasPrefix(line, "#") { continue } - k, v, ok := strings.Cut(line, "=") - if !ok || strings.TrimSpace(k) != key { + k, v, found := strings.Cut(line, "=") + if !found { continue } - value, found = v, true + props[strings.TrimSpace(k)] = v } - return value, found + return props, true +} + +// ideProps returns the VS Code state file's keys when the file is valid: it exists, is readable, is at +// most 8 KB, and its cx_schema_version is absent or 1. An invalid file returns ok=false. +func ideProps(path string) (props map[string]string, ok bool) { + props, ok = readProps(path) + if !ok { + return nil, false + } + if v, set := props[ideSchemaKey]; set && strings.TrimSpace(v) != ideSchemaVersion { + return nil, false + } + return props, true +} + +// SelfHealingEnabled reports whether Checkmarx Self-Healing is on in VS Code. It is OFF only when the +// VS Code state file is valid and cx_self_healing_enabled is a false-like value; a missing, unreadable +// or unknown-schema file, a missing key or any other value means ON. +func SelfHealingEnabled() bool { + return selfHealingIn(IDEPath()) +} + +func selfHealingIn(path string) bool { + props, ok := ideProps(path) + if !ok { + return true + } + v, set := props[ideSelfHealingKey] + return !set || !isFalse(v) +} + +// IDEEnabled is Enabled for events from VS Code: when the VS Code state file is valid its +// cx_*_scanner_enabled keys decide (a missing key means enabled); otherwise it falls back to the +// terminal's ~/.checkmarx/cx-onboarding.properties, exactly like Enabled. +func IDEEnabled(s Scanner) bool { + return ideEnabledIn(IDEPath(), Path(), s) +} + +func ideEnabledIn(idePath, cliPath string, s Scanner) bool { + props, ok := ideProps(idePath) + if !ok { + return enabledIn(cliPath, s) + } + v, set := props[string(s)] + return !set || !isFalse(v) } func isFalse(v string) bool { @@ -103,19 +180,45 @@ func Threshold() int { } func thresholdIn(path string) int { - value, found := valueIn(path, thresholdKey) - if !found { - return 1 - } + value, _ := valueIn(path, thresholdKey) + return thresholdRank(value) +} + +// thresholdRank is the rank of a cx_severity_threshold value; blank or invalid means low (1). +func thresholdRank(value string) int { if rank, ok := severityRank[strings.ToLower(strings.TrimSpace(value))]; ok { return rank } return 1 } +// 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()) +} + +func ideThresholdIn(path string) int { + props, ok := ideProps(path) + if !ok { + return 1 + } + return thresholdRank(props[thresholdKey]) +} + // 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()) +} + +// IDEBelowThreshold is BelowThreshold for events from VS Code, against IDEThreshold. +func IDEBelowThreshold(severity string) bool { + return belowRank(severity, IDEThreshold()) +} + +func belowRank(severity string, threshold int) bool { rank, ok := severityRank[strings.ToLower(strings.TrimSpace(severity))] - return ok && rank < Threshold() + return ok && rank < threshold } diff --git a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go index 3353059f..78aecd9c 100644 --- a/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go +++ b/internal/commands/agenthooks/scannerconfig/scannerconfig_test.go @@ -136,3 +136,131 @@ func TestBelowThreshold(t *testing.T) { t.Error("blank threshold must filter nothing") } } + +func writeIDE(t *testing.T, body string) string { + t.Helper() + p := filepath.Join(t.TempDir(), ideFileName) + if err := os.WriteFile(p, []byte(body), 0o600); err != nil { + t.Fatal(err) + } + return p +} + +func TestSelfHealingIn(t *testing.T) { + cases := []struct { + name string + body string + want bool + }{ + {"key missing is on", "cx_schema_version=1\n", true}, + {"explicit true is on", "cx_self_healing_enabled=true\n", true}, + {"garbage is on", "cx_self_healing_enabled=flase\n", true}, + {"empty value is on", "cx_self_healing_enabled=\n", true}, + {"false is off", "cx_schema_version=1\ncx_self_healing_enabled=false\n", false}, + {"no schema key, off", "cx_self_healing_enabled=false\n", false}, + {"caps / spaces / CRLF / BOM, off", "\xef\xbb\xbfcx_schema_version= 1 \r\ncx_self_healing_enabled= Disabled \r\n", false}, + {"0 / no / off are off", "cx_self_healing_enabled=0\ncx_self_healing_enabled=no\ncx_self_healing_enabled=off\n", false}, + {"last occurrence wins", "cx_self_healing_enabled=false\ncx_self_healing_enabled=true\n", true}, + {"commented key ignored", "# cx_self_healing_enabled=false\n", true}, + {"unknown schema is on", "cx_schema_version=2\ncx_self_healing_enabled=false\n", true}, + {"blank schema is on", "cx_schema_version=\ncx_self_healing_enabled=false\n", true}, + {"oversized is on", strings.Repeat("# pad\n", 5000) + "cx_self_healing_enabled=false\n", true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + if got := selfHealingIn(writeIDE(t, tc.body)); got != tc.want { + t.Fatalf("selfHealingIn(%q) = %v, want %v", tc.body, got, tc.want) + } + }) + } + if !selfHealingIn(filepath.Join(t.TempDir(), "missing")) || !selfHealingIn("") { + t.Error("missing file / path must mean on") + } + if !selfHealingIn(t.TempDir()) { + t.Error("unreadable (directory) must mean on") + } +} + +func TestIDEEnabledIn(t *testing.T) { + cli := write(t, "cx_asca_scanner_enabled=false\n") // terminal: ASCA off, others on + cases := []struct { + name string + ide string // "" = no IDE file + s Scanner + want bool + }{ + {"no IDE file falls back to CLI (off)", "", ASCA, false}, + {"no IDE file falls back to CLI (on)", "", KICS, true}, + {"valid IDE file, key missing is on despite CLI off", "cx_schema_version=1\n", ASCA, true}, + {"valid IDE file, key off", "cx_kics_scanner_enabled=false\n", KICS, false}, + {"valid IDE file, key on", "cx_asca_scanner_enabled=true\n", ASCA, true}, + {"valid IDE file, garbage is on", "cx_sca_scanner_enabled=banana\n", SCA, true}, + {"valid IDE file, secrets off", "cx_secret_scanner_enabled=OFF\n", Secrets, false}, + {"unknown schema falls back to CLI", "cx_schema_version=9\ncx_asca_scanner_enabled=true\n", ASCA, false}, + {"oversized IDE file falls back to CLI", strings.Repeat("# pad\n", 5000), ASCA, false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + ide := filepath.Join(t.TempDir(), "missing") + if tc.ide != "" { + ide = writeIDE(t, tc.ide) + } + if got := ideEnabledIn(ide, cli, tc.s); got != tc.want { + t.Fatalf("ideEnabledIn(%s) = %v, want %v", tc.s, got, tc.want) + } + }) + } +} + +func TestIDEPathUsesHome(t *testing.T) { + dir := t.TempDir() + t.Setenv("HOME", dir) + t.Setenv("USERPROFILE", dir) + if got := IDEPath(); got != filepath.Join(dir, ".checkmarx", "cx-onboarding-ide.properties") { + t.Errorf("unexpected path %q", got) + } + if !SelfHealingEnabled() || !IDEEnabled(ASCA) { + t.Error("no files under home must mean on") + } + _ = os.MkdirAll(filepath.Join(dir, ".checkmarx"), 0o755) + _ = os.WriteFile(IDEPath(), []byte("cx_self_healing_enabled=false\ncx_kics_scanner_enabled=false\n"), 0o600) + if SelfHealingEnabled() || IDEEnabled(KICS) || !IDEEnabled(ASCA) { + t.Error("SelfHealingEnabled / IDEEnabled should read the IDE file under the user's home") + } + if !Enabled(KICS) { + t.Error("Enabled (terminal) must never read the IDE file") + } +} + +func TestIDEThresholdIn(t *testing.T) { + cases := map[string]int{ + "cx_schema_version=1\n": 1, // VS Code writes no threshold: low + "cx_severity_threshold=high\n": 3, + "cx_schema_version=1\ncx_severity_threshold=\n": 1, // blank + "cx_severity_threshold=hihg\n": 1, // invalid + "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 { + t.Errorf("%q: got %d, want %d", body, got, want) + } + } + if ideThresholdIn(filepath.Join(t.TempDir(), "missing")) != 1 || ideThresholdIn("") != 1 { + t.Error("missing IDE file / path must mean low") + } +} + +func TestIDEBelowThresholdIgnoresTerminalThreshold(t *testing.T) { + dir := t.TempDir() + t.Setenv("HOME", dir) + t.Setenv("USERPROFILE", dir) + _ = 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") { + 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)") + } +} From f51009f9e66fabd6ea30bf67f3736523df915988 Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Fri, 30 Oct 2026 21:04:05 +0530 Subject: [PATCH 2/9] AST-180812 - Detect VS Code Copilot CLI sessions from GITHUB_COPILOT_INTEGRATION_ID (#1604) --- internal/commands/agenthooks/hostenv/hostenv.go | 12 ++++++++++-- internal/commands/agenthooks/hostenv/hostenv_test.go | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/commands/agenthooks/hostenv/hostenv.go b/internal/commands/agenthooks/hostenv/hostenv.go index 301af4d1..515afcdb 100644 --- a/internal/commands/agenthooks/hostenv/hostenv.go +++ b/internal/commands/agenthooks/hostenv/hostenv.go @@ -20,6 +20,9 @@ const ( // copilotAgent is the agent name the hook handlers use for GitHub Copilot (see cx.agentToString). const copilotAgent = "Copilot" +// VSCodeIntegrationID is the GITHUB_COPILOT_INTEGRATION_ID VS Code sets on the Copilot CLI engine it bundles. +const VSCodeIntegrationID = "vscode-chat" + // agentVSCode is the telemetry agent label for GitHub Copilot inside VS Code. The terminal keeps "-cli". const agentVSCode = "Copilot-VSCode" @@ -30,7 +33,9 @@ const agentVSCode = "Copilot-VSCode" // likewise), whether the plugin was installed by the Copilot CLI or from VS Code's marketplace; the // terminal Copilot CLI (also when started in VS Code's integrated terminal) runs it from // ~/.copilot/installed-plugins/. Hashes and user names in the path are ignored. Any other PLUGIN_ROOT -// (a VS Code fork, JetBrains, Visual Studio, ...) is HostOther; no PLUGIN_ROOT is HostUnknown. +// (a VS Code fork, JetBrains, Visual Studio, ...) is HostOther. Only when PLUGIN_ROOT is not set at all +// does GITHUB_COPILOT_INTEGRATION_ID=vscode-chat mark VS Code (VS Code's Copilot CLI chat sessions); +// otherwise no PLUGIN_ROOT is HostUnknown. func PluginHost() string { root := strings.ToLower(strings.ReplaceAll(os.Getenv("PLUGIN_ROOT"), `\`, "/")) // The terminal marker is checked first: VS Code's folder names encode the source path with dashes @@ -43,8 +48,11 @@ func PluginHost() string { case strings.Contains(root, "/code/agentplugins/"), strings.Contains(root, "/code - insiders/agentplugins/"): return HostVSCode case strings.TrimSpace(root) != "": - // Any other plugin folder (a VS Code fork's agentPlugins, JetBrains, Visual Studio, ...) is not VS Code. + // Any other plugin folder (a VS Code fork's agentPlugins, JetBrains, Visual Studio, ...) is not + // VS Code, and the fallback below must not override that. return HostOther + case strings.TrimSpace(os.Getenv("GITHUB_COPILOT_INTEGRATION_ID")) == VSCodeIntegrationID: + return HostVSCode } return HostUnknown } diff --git a/internal/commands/agenthooks/hostenv/hostenv_test.go b/internal/commands/agenthooks/hostenv/hostenv_test.go index d45d8a2a..d27ba3d7 100644 --- a/internal/commands/agenthooks/hostenv/hostenv_test.go +++ b/internal/commands/agenthooks/hostenv/hostenv_test.go @@ -35,7 +35,8 @@ func TestPluginHost(t *testing.T) { {"terminal path containing agentPlugins by chance", `C:\Users\agentPlugins\.copilot\installed-plugins\m\cx-devassist`, "", HostCLI}, {"terminal path under an agentPlugins folder", `/home/u/agentPlugins/.copilot/installed-plugins/m/cx-devassist`, "", HostCLI}, {"other plugin folder (JetBrains, Visual Studio, ...) is not VS Code", `D:\other\plugin`, "vscode-chat", HostOther}, - {"integration id alone is not VS Code", "", "vscode-chat", HostUnknown}, + {"VS Code Copilot CLI session (integration id, no PLUGIN_ROOT)", "", "vscode-chat", HostVSCode}, + {"integration id with surrounding spaces", "", " vscode-chat ", HostVSCode}, {"nothing set", "", "", HostUnknown}, {"other integration id", "", "copilot-developer-cli", HostUnknown}, } From b773cb4fa6fd1ae17765c299c451e90628d90910 Mon Sep 17 00:00:00 2001 From: Rahul Pidde <206018639+cx-rahul-pidde@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:08:26 +0530 Subject: [PATCH 3/9] Feature/ast 180812 vscode copilot cli host (#1607) --- .../commands/agenthooks/hostenv/hostenv.go | 18 ++++++++++--- .../agenthooks/hostenv/hostenv_test.go | 25 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/internal/commands/agenthooks/hostenv/hostenv.go b/internal/commands/agenthooks/hostenv/hostenv.go index 515afcdb..c00641bc 100644 --- a/internal/commands/agenthooks/hostenv/hostenv.go +++ b/internal/commands/agenthooks/hostenv/hostenv.go @@ -23,6 +23,11 @@ const copilotAgent = "Copilot" // VSCodeIntegrationID is the GITHUB_COPILOT_INTEGRATION_ID VS Code sets on the Copilot CLI engine it bundles. const VSCodeIntegrationID = "vscode-chat" +// pluginHostEnv is set by the cx-devassist Copilot plugin's hooks/cx_run.sh to "vscode" when its own host +// check (which also reads the process tree) finds VS Code. VS Code's Copilot CLI chat sessions run the +// plugin from ~/.copilot/installed-plugins/, the terminal's folder, so PLUGIN_ROOT alone cannot tell. +const pluginHostEnv = "CX_COPILOT_HOST" + // agentVSCode is the telemetry agent label for GitHub Copilot inside VS Code. The terminal keeps "-cli". const agentVSCode = "Copilot-VSCode" @@ -33,17 +38,22 @@ const agentVSCode = "Copilot-VSCode" // likewise), whether the plugin was installed by the Copilot CLI or from VS Code's marketplace; the // terminal Copilot CLI (also when started in VS Code's integrated terminal) runs it from // ~/.copilot/installed-plugins/. Hashes and user names in the path are ignored. Any other PLUGIN_ROOT -// (a VS Code fork, JetBrains, Visual Studio, ...) is HostOther. Only when PLUGIN_ROOT is not set at all -// does GITHUB_COPILOT_INTEGRATION_ID=vscode-chat mark VS Code (VS Code's Copilot CLI chat sessions); -// otherwise no PLUGIN_ROOT is HostUnknown. +// (a VS Code fork, JetBrains, Visual Studio, ...) is HostOther. When PLUGIN_ROOT is under +// ~/.copilot/installed-plugins/ or not set, CX_COPILOT_HOST=vscode (from the plugin) marks VS Code. Only +// when PLUGIN_ROOT is not set at all does GITHUB_COPILOT_INTEGRATION_ID=vscode-chat mark VS Code too +// (VS Code's Copilot CLI chat sessions); otherwise no PLUGIN_ROOT is HostUnknown. func PluginHost() string { root := strings.ToLower(strings.ReplaceAll(os.Getenv("PLUGIN_ROOT"), `\`, "/")) + pluginSaysVSCode := strings.EqualFold(strings.TrimSpace(os.Getenv(pluginHostEnv)), HostVSCode) // The terminal marker is checked first: VS Code's folder names encode the source path with dashes // (…-copilot-installed-plugins-…), so they never contain it, while a terminal path could contain // "agentPlugins" by chance (a user or folder name). Only VS Code's own user-data folder ("Code", // "Code - Insiders") counts: VS Code forks keep their agentPlugins copies under their own folder. switch { case strings.Contains(root, "/.copilot/installed-plugins/"): + if pluginSaysVSCode { + return HostVSCode + } return HostCLI case strings.Contains(root, "/code/agentplugins/"), strings.Contains(root, "/code - insiders/agentplugins/"): return HostVSCode @@ -51,7 +61,7 @@ func PluginHost() string { // Any other plugin folder (a VS Code fork's agentPlugins, JetBrains, Visual Studio, ...) is not // VS Code, and the fallback below must not override that. return HostOther - case strings.TrimSpace(os.Getenv("GITHUB_COPILOT_INTEGRATION_ID")) == VSCodeIntegrationID: + case pluginSaysVSCode, strings.TrimSpace(os.Getenv("GITHUB_COPILOT_INTEGRATION_ID")) == VSCodeIntegrationID: return HostVSCode } return HostUnknown diff --git a/internal/commands/agenthooks/hostenv/hostenv_test.go b/internal/commands/agenthooks/hostenv/hostenv_test.go index d27ba3d7..df4fa597 100644 --- a/internal/commands/agenthooks/hostenv/hostenv_test.go +++ b/internal/commands/agenthooks/hostenv/hostenv_test.go @@ -17,6 +17,7 @@ func useHost(t *testing.T, pluginRoot, integrationID string) { t.Helper() t.Setenv("PLUGIN_ROOT", pluginRoot) t.Setenv("GITHUB_COPILOT_INTEGRATION_ID", integrationID) + t.Setenv(pluginHostEnv, "") } func TestPluginHost(t *testing.T) { @@ -50,6 +51,30 @@ func TestPluginHost(t *testing.T) { } } +func TestPluginHostFromPlugin(t *testing.T) { + cases := []struct { + name, root, pluginHost, want string + }{ + {"VS Code Copilot CLI session from the terminal's folder", rootCLI, "vscode", HostVSCode}, + {"plugin value is trimmed and case-insensitive", rootCLI, " VSCode ", HostVSCode}, + {"terminal Copilot CLI (plugin leaves it unset)", rootCLI, "", HostCLI}, + {"other plugin value is ignored", rootCLI, "cli", HostCLI}, + {"no PLUGIN_ROOT", "", "vscode", HostVSCode}, + {"VS Code copy stays VS Code", rootVSCodeFromCLIInstall, "", HostVSCode}, + {"VS Code fork is never VS Code", `C:\Users\u\AppData\Roaming\Windsurf\agentPlugins\x\1a`, "vscode", HostOther}, + {"other plugin folder is never VS Code", `D:\other\plugin`, "vscode", HostOther}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + useHost(t, tc.root, "") + t.Setenv(pluginHostEnv, tc.pluginHost) + if got := PluginHost(); got != tc.want { + t.Fatalf("PluginHost() = %q, want %q", got, tc.want) + } + }) + } +} + func TestTelemetryAgent(t *testing.T) { cases := []struct { name, agent, root, want string From 0e0237d0cbecf02d33b46da65ef932fffc2283f8 Mon Sep 17 00:00:00 2001 From: Anurag Dalke Date: Thu, 5 Nov 2026 16:25:20 +0530 Subject: [PATCH 4/9] Update brotli dependency to v1.2.7 (AST-189161) (#1610) * Update github.com/andybalholm/brotli from v1.2.0 to v1.2.7 (AST-189161) Indirect dependency pulled in via anchore/syft -> anchore/archiver. No API removals; archiver only uses NewWriterLevel/NewReader, which are unchanged. Co-Authored-By: Claude Fable 5.1 * Update Docker base image checkmarx/bash:5.3 to latest digest (AST-189161) Bumps the SHA256-pinned base image to the 5.3-r14 build pushed on 2026-11-04. Co-Authored-By: Claude Fable 5.1 * Replace .trivyignore entries with current binary findings (AST-189161) Ignore GO-2026-5932 (x/crypto/openpgp via helm provenance), CVE-2026-78661 and CVE-2026-97045 (x/net/html via syft Maven cataloger). Remove the previous Wolfi base-image and syft/docker entries, which no longer apply. Co-Authored-By: Claude Fable 5.1 * Restore syft and docker entries in .trivyignore (AST-189161) CVE-2026-33481 (syft temp cleanup) and CVE-2026-33997 (moby plugin privilege bypass) are still reported against the binary. Neither has an adoptable fix: syft >= 1.42.3 reintroduces the binary-size regression reverted in AST-188320 and docker/docker has no 29.x release on its module path. Justifications and reachability analysis are recorded in the file. Co-Authored-By: Claude Fable 5.1 * Bump golang.org/x/net to v0.62.0 and trim .trivyignore (AST-189161) Bump the indirect golang.org/x/net dependency to v0.62.0, which fixes CVE-2026-78661 and CVE-2026-97045, so their ignore entries are dropped. Keep only the ignores that cannot be fixed directly: GO-2026-5932 (x/crypto openpgp, via helm), CVE-2026-33481 (syft) and CVE-2026-33997 (docker). Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Claude Fable 5.1 Co-authored-by: atishj99 --- .trivyignore | 51 +++++++++++---------------------------------------- Dockerfile | 2 +- go.mod | 4 ++-- go.sum | 8 ++++---- 4 files changed, 18 insertions(+), 47 deletions(-) diff --git a/.trivyignore b/.trivyignore index 58ab2c14..cd0e4ebc 100644 --- a/.trivyignore +++ b/.trivyignore @@ -1,44 +1,6 @@ # Trivy Ignore Configuration -# These vulnerabilities are in the Wolfi Linux base image or have compatibility issues - -# ============================================================================ -# BASE IMAGE VULNERABILITIES (Wolfi) - Cannot be patched by CLI code -# ============================================================================ - -# CVE-2026-8674: glibc DNS stub resolver DoS via long search domain -# Severity: MEDIUM -# Component: zlib 1.3.2-r6 (in Wolfi base image) -# Impact: Local DNS parsing issue - requires malformed DNS configuration -# Reason: Base image vulnerability - awaiting Wolfi update to zlib 1.3.2.1_rc20260601-r0 -CVE-2026-8674 - -# CVE-2026-86805: glibc TOCTOU privilege escalation -# Severity: MEDIUM -# Component: glibc 2.44-r7 (in base image) -# Impact: Local attacker with file system access - requires race condition exploit -# Reason: Base image vulnerability - awaiting Wolfi update to glibc 2.44-r8 -CVE-2026-86805 - -# CVE-2026-89092: glibc nscd stack overflow -# Severity: MEDIUM -# Component: glibc 2.44-r7 (in base image) -# Impact: Local DoS via nscd service - requires nscd to be running -# Reason: Base image vulnerability - awaiting Wolfi update to glibc 2.44-r8 -CVE-2026-89092 - -# CVE-2026-95818: glibc local DoS and information disclosure -# Severity: MEDIUM -# Component: glibc 2.44-r7 (in base image) -# Impact: Local attacker can cause denial of service -# Reason: Base image vulnerability - awaiting Wolfi update to glibc 2.44-r8 -CVE-2026-95818 - -# CVE-2026-85091: zlib heap buffer overflow -# Severity: MEDIUM -# Component: zlib 1.3.2-r6 (in Wolfi base image) -# Impact: Heap buffer overflow in compression library -# Reason: Base image vulnerability - awaiting Wolfi update to 1.3.2.1_rc20260601-r0 -CVE-2026-85091 +# These vulnerabilities are in Go dependencies that cannot be updated or fixed directly. +# Review periodically and remove entries once the underlying dependency is upgraded. # ============================================================================ # BINARY VULNERABILITIES - Compatibility Issues (Not Updated) @@ -62,3 +24,12 @@ CVE-2026-33481 # Docker plugin system - uses only core Docker SDK for container scanning. # Status: Risk accepted - vulnerability not exploitable in CLI usage pattern CVE-2026-33997 + +# GO-2026-5932: golang.org/x/crypto/openpgp is unmaintained and unsafe by design +# Severity: UNKNOWN +# Component: golang.org/x/crypto v0.58.0 (transitive via helm.sh/helm/v3/pkg/provenance) +# Reason: Not imported by ast-cli directly; the "fixed" version is an untagged pseudo-version. +# Awaiting Helm to drop x/crypto/openpgp. +# Impact: CLI does not perform OpenPGP signing/verification. +# Status: Risk accepted +GO-2026-5932 diff --git a/Dockerfile b/Dockerfile index 04f46d28..2c4c92c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM checkmarx/bash:5.3-r14-365aa4c3c7b3fc@sha256:365aa4c3c7b3fcb580687c427e90ee9cda26e75cd12cae3a2b521777c0b4d3f3 +FROM checkmarx/bash:5.3-r14-e52a196c3a914c@sha256:e52a196c3a914c6496c72465ad4a8f7efd1ff8ad988b328cbb92018652c23c7d USER nonroot COPY cx /app/bin/cx diff --git a/go.mod b/go.mod index 14f990e9..ae7728e6 100644 --- a/go.mod +++ b/go.mod @@ -102,7 +102,7 @@ require ( github.com/anchore/packageurl-go v0.1.1-0.20250220190351-d62adb6e1115 // indirect github.com/anchore/stereoscope v0.1.0 // indirect github.com/anchore/syft v1.21.0 // indirect - github.com/andybalholm/brotli v1.2.0 // indirect + github.com/andybalholm/brotli v1.2.7 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/aquasecurity/go-pep440-version v0.0.1 // indirect github.com/aquasecurity/go-version v0.0.1 // indirect @@ -296,7 +296,7 @@ require ( go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f // indirect golang.org/x/mod v0.41.0 // indirect - golang.org/x/net v0.60.0 // indirect + golang.org/x/net v0.62.0 // indirect golang.org/x/oauth2 v0.36.0 // indirect golang.org/x/sys v0.49.0 // indirect golang.org/x/term v0.47.0 // indirect diff --git a/go.sum b/go.sum index daf8984b..93a24450 100644 --- a/go.sum +++ b/go.sum @@ -151,8 +151,8 @@ github.com/anchore/stereoscope v0.1.0/go.mod h1:3vasimie0IJOXvMbMpjwvwIHBDA1+192 github.com/anchore/syft v1.21.0 h1:JHmYOnEbCJsElROCCfg+3oIODw1LQLfXGkIrmXNZYsI= github.com/anchore/syft v1.21.0/go.mod h1:8i8Yp/MiSOdqID0+6eiwE9bOJWM7fEBYitINZyr2G6s= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= -github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ= -github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= +github.com/andybalholm/brotli v1.2.7 h1:UgafRPGMam5ySHfRkhthMqOFA6IFoeF3D7mWIDLjG5A= +github.com/andybalholm/brotli v1.2.7/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -1201,8 +1201,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU= -golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= +golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= +golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= From 57638a2a6273dc6fa8c8b6d2f53b03956a364cff Mon Sep 17 00:00:00 2001 From: Sumit Morchhale Date: Thu, 5 Nov 2026 16:26:01 +0530 Subject: [PATCH 5/9] revret exclude git config changes (#1609) Co-authored-by: Aniket Shinde --- internal/commands/scan.go | 14 -------------- internal/params/filters.go | 5 ----- 2 files changed, 19 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 1b742412..37931d16 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -1821,20 +1821,6 @@ func addDirFilesIgnoreFilter(zipWriter *zip.Writer, baseDir, parentDir string) e err = addDirFilesIgnoreFilter(zipWriter, newBase, newParent) } else { fileName := parentDir + file.Name() - relPath := filepath.ToSlash(baseDir + file.Name()) - - excluded := false - for _, pattern := range commonParams.BaseExcludedFiles { - if relPath == pattern || strings.HasSuffix(relPath, pattern) { - excluded = true - logger.PrintIfVerbose("Excluded: " + fileName) - break - } - } - if excluded { - continue - } - logger.PrintIfVerbose("Included: " + fileName) dat, _ := ioutil.ReadFile(fileName) diff --git a/internal/params/filters.go b/internal/params/filters.go index 7536621b..65b1aee4 100644 --- a/internal/params/filters.go +++ b/internal/params/filters.go @@ -203,11 +203,6 @@ var BaseExcludeFilters = []string{ "!node_modules", } -// BaseExcludedFiles defines the base set of files to exclude from ZIP archives during scans. -var BaseExcludedFiles = []string{ - ".git/config", -} - var KicsBaseFilters = []string{ ".tf", ".yaml", From 8c15dca64c10ddefb25d9adbe9e1cb77c217c32b Mon Sep 17 00:00:00 2001 From: atishj99 Date: Thu, 5 Nov 2026 16:38:47 +0530 Subject: [PATCH 6/9] Use self-repository syntax for reusable workflow in nightly-parallel (AST-189161) Replace `uses: ./.github/workflows/ci-tests.yml` with the `$/` form to satisfy the zizmor `self-repository` audit (added in zizmor v1.30.0). Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/nightly-parallel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly-parallel.yml b/.github/workflows/nightly-parallel.yml index 77bc9eea..4f6c38e0 100644 --- a/.github/workflows/nightly-parallel.yml +++ b/.github/workflows/nightly-parallel.yml @@ -18,6 +18,6 @@ permissions: jobs: integration-tests: # zizmor: ignore[anonymous-definition] - uses: ./.github/workflows/ci-tests.yml + uses: $/.github/workflows/ci-tests.yml # ci-tests.yml requires ~20 CX/SCM secrets; it's a same-repo reusable workflow, not a fork/third-party target. secrets: inherit # zizmor: ignore[secrets-inherit] From e3250aa5d80d0bd70df3f9d6164363a54aaf2875 Mon Sep 17 00:00:00 2001 From: Sumit Morchhale Date: Wed, 11 Nov 2026 21:43:24 +0530 Subject: [PATCH 7/9] Handle missing feature flags(AST-188568) (#1613) * Handle missing feature flags gracefully (code 100 response) When the API returns a 404 with error code 100 and message "flag with the given name is not found", return a disabled flag model instead of nil to prevent nil pointer dereference panics in calling code. Missing flags are treated as enabled (default) to ensure safe feature flag fallback behavior. Fixes panic: runtime error: invalid memory address or nil pointer dereference when GetSpecificFlag is called and the flag doesn't exist on the server. * Refactor: use existing WebError struct instead of inline type Replace inline error response struct with the existing WebError struct from ast.go for consistency with the rest of the codebase. This improves maintainability and follows the established pattern in wrappers like bfl-http.go and codebashing-http.go. * handle remove ff * Remove INCREASE_FILE_UPLOAD_LIMIT flag - now always enabled for large files Removed the INCREASE_FILE_UPLOAD_LIMIT feature flag that controlled multipart uploads. The flag is now permanently enabled - files > 5GB always use multipart upload, smaller files use single upload. This simplifies the code by removing the flag check and associated tests. Changes: - Removed flag constant from feature-flags.go - Updated scan.go to always check file size (no flag check) - Consolidated 5 tests to 3 tests (removed redundant flag-based tests) - Behavior unchanged: multipart for >5GB, single for <=5GB No regression - functionality preserved, code simplified. * removed status code handling * updated docker image --------- Co-authored-by: Anurag Dalke <120229307+cx-anurag-dalke@users.noreply.github.com> --- Dockerfile | 8 +++---- internal/commands/scan.go | 3 +-- internal/commands/scan_test.go | 37 +++--------------------------- internal/wrappers/feature-flags.go | 1 - 4 files changed, 8 insertions(+), 41 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c4c92c7..3b0ef2e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM checkmarx/bash:5.3-r14-e52a196c3a914c@sha256:e52a196c3a914c6496c72465ad4a8f7efd1ff8ad988b328cbb92018652c23c7d +FROM checkmarx/bash:5.3-r14-fad83378373438@sha256:fad833783734389f27b9d8ab3b5e9dda6eb44fdf1892145c70058cb774da817d USER nonroot -COPY cx /app/bin/cx - -ENTRYPOINT ["/app/bin/cx"] +COPY cx /app/bin/cx + +ENTRYPOINT ["/app/bin/cx"] HEALTHCHECK NONE diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 37931d16..816e3dc7 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -2565,8 +2565,7 @@ func uploadZip(uploadsWrapper wrappers.UploadsWrapper, zipFilePath string, unzip } logger.PrintIfVerbose(fmt.Sprintf("Zip size before upload: %.2fMB\n", float64(fileInfo.Size())/mbBytes)) - flagResponse, _ := featureFlagsWrapper.GetSpecificFlag(wrappers.IncreaseFileUploadLimit) - if flagResponse.Status && fileInfo.Size() > MaxSizeBytes { + if fileInfo.Size() > MaxSizeBytes { logger.PrintIfVerbose("Uploading source code in multiple parts.") preSignedURL, zipFilePathErr = uploadsWrapper.UploadFileInMultipart(zipFilePath, featureFlagsWrapper) } else { diff --git a/internal/commands/scan_test.go b/internal/commands/scan_test.go index 76037be0..fadd433a 100644 --- a/internal/commands/scan_test.go +++ b/internal/commands/scan_test.go @@ -4913,12 +4913,11 @@ func TestEnforceLocalResolutionForTarFiles_Integration(t *testing.T) { } } -func TestUploadZip_AsMultipartUpload_when_FF_Enable_ZIP_Exceeds_5GB(t *testing.T) { +func TestUploadZip_AsMultipartUpload_when_ZIP_Exceeds_5GB(t *testing.T) { // Simulate a file size > 5GB by setting MaxSizeBytes to less than actual size MaxSizeBytes = 1 defer func() { MaxSizeBytes = 5 * 1024 * 1024 * 1024 }() // Reset after test uploadWrapper := mock.UploadsMockWrapper{} - mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.IncreaseFileUploadLimit, Status: true} featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{} url, zipPath, err := uploadZip(&uploadWrapper, "data/sources.zip", false, true, featureFlagsWrapper) assert.NilError(t, err) @@ -4926,37 +4925,8 @@ func TestUploadZip_AsMultipartUpload_when_FF_Enable_ZIP_Exceeds_5GB(t *testing.T assert.Equal(t, url, "multiPart/path/to/nowhere") } -func TestUploadZip_AsMultipartUpload_when_FF_Disable_ZIP_Exceeds_5GB(t *testing.T) { - fileInfo, err := os.Stat("data/sources.zip") - if err != nil { - t.Fatalf("Failed to close zip file: %v", err) - } - // Simulate a file size > 5GB by setting MaxSizeBytes to less than actual size - MaxSizeBytes = fileInfo.Size() - 1 - defer func() { MaxSizeBytes = 5 * 1024 * 1024 * 1024 }() // Reset after test - - uploadWrapper := mock.UploadsMockWrapper{} - mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.IncreaseFileUploadLimit, Status: false} - featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{} - url, zipPath, err := uploadZip(&uploadWrapper, "data/sources.zip", false, true, featureFlagsWrapper) - assert.NilError(t, err) - assert.Equal(t, zipPath, "") - assert.Equal(t, url, "singlePart/path/to/nowhere") -} - -func TestUploadZip_AsMultipartUpload_when_FF_Enable_ZIP_LessThan_5GB(t *testing.T) { - uploadWrapper := mock.UploadsMockWrapper{} - mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.IncreaseFileUploadLimit, Status: true} - featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{} - url, zipPath, err := uploadZip(&uploadWrapper, "data/sources.zip", false, true, featureFlagsWrapper) - assert.NilError(t, err) - assert.Equal(t, zipPath, "") - assert.Equal(t, url, "singlePart/path/to/nowhere") -} - -func TestUploadZip_AsMultipartUpload_when_FF_Disable_ZIP_LessThan_5GB(t *testing.T) { +func TestUploadZip_AsSingleUpload_when_ZIP_LessThan_5GB(t *testing.T) { uploadWrapper := mock.UploadsMockWrapper{} - mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.IncreaseFileUploadLimit, Status: false} featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{} url, zipPath, err := uploadZip(&uploadWrapper, "data/sources.zip", false, true, featureFlagsWrapper) assert.NilError(t, err) @@ -4964,7 +4934,7 @@ func TestUploadZip_AsMultipartUpload_when_FF_Disable_ZIP_LessThan_5GB(t *testing assert.Equal(t, url, "singlePart/path/to/nowhere") } -func TestUploadZip_AsMultipartUpload_when_FF_Enable_ZIP_Exceeds_5GB_Error(t *testing.T) { +func TestUploadZip_AsMultipartUpload_when_ZIP_Exceeds_5GB_Error(t *testing.T) { // Create a temporary zip file dir := t.TempDir() zipPathTemp := filepath.Join(dir, "failureCaseLarge.zip") @@ -4998,7 +4968,6 @@ func TestUploadZip_AsMultipartUpload_when_FF_Enable_ZIP_Exceeds_5GB_Error(t *tes defer func() { MaxSizeBytes = 5 * 1024 * 1024 * 1024 }() // uploadWrapper := mock.UploadsMockWrapper{} - mock.Flag = wrappers.FeatureFlagResponseModel{Name: wrappers.IncreaseFileUploadLimit, Status: true} featureFlagsWrapper := &mock.FeatureFlagsMockWrapper{} _, zipPath, err := uploadZip(&uploadWrapper, zipPathTemp, false, true, featureFlagsWrapper) assert.Assert(t, err != nil) diff --git a/internal/wrappers/feature-flags.go b/internal/wrappers/feature-flags.go index c4008f64..6831f277 100644 --- a/internal/wrappers/feature-flags.go +++ b/internal/wrappers/feature-flags.go @@ -19,7 +19,6 @@ const SscsCommitHistoryEnabled = "SSCS_COMMIT_HISTORY_ENABLED" const DirectAssociationEnabled = "DIRECT_APP_ASSOCIATION_ENABLED" const DaMigrationEnabled = "DA_MIGRATION_ENABLED" const maxRetries = 3 -const IncreaseFileUploadLimit = "INCREASE_FILE_UPLOAD_LIMIT" const ScaDeltaScanEnabled = "SCA_DELTASCAN_ENABLED" // RepostoreCustomerContributorsCsvEnabled is the feature flag for generating contributors.csv and metadata.json. From 074b99763cb100bce356122ef3455de7757936bd Mon Sep 17 00:00:00 2001 From: Sumit Morchhale Date: Thu, 12 Nov 2026 08:46:07 +0530 Subject: [PATCH 8/9] Undo merge conflict resolution commit This removes the problematic merge commit a1df4b17 that resolved the Dockerfile conflict. Going back to the clean state before that merge attempt. All code is preserved - reverting to e3250aa5 state. Co-Authored-By: Claude Haiku 4.5 From 25dc71dec277d7eb4b5ee77e17ef8579e349b301 Mon Sep 17 00:00:00 2001 From: Aniket Shinde Date: Thu, 12 Nov 2026 12:30:40 +0530 Subject: [PATCH 9/9] Ignore glibc CVE-2026-84243 and Go stdlib CVE-2026-97054 in Trivy Both are newly disclosed. glibc comes from the checkmarx/bash base image (fix in 2.44-r16, no rebuilt image yet); stdlib is fixed in Go 1.26.11. Remove once the base image is rebuilt and the Go toolchain is bumped. Co-Authored-By: Claude Sonnet 5.5 --- .trivyignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.trivyignore b/.trivyignore index cd0e4ebc..ced74e1b 100644 --- a/.trivyignore +++ b/.trivyignore @@ -33,3 +33,22 @@ CVE-2026-33997 # Impact: CLI does not perform OpenPGP signing/verification. # Status: Risk accepted GO-2026-5932 + +# ============================================================================ +# NEWLY DISCLOSED - Waiting on upstream fix +# ============================================================================ + +# CVE-2026-84243: glibc arbitrary code execution via directory traversal in LANGUAGE env var +# Severity: MEDIUM +# Component: glibc, glibc-2.44-locale-posix, ld-linux, libcrypt1 (checkmarx/bash base image) +# Current Version: 2.44-r14 (fixed in 2.44-r16) +# Reason: OS package inside the checkmarx/bash base image; no newer image is published yet. +# Status: Temporary ignore - remove once the base image is rebuilt with glibc >= 2.44-r16 +CVE-2026-84243 + +# CVE-2026-97054: Go stdlib net/http HTTP/1 MaxBytesReader limit handling +# Severity: UNKNOWN +# Component: stdlib (Go v1.26.10) +# Reason: Fixed in Go 1.26.11 / 1.27.4. +# Status: Temporary ignore - remove once go.mod / CI toolchain is bumped to Go >= 1.26.11 +CVE-2026-97054