fix(ai): gate privileged add_finding types at the guardrail (M7)#1260
Merged
Conversation
…ndings (M7) Injected/scanned content can drive the AI to emit an add_finding action with _type:"target". Downstream, tasks/ai.py _auto_approve_workspace_targets() searches _type:"target" findings and auto-approves them all as in-scope, so a smuggled target finding silently widens scope with no prompt. Gate at the guardrail: add_finding of a privileged (downstream-trusted) finding type now returns "ask" instead of unconditional allow. Benign/info add_finding and read-only query/follow_up are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
M7 (P1, Security): `add_finding`/`query` unconditionally allowed
Finding: Injected/scanned content can drive the AI to write a `_type:"target"` finding that auto-approve later trusts, silently widening scope with no prompt.
Root cause: `secator/ai/guardrails.py:826-827` blanket-allowed `add_finding` (alongside `query`/`follow_up`):
```python
elif action_type in ("query", "follow_up", "add_finding"):
return PermissionResult(decision="allow", reason=f"{action_type} is always allowed")
```
What "privileged/trusted" means downstream: `secator/tasks/ai.py:538-556` `_auto_approve_workspace_targets()` runs `QueryEngine.search({"_type": "target"}, limit=1000)` and passes every hit to `permission_engine.add_runtime_allow([...])`. So any `target`-typed finding in the workspace is auto-approved as in-scope on the next turn. An injected `add_finding` of that type therefore smuggles a new trusted target and widens scope.
Fix
Small guardrail-layer defense (defense-in-depth). New module-level predicate:
```python
_PRIVILEGED_FINDING_TYPES = frozenset({"target"})
def _is_privileged_finding_type(action: Dict) -> bool:
return str(action.get("_type", "")).strip().lower() in _PRIVILEGED_FINDING_TYPES
```
The decision branch now returns `ask` (engine vocabulary, reuses `PermissionResult`) when an `add_finding` would mint a privileged/trusted type. It reads `_type` straight off the action dict the engine already receives — no `actions.py` change needed. Benign/info `add_finding` stays `allow`; read-only `query` and engine-internal `follow_up` are untouched.
Tests
Related trust smell (flagged, not fixed here — cross-lane)
`secator/tasks/ai.py:538-556` is the sink that auto-trusts `_type:"target"` findings. Note `_handle_add_finding` (`secator/ai/actions.py:466-467`) strips `_type` from `finding_data` and `type_map` only covers `FINDING_TYPES` (no `Target`), so today it can't build a literal Target — but this guardrail closes the intent path as defense-in-depth. AI-origin findings also aren't tagged distinctly from tool-discovered ones (`actions.py:519-524`), so downstream can't tell them apart.
🤖 Generated with Claude Code