Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/automations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Secfoo Automations (`docs/AUTOMATIONS.md`)

Secfoo automations let AI coding tools run targeted security checks automatically on tool calls, file edits, turn completion, and scheduled runs — using one shared entrypoint (`secfoo hook <recipe> --host <tool>`).

## Claude Code (Reference Implementation)

Secfoo integrates with Claude Code across five hook lifecycle events and three settings scopes:

| Recipe | Claude Code Event | Behavior |
|---|---|---|
| `commit-guard` | `PreToolUse` (`Bash`) | Denies `git commit` / `git push` / `gh pr create` when findings at or above `--fail-on` exist (`permissionDecision: "deny"`). Backgrounds cleanly if over budget. |
| `secret-on-edit` | `PostToolUse` (`Write\|Edit`) | Non-blocking secret scan on edited files (`async: true`). |
| `pr-security-review` | `Stop` | Reviews turn changes on stop; blocks continuation if findings exceed threshold, while respecting `stop_hook_active` to avoid loops. |

### Enable / disable by scope

```bash
secfoo automations list
secfoo automations enable commit-guard --host claude
secfoo automations status
secfoo automations doctor
secfoo automations disable commit-guard --host claude
```

In Claude Code, settings can live at:
- **Project (shared):** `.claude/settings.json`
- **Local (gitignored):** `.claude/settings.local.json`
- **User (global):** `~/.claude/settings.json`

`secfoo automations doctor` checks these files for `disableAllHooks: true` and `allowManagedHooksOnly: true`.

### Plugin commands & hooks

The `secfoo` Claude Code plugin (`plugins/secfoo/`) ships:
- `hooks/hooks.json` for `PreToolUse`, `PostToolUse`, and `Stop`
- `/secfoo:automations` (`commands/automations.md`)
- `/secfoo:fix-findings` (`commands/fix-findings.md`)

### Recursion guard

`secfoo hook` sets `SECFOO_HOOK_ACTIVE=1` for delegated scans so nested agent invocations never re-trigger hooks.

### Cloud scheduled task example

```bash
SECFOO_API_KEY="$SECFOO_API_KEY" secfoo run \
--agent claude --target . --depth standard \
--skill sast --skill secret-scanning --skill sca-reachability --json --rescan
```
9 changes: 9 additions & 0 deletions plugins/secfoo/commands/automations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: Enable, disable, or inspect Secfoo automation hook recipes in this repository.
---

Manage Secfoo automation hooks for Claude Code based on `$ARGUMENTS`:

1. Run `secfoo automations list` to show available recipes (`commit-guard`, `secret-on-edit`, `pr-security-review`).
2. Run `secfoo automations status` and `secfoo automations doctor` to inspect active hooks and verify that `disableAllHooks` / `allowManagedHooksOnly` are not blocking execution.
3. If the user asks to enable or disable a recipe, run `secfoo automations enable <recipe> --host claude` (or `disable`).
9 changes: 9 additions & 0 deletions plugins/secfoo/commands/fix-findings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
description: List open Secfoo security findings for this workspace, fix them, and re-run verification.
---

Resolve open Secfoo findings in the current workspace (`$ARGUMENTS` optional filter):

1. Call `list_findings` on the `secfoo` MCP server to retrieve open findings (prioritize Critical and High).
2. Inspect each affected file, implement minimal secure fixes, and preserve existing tests and behavior.
3. Re-run the relevant Secfoo skill and call `submit_report(...)` to confirm closure.
41 changes: 41 additions & 0 deletions plugins/secfoo/hooks/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"description": "Secfoo automation hooks for Claude Code (#243).",
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "secfoo hook commit-guard --host claude",
"timeout": 150
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "secfoo hook secret-on-edit --host claude",
"async": true,
"timeout": 150
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "secfoo hook pr-security-review --host claude",
"timeout": 150
}
]
}
]
}
}
1 change: 1 addition & 0 deletions src/secfoo/automations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading