fix(ai): stop discarding exploit mode; wire + document it (D2)#1263
Merged
Conversation
`_detect_mode` accepted only ("attack","chat") from the intent LLM and
discarded an "exploit" classification (fell back to old_mode/chat), even
though the full exploit mode exists (MODES entry, SYSTEM_EXPLOIT prompt,
get_system_prompt branch, _selection.txt classifies it). So exploit mode
was unreachable by detection and the `mode` opt help omitted it.
- _detect_mode: accept any mode in MODES (incl. exploit); attack/chat
unchanged.
- `mode` opt help derived from MODES.keys() (DRY, no drift).
- Tests: LLM "exploit" verdict now sets mode=exploit; attack/chat/unknown
unchanged; exploit system prompt renders with no leftover template vars.
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.
Finding — D2:
exploitmode half-wired (P4 Pertinence)The selection prompt offers
exploit, and the full mode exists(
MODES["exploit"],SYSTEM_EXPLOIT,get_system_promptbranch,modes/_selection.txtclassifies attack/chat/exploit), but detectionthrew the classification away and the opt help omitted it.
Root cause
secator/tasks/ai.py:764(pre-change) —_detect_modeaccepted only("attack", "chat")from the intent LLM; anexploitverdict hit theelseand reverted toold_mode or "chat". Since D4'sfast_detect_modealready defers exploit-ish prompts to the LLM, the LLM could return
exploit— it was just discarded here.secator/tasks/ai.py:74—modeopt help hardcoded"Mode: attack or chat".Changes
_detect_mode: accept anymode in MODES(addsexploit; attack/chatbehavior identical).
secator/tasks/ai.py:764modeopt help derived fromMODES.keys()— single source of truth, nodrift (
f"Mode: {', '.join(MODES)}").secator/tasks/ai.py:74MODESinto the task module (DRY; no third hardcoded mode tuple).No change to the exploit SAFETY posture — exploit still runs through the same
PermissionEngine/guardrails; only detection + docs changed.Exploit prompt is real
secator/ai/prompts/modes/exploit.txtis a full 43-line template (persona ="exploitation verification specialist", methodology,
add_findingexploitation-report flow,
${guardrails}/${isolation}constraints).get_system_prompt("exploit", ...)renders with no leftover${include}or$template_varplaceholders (D1's$query_types/$output_types_referencesubstitution covers exploit too).
Tests
Added focused tests (
tests/unit/test_ai_task_opts.py,tests/unit/test_ai_prompts.py):_detect_modeverdict ofexploitnow setsself.mode == "exploit"(previously fell back to chat).
get_system_prompt("exploit")renders clean (no unresolved placeholders).modeopt help lists every mode incl. exploit.Baseline vs after (
test_ai_loop.py test_ai_session.py test_ai_prompts.py):baseline 12 failed / 85 passed → after 12 failed / 86 passed. The 12
failures are identical pre-existing env failures (shfmt/safecmd sandbox), not
regressions; the +1 pass is the new exploit-render test.
Related smells (not fixed here)
secator/ai/prompts.py:248—if mode in ("attack", "exploit"):hardcodesthe "uses library reference" set; a new library-using mode would need a
manual edit. Candidate to derive from mode config.
secator/tasks/ai.py:66— class docstring still says "(attack or chatmode)"; omits exploit.
secator/ai/prompts/modes/_selection.txthardcodes the three mode names inprose — can drift from
MODESif a mode is added/removed.🤖 Generated with Claude Code