Skip to content

AST-164154: Fix KICS agent-hook guardrail never scanning (empty container engine)- #1528 #1528 - #1531

Open
cx-anurag-dalke wants to merge 4 commits into
other/release_2_3_59from
fix/kics-hook-container-engine-detection
Open

AST-164154: Fix KICS agent-hook guardrail never scanning (empty container engine)- #1528 #1528#1531
cx-anurag-dalke wants to merge 4 commits into
other/release_2_3_59from
fix/kics-hook-container-engine-detection

Conversation

@cx-anurag-dalke

Copy link
Copy Markdown
Contributor

Description
The KICS agent-hook guardrail (used by AI-agent plugins like Claude Code via cx hooks claude-pre-file-write) was passing an empty container engine name ("") to RunIacRealtimeScan instead of a real engine like "docker". This caused container-engine resolution to fail on every invocation, and because ScanFileEdit fails open on scan errors, the guardrail silently allowed every IaC file edit without ever actually running KICS — with no visible error or log output under normal operation.

Verified live: with the bug, writing a Terraform file with an obviously public S3 bucket ACL was silently allowed. After the fix, the same write is correctly denied with full KICS findings and remediation guidance.

Changes
internal/commands/agenthooks/guardrails/kics/scanner.go: Resolve the container engine via, in order: CX_HOOKS_CONTAINER_ENGINE env var override → PATH auto-detection (docker then podman) → "docker" fallback default (matching the existing --engine flag default on cx scan iac-realtime). This also gives Podman-only users a working path, since the guardrail has no CLI flag surface to read --engine from (it's invoked as cx hooks with only stdin JSON).
internal/commands/agenthooks/guardrails/kics/kics.go: Added --debug-gated logging (logger.PrintfIfVerbose) at the previously-silent fail-open branches (both svc.scan error paths, and the panic-recovery deferred func), so a future regression in this path is diagnosable instead of invisible.
internal/params/envs.go: Added HooksContainerEngineEnv = "CX_HOOKS_CONTAINER_ENGINE" constant.
internal/commands/agenthooks/guardrails/kics/scanner_test.go: New unit tests for the engine-resolution priority order (env override wins, auto-detects from PATH, falls back to default when nothing resolves).

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Related Issues

Link any related issues or tickets.

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules
  • I have updated the CLI help for new/changed functionality in this PR (if applicable)
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used

Screenshots (if applicable)

Add screenshots to help explain your changes.

Additional Notes

Add any other relevant information.

cx-avi-sabzerou and others added 4 commits July 23, 2026 16:00
…iner engine)

The KICS file-edit guardrail passed an empty container engine name to
RunIacRealtimeScan instead of "docker", causing engine resolution to
always fail and the scan to silently fail open on every file edit.
Now resolves the engine via CX_HOOKS_CONTAINER_ENGINE override, then
PATH auto-detection (docker/podman), falling back to "docker". Also
logs the swallowed scan errors via --debug so a future regression here
is diagnosable instead of silently invisible.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Dockerfile and docker-compose findings were sent through codeRemediation
like any other IaC misconfiguration, but they need imageRemediation for
base-image CVEs/hardening. Route by KICS's own platform field on the
finding (Dockerfile/DockerCompose), falling back to filename heuristics
only when platform metadata is unavailable.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@stepsecurity-app

Copy link
Copy Markdown
Contributor

Security Policy Alert: Secret Policy Violation

This workflow run has been blocked by StepSecurity's secrets policy because it accesses secrets and the workflow file differs from the default branch.

Secret references detected:

  • secrets.AST_RND_SCANS_BASE_URI at line 27
  • secrets.AST_RND_SCANS_TENANT at line 28
  • secrets.AST_RND_SCANS_CLIENT_ID at line 29
  • secrets.AST_RND_SCANS_CLIENT_SECRET at line 30

To approve this workflow, please add the workflows-approved label to this PR.

Note: The label must be added by someone other than the PR author (cx-anurag-dalke) or automation bots to ensure proper security review.

After the label is added, you can re-run the blocked workflow to proceed.

This workflow will be automatically approved once merged into the default branch.

For more information, see StepSecurity's Secret Exfiltration Policy documentation.

@stepsecurity-app

Copy link
Copy Markdown
Contributor

Security Policy Alert: Secret Policy Violation

This workflow run has been blocked by StepSecurity's secrets policy because it accesses secrets and the workflow file differs from the default branch.

Secret references detected:

  • secrets.CX_BASE_URI at line 199
  • secrets.CX_CLIENT_ID at line 200
  • secrets.CX_CLIENT_SECRET at line 201
  • secrets.CX_BASE_AUTH_URI at line 202
  • secrets.CX_AST_USERNAME at line 203
  • secrets.CX_AST_PASSWORD at line 204
  • secrets.CX_APIKEY at line 205
  • secrets.CX_TENANT at line 206
  • secrets.CX_SCAN_SSH_KEY at line 207
  • secrets.PERSONAL_ACCESS_TOKEN at line 209
  • secrets.PROXY_USER at line 212
  • secrets.PROXY_PASSWORD at line 213
  • secrets.PR_GITLAB_TOKEN at line 218
  • secrets.PR_GITLAB_NAMESPACE at line 219
  • secrets.PR_GITLAB_REPO_NAME at line 220
  • secrets.PR_GITLAB_PROJECT_ID at line 221
  • secrets.PR_GITLAB_IID at line 222
  • secrets.AZURE_ORG at line 223
  • secrets.AZURE_PROJECT at line 224
  • secrets.AZURE_REPOS at line 225
  • secrets.AZURE_TOKEN at line 226
  • secrets.BITBUCKET_WORKSPACE at line 228
  • secrets.BITBUCKET_REPOS at line 229
  • secrets.BITBUCKET_USERNAME at line 230
  • secrets.BITBUCKET_PASSWORD at line 231
  • secrets.GITLAB_TOKEN at line 232
  • secrets.PR_BITBUCKET_TOKEN at line 234
  • secrets.ECHO_LIBRARIES_ACCESS_KEY at line 259
  • secrets.MS_TEAMS_WEBHOOK_URL_INTEGRATION_TESTS at line 399

To approve this workflow, please add the workflows-approved label to this PR.

Note: The label must be added by someone other than the PR author (cx-anurag-dalke) or automation bots to ensure proper security review.

After the label is added, you can re-run the blocked workflow to proceed.

This workflow will be automatically approved once merged into the default branch.

For more information, see StepSecurity's Secret Exfiltration Policy documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants