Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(detector): report AI agent hooks and approval settings - #311

Open
raysubham wants to merge 12 commits into
step-security:mainfrom
raysubham:feat/ai-agent-config
Open

raysubham wants to merge 12 commits into
step-security:mainfrom
raysubham:feat/ai-agent-config

Conversation

@raysubham

@raysubham raysubham commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Enterprise uploads now report, per AI coding agent, every settings source on the device with the approval, permission and sandbox keys written in it and the hooks it declares. Agents: Claude Code, Codex, GitHub Copilot (CLI and VS Code), Cursor and Gemini CLI.

  • New agent_config section from a new agent_config_scan phase, between the skills and plugins phases. Each agent lists its sources (managed, user, project), each source its allowlisted keys with their values and its hooks (event, matcher, handler type, command text and SHA-256 of the full redacted text).
  • Sources. Managed files and drop-in folders, macOS managed preference profiles (machine-wide and console user), Windows policy registry values, user config roots (CLAUDE_CONFIG_DIR, CODEX_HOME and COPILOT_HOME respected) and project folders. The full table is in SCAN_COVERAGE.md.
  • File contents only. The section does not say whether a hook ran, whether a project is trusted, or which value the agent applies. The backend computes the posture from the reported values.
  • Projects. The reader uses the projects the skills scan found. A repository that holds only agent settings or hook files is found too, on a separate list with its own caps, so the skills, skill scan info and plugins output do not change on any device. A skills project that the 200-project cap cuts from the skills list moves to that settings list, so its settings are still read (on enterprise uploads, package-scanner roots fill the skills list first on machines with many package.json folders).
  • Privacy. The home folder is shown as ~ in every path, value, matcher and command. Secrets are redacted before hashing. HTTP hook URLs lose user info, query and fragment. Environment blocks, headers and trust state are never read into the output. Project and VS Code sources are sent only when they hold a listed key or a hook.
  • Bounds. Per agent: 250 sources, 100 hooks, 50 values per key, 256-byte values and command text, 1,024-byte paths, 128 KiB of JSON. A cut marks the agent truncated; a cut project list marks every agent truncated.
  • Failure handling. The phase has its own budget and never fails the scan. The section is left out (so the backend keeps stored state) when the project list could not be built, the scanned user's environment could not be read, a read panics, or the budget runs out. A missing ~/.claude.json still reports.

Backend counterpart for step-security/agent-api#12041: step-security/agent-api#12669 (into the 1.20 backend branch) and step-security/agent-api#12668 (int, for integration testing). An older backend ignores the section.

Validation

  • gofmt, go vet ./..., golangci-lint and go test ./... -race -count=1 pass; GOOS=windows go build ./... passes.
  • The shared golden fixture internal/model/testdata/agent_config_v1_golden.json (SHA-256 503a86c315a7e4a8b413a05532b16ceb1eeee7083f5945888949aba6b23ada15) is byte-identical to the backend copy.
  • A scratch home with settings-only repositories, scanned with this branch and with the base commit: every section except agent_config is identical apart from timestamps and durations, and two runs give byte-identical agent_config.
  • Scans with this branch on macOS, Linux and Windows VMs, with lab settings for every agent in user and project scope (settings-only repositories, CODEX_HOME, VS Code profiles, malformed, BOM and unreadable files, size cuts): keys, hooks, ~ paths, redaction and hashes as expected, and no login name, fake secret or URL user info in the section. Against the base commit, every other section is identical apart from timestamps (on Windows also fields that already differ between two runs of one binary). Two runs give identical agent_config.
  • Quoted secret values in hook commands (TOKEN='...', --password 'a b c', --token "a b") are redacted on all three systems; the previous head sent them.
  • Codex notify arguments that hold a space or a quote are quoted before the join, so a multiword secret argument ("--password", "a b c" or "--token=a b") is redacted whole. On a Linux VM, the previous head sent the tail of both; this head sends --password [REDACTED] --token=[REDACTED], and the rest of the lab's agent_config is identical between the two heads.
  • On macOS, a run from a LaunchAgent caused no permission prompt while VS Code settings were linked into ~/Documents.
  • Managed channels read as expected on macOS, Linux and Windows VMs: Claude managed file and drop-ins (and the registry policy on Windows); Codex requirements.toml; Copilot managed settings and policy.d; the VS Code chat policies (registry on Windows, /etc/vscode/policy.json on Linux); Cursor and Gemini system files. On macOS, managed preference profiles for Claude (machine-wide and console user, sent under ~), Codex, Copilot and VS Code. Managed sources come before user sources. A VS Code policy that holds only an extension allowlist is not sent.
  • Backend round trip against the int backend (agent-api#12668) from all three VMs: every source, setting and hook stored and returned as sent, first_seen kept across scans and reset when a hook is removed and added again, the approvals matrix as expected, an older agent upload (no section) leaves stored state unchanged, and the fleet hook list, hook detail, settings list and summary (REST and MCP) agree with the device views. Skills, plugins, MCP servers and AI agent inventories are unchanged.
  • On a Linux VM, a second OS user with its own Claude settings uploads: the backend keeps both users' user sources, lists managed sources once and counts a shared hook once for the device, and a later upload from that user without the section changes nothing.
  • On a Windows VM whose upload has 231 project roots, a project cut from the skills list still has its settings in the upload, and the device's skills and plugins are identical to an upload built without the fallback.

Known limits

  • Not read: Copilot policy subkeys under HKLM\Software\Policies\GitHub\Copilot, Codex config_toml_base64 and managed_config.toml, VS Code HKCU policy, the Insiders policy domain and project .vscode/settings.json, Gemini system settings path overrides and system-defaults.json, Cursor $XDG_CONFIG_HOME/cursor/cli-config.json, and Copilot reading .claude/settings*.json.
  • A ~/.claude.json that is a symlink to a file outside the home folder is unsafe_path, so that device sends no section.
  • Managed and user sources are never dropped to fit, so on their own they can pass 250 sources or 128 KiB; the backend then caps the agent at 250 sources and marks it truncated.
  • A project beyond both 200-project lists is not read; every agent is then marked truncated.
  • A device where the scanned user's environment can never be read sends no section, as COPILOT_HOME and XDG_CONFIG_HOME would otherwise fall back to their defaults and drop real sources.
  • A quoted secret assignment whose value holds a space or an escaped quote (TOKEN="a b") is redacted only up to that character.
  • A VS Code settings.json (or profile folder) that links into a macOS protected folder such as ~/Documents, or outside the home folder, is skipped so the scan never triggers a permission prompt.

Add an agent_config section that lists, for Claude Code, Codex, Cursor,
Gemini CLI and GitHub Copilot, every managed, user and project settings
source found on the device, with the allowlisted approval, sandbox and
hook-policy keys written in it and every hook it declares.

Sources include managed files and drop-in folders, macOS managed
preference profiles, Windows policy registry values, user config roots
(CLAUDE_CONFIG_DIR, CODEX_HOME, COPILOT_HOME) and the repositories found
by the skills scan. Repository discovery also accepts settings-only
agent folders.

Values and hook text have the home folder shown as ~ and secrets
redacted; hook text is fingerprinted with SHA-256. Output is bounded per
agent (250 sources, 100 hooks, 50 values per key, 128 KiB) and marked
truncated when cut. The phase has its own budget and never fails the
scan; the section is omitted when the project list is unavailable.
Repositories found only by an agent settings marker now go on their own
list with the same admission rules and caps, so they never take a skills
project's place, change the skills or plugins results, or stop the walk.
The agent configuration reader reads both lists and counts both in
repositories_scanned.

A cut project list (registry cap, walk caps, an unlistable search root,
or the settings-only caps) marks every reported agent truncated.

Also: an unreadable VS Code policy registry value is not sent; a hook
entry with no handler field is skipped; matchers show the home folder as
~; the source dedupe in finalize is removed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues allow unconfined settings reads that can trigger permission prompts or exceed deadlines, and upload event and matcher strings without secret redaction.

6 open issues
What changed in this PR

Adds AI agent configuration reporting to the existing scan pipeline, exposing settings sources, approval controls, sandbox settings, and declared hooks for five agents.

Changes:

  • Adds configuration collection across managed, user, and project sources, with privacy filtering and output limits.
  • Discovers settings-only repositories separately from skills and plugins.
  • Wires the new section into scan results and telemetry, with platform fixtures and shared wire-format tests.
File Description
SCAN_COVERAGE.md Documents configuration sources, privacy, bounds, and exclusions.
README.md Adds configuration reporting to coverage and collected-data summaries.
internal/​telemetry/​telemetry.go Runs the configuration phase and includes its payload.
internal/​telemetry/​telemetry_out_test.go Tests configuration serialization and omission.
internal/​telemetry/​phase_deadline.go Assigns the configuration phase a time budget.
internal/​scan/​scanner.go Integrates configuration collection into community scans.
internal/​procusage/​history_test.go Includes the new phase in resource-history fixtures.
internal/​model/​testdata/​agent_config_v1_golden.json Defines the shared configuration wire fixture.
internal/​model/​scanresult_jsonshape_test.go Checks omission of unreported configuration.
internal/​model/​model.go Adds the optional configuration result field.
internal/​model/​agentconfig.go Defines configuration sources, settings, and hooks.
internal/​model/​agentconfig_golden_test.go Validates fixture round trips and wire invariants.
internal/​detector/​skills.go Separately discovers settings-only projects.
internal/​detector/​skills_homewalk_test.go Tests configuration project markers.
internal/​detector/​registry_windows.go Adds native Windows policy-value reads.
internal/​detector/​registry_windows_test.go Tests native registry value handling.
internal/​detector/​registry_other.go Adds registry-query parsing for cross-platform fixtures.
internal/​detector/​plugins.go Carries configuration results and discovery state.
internal/​detector/​plugins_test.go Adapts tests to the discovery return values.
internal/​detector/​plugins_copilot.go Extracts reusable VS Code user-directory resolution.
internal/​detector/​plugins_codex.go Reuses ProgramData path resolution.
internal/​detector/​agentconfig.go Implements configuration collection and normalization.
internal/​detector/​agentconfig_test.go Tests sources, privacy, limits, and scan integration.

Review effort: Balanced

Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig_test.go Resolved
VS Code User settings are read through a reader confined to home and the
User folder, so a symlinked settings file or folder is not followed into
another protected folder or out of home.

Hook events and matchers now get the same home folder replacement,
redaction and cut as setting values. HTTP hook URLs drop the query and
fragment before sanitizing, so a long query no longer empties the URL.

Document that managed and user sources can exceed the source and size
bounds on their own.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved findings allow quoted shell secrets to be uploaded, VS Code directory symlinks to expose files outside home, and configuration coverage to appear complete despite environment or discovery failures.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Mark discovery incomplete when a search root cannot be listed

internal/​detector/​skills.go:255

If rootIsRealDir cannot list a search root's ancestor, the walk records an error but leaves projectInfo.Truncated false. This can report truncated: false for every agent despite omitting that root's repositories. Use the existing ps.projectsIncomplete signal here so discovery errors also mark configuration coverage incomplete.

6 resolved since last review

Review effort: Balanced

Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
A secret assignment with a single-quoted value was passed through unchanged, and a long-form secret flag with a quoted value containing spaces kept every word after the first. Accept a single quote where a double quote was accepted, and take the whole quoted value of a secret flag, including text joined to the quotes.
…esolved

Without the target user's environment, overrides such as COPILOT_HOME and XDG_CONFIG_HOME fall back to their defaults and the section would drop sources that still exist. Leave the section unset so the backend keeps its stored state.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved redaction flaws allow secret flag values and escaped private settings to reach uploads, while project-discovery errors can incorrectly report complete coverage.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Redact escaped strings in collection-valued settings

internal/​detector/​agentconfig.go:1039

json.Compact preserves string escapes, so sanitizing collection-valued settings as plain text misses home paths such as \/Users\/testuser\/src and URL credentials such as https:\/\/user:pass@host. These private values remain recoverable in the uploaded settings. Decode collection subtrees and normalize/redact their string leaves before serialization in both the array and object branches.

Medium severity Handle escaped quotes when redacting secret values

internal/​aiagents/​redact/​redact.go:221

Escaped quotes still expose part of a secret flag value: mysql --password "correct\" horse battery staple" becomes mysql --password [REDACTED] horse battery staple". The POSIX single-quote escape form also leaks the tail, which survives subsequent redaction and reaches uploaded hook commands. Handle backslash escapes inside double quotes and unquoted segments, and add regression cases for both forms.

Medium severity Mark project discovery errors as incomplete coverage

internal/​detector/​skills.go:255

Project-discovery failures that only populate projectInfo.Errors are lost here. For example, a failed ReadDir on a project's marker directory records an error without setting projectInfo.Truncated, so its settings-only repository disappears and agent_config reports the remaining agents with truncated: false. The existing projectsIncomplete flag already accounts for these failures; include it in projectsCut so missing project sources are not reported as complete coverage.

3 resolved since last review

Review effort: Balanced

A long-form secret flag value now keeps shell escapes inside it: a
backslash-escaped quote in a double-quoted value, an escaped single quote
between quoted parts, and an escaped double-quoted value inside a quoted
command. Each of these previously sent the words after the first space.
@raysubham

Copy link
Copy Markdown
Collaborator Author

Review notes on the three items Copilot raised in its last review (no inline threads, so recorded here):

Escaped quotes in secret flag values: fixed in 823efd7. A long-form secret flag value now keeps shell escapes inside it: --password "correct\" horse battery staple", --token 'it'\''s a secret' and an escaped double-quoted value inside a quoted command (bash -c "mysql --password \"correct horse\" -h db") are redacted whole. The first two sent the words after the escaped quote before; the third is pinned by a test so it stays covered. The fix is in the shared redactor, so hook commands and every other caller get it, and the hash is taken after redaction. Regression cases added. Unchanged known limit: a quoted assignment value (TOKEN="a b") is redacted only up to the first space or quote.

JSON escapes kept in collection values: not changing. Strings in a list are decoded before the home folder is replaced and secrets are redacted; only non-string list items and object values are sent as compact JSON. The one listed key whose documented schema nests strings there is Gemini tools.sandbox in its object form (image, allowedPaths). Windows paths in it are covered, because the JSON-escaped form of the home folder is replaced too, and a POSIX path normally has no escapes. What is left is a home path written with \/ or \u escapes, which shows the user name the device record already carries. Token-shaped secrets have no escapes and are still redacted.

Project-discovery errors and truncated: not changing. The project walk marks a scan partial only when a cap is hit or a search root cannot be listed. A folder deeper down that cannot be listed is recorded in agent_skill_scan.errors ("home walk read marker ...") and does not mark the scan truncated. Otherwise one unreadable folder would keep the flag set on that machine on every scan, and the flag would stop meaning anything. agent_config follows the same signal. In the backend truncated is shown, not used to keep stored sources, so setting it would not keep the missing source either.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Secret-redaction gaps, incomplete configuration reporting, and uncancellable hook processing warrant human assessment of the change’s security and reliability risks.

No open issues 🎉

Review effort: Balanced

On the telemetry path every package-scanner project root comes before
the home-walk projects, so a machine with many package.json folders
fills the 200-project list before a walk-found project is reached. A
project with agent settings and a skills folder was then not read by
the agent configuration scan, which only marked itself truncated.

A walk project cut from the skills list now falls to the settings-only
list, which has its own cap, so its settings are still reported. Skills
and plugins still read the skills list only, so their output does not
change.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to assess multiple critical credential-exposure paths and incomplete discovery that can cause stored agent configurations to be removed.

No open issues 🎉

Review effort: Balanced

# Conflicts:
#	README.md
#	internal/detector/plugins_test.go
#	internal/detector/skills.go
#	internal/telemetry/telemetry.go
@raysubham
raysubham marked this pull request as ready for review November 24, 2026 18:51
@raysubham raysubham closed this Nov 24, 2026
@raysubham raysubham reopened this Nov 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Secret-redaction flaws expose password fragments in uploads and hash inputs, while discovery gaps omit project configurations and incorrectly report complete coverage.

4 open issues

Review effort: Balanced

Comment thread internal/aiagents/redact/redact.go Resolved
Comment thread internal/detector/agentconfig.go Resolved
Comment thread internal/detector/skills.go Resolved
Comment thread internal/detector/skills.go Resolved
Codex notify is an argv array. Joining it with plain spaces let a multiword
secret split across words, so only its first word was redacted. Arguments
that hold whitespace or quotes are now single-quoted before the join, and a
--name=value argument keeps its name outside the quotes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed to assess nested credential exposure, unintended deletion of stored agent sources during capped scans, and incorrect Unicode path handling.

No open issues 🎉

4 resolved since last review

Review effort: Balanced

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants