Repository navigation
Harden the Claude adapter (SECFOO-40 to 43) - #26
Merged
Varunpoojari merged 4 commits intoOct 3, 2026
Merged
Conversation
…P servers (SECFOO-40) `claude -p` skips the workspace-trust prompt, so running it inside an untrusted target loaded that target's `.claude/settings.json`: its hooks ran as shell commands, and `enableAllProjectMcpServers` started whatever its `.mcp.json` named. Both reproduced on Claude Code 2.1.288. - `--setting-sources user`: ignore project and local settings from the target; the user's own settings still apply. - `--strict-mcp-config`: only load MCP servers secfoo passes through `--mcp-config`. - Tests for both flags, and that permissions are never bypassed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD
On an error result Claude Code exits 1 with an empty stderr and puts the reason in its stdout JSON (`is_error`, `subtype`, `errors`). secfoo only keeps stderr as the failure reason, so the run was saved as failed with no explanation. - base.py: add a `describe_failure()` hook, consulted only on a non-zero exit, whose reason is prepended to stderr like `detect_failure()`'s. Adapters that don't override it are unaffected. - claude.py: read `subtype` and `errors` (or `result`) from an error result. Share one JSON-object parser, so a non-object or null `result` no longer raises in `extract_report()`. - Tests use an error payload captured from Claude Code 2.1.288. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD
PR secfoo-com#23 moved Codex and Copilot to stdin because npm-installed CLIs are `.cmd` shims on Windows and cmd.exe cuts an argv prompt at its first newline. The Claude adapter still passed the prompt as an argument. `claude -p` with no prompt argument reads it from stdin; a two-line prompt was read in full on Linux with Claude Code 2.1.288. The Windows truncation itself was not reproduced for Claude (no Windows machine). - claude.py: `prompt_via_stdin = True`, prompt dropped from the argv. - test_base.py: the "stdin is DEVNULL" test used Claude as its example of an argv-prompt adapter; it now uses Cursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD
- `--no-session-persistence`: a scan no longer leaves a transcript under ~/.claude/projects/<target path>/ (the Codex adapter's `--ephemeral`). - `--permission-mode default` is kept. `default` is no longer listed in `claude --help` (2.1.288) but is still accepted, and a tool outside the grant is still denied with it. The listed names were not tried on older CLIs, so the value is unchanged and the reasoning is now in a comment. - Module docstring recording the CLI version the flags were checked against, as codex.py and copilot.py do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four fixes to the existing Claude Code adapter (
src/secfoo/agents/claude.py), found while verifying SECFOO-5. One commit per Jira issue.--permission-modevalue; module docstringThe adapter's command changes from
to
What each commit does
SECFOO-40.
claude -pskips the workspace-trust prompt, so running it inside a target loaded that target's.claude/settings.json.--setting-sources userignores the target's project and local settings (the user's own still apply).--strict-mcp-configloads only the MCP servers secfoo passes through--mcp-config.docs/REFERENCE.mdgets one sentence saying so.SECFOO-41. On an error result Claude Code exits 1 with an empty stderr and puts the reason in its stdout JSON. secfoo keeps only stderr as the failure reason, so the run was saved as
failedwith nothing to explain it.base.pygains adescribe_failure()hook, consulted only on a non-zero exit; adapters that do not override it behave as before.ClaudeAdapterreadssubtypeanderrorsfrom the result.SECFOO-42. Same change PR #23 made for Codex and Copilot:
prompt_via_stdin = True, prompt dropped from the argv.SECFOO-43.
--no-session-persistence, so a scan does not leave a transcript under~/.claude/projects/.--permission-mode defaultis kept:defaultis no longer listed inclaude --helpbut is still accepted. A module docstring records the CLI version the flags were checked against.Testing
Claude Code 2.1.288 on Linux,
main@ 138452f.pytest tests: 751 passed (736 before, 15 new).ruff checkon the touched files: clean. Repo-wide count unchanged.SessionStarthook, a.mcp.jsonserver, and settings withenableAllProjectMcpServersandpermissions.allow: ["Write", "Edit", "Bash"]:.mcp.jsonserver startsWriteoutside the tool grant--mcp-configserver startssecfoo run --skill sast --agent claudeagainst that repo: statussuccess, the SQL injection in the test file reported as one High finding, tokens and cost recorded, target unchanged.claudethat replays a captured error result (error_max_budget_usd, exit 1): the run isfailedandstderr.lognow readssecfoo: Claude Code reported error_max_budget_usd: Reached maximum budget ($0.0001).Not tested
error: unknown option, so the run fails visibly instead of running without the protection.Notes for reviewers
SECURITY.mdsays the agent CLI "does whatever it would normally do when you point it at that same target directly". For Claude that is now stricter than the text. I have leftSECURITY.mdunchanged; say if you want it updated in this PR.--strict-mcp-config, MCP servers from the user's global Claude config are no longer started during a scan. Their tools were never in--allowedTools, so they could not be called before either.src/secfoo/agents/base.py. This branch does not touch therun()signature line, and a trial merge of the two auto-mergesbase.py.🤖 Generated with Claude Code
https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD