Skip to content

fix(detectors): reject non-dict config and handle non-numeric comparisons#261

Open
stealthwhizz wants to merge 3 commits intoGenAI-Security-Project:mainfrom
stealthwhizz:fix/detector-config-and-numeric-validation
Open

fix(detectors): reject non-dict config and handle non-numeric comparisons#261
stealthwhizz wants to merge 3 commits intoGenAI-Security-Project:mainfrom
stealthwhizz:fix/detector-config-and-numeric-validation

Conversation

@stealthwhizz
Copy link
Contributor

@stealthwhizz stealthwhizz commented Mar 18, 2026

Summary

Fixes #117
Fixes #131

  • Bug 020: BaseDetector now raises TypeError at init when config is not a dict. Previously, passing a string or list as config was silently accepted, then crashed with AttributeError when _validate_config() called self.config.get(). The fix validates at the right layer so all detector subclasses are protected.
  • Bug 034: ToolCallDetector._check_condition numeric operators (gt, gte, lt, lte) now return False when values cannot be converted to float. Previously, a non-numeric string like "abc" caused an unhandled ValueError that crashed the detector and disabled all future detection for that challenge.

Fixes #130 alongside the other two (as copilot suggested)

Test plan

  • pytest tests/unit/ctf/test_base_detector.py passes (8 tests)
  • pytest tests/unit/ctf/test_tool_call_detector.py passes (17 tests)
  • Existing tests unaffected: pytest tests/unit/ctf/ passes

…sons

Bug 020: BaseDetector now raises TypeError at init when config is not a
dict, instead of deferring to AttributeError in _validate_config().

Bug 034: ToolCallDetector._check_condition numeric operators (gt, gte,
lt, lte) now return False when actual or expected values cannot be
converted to float, instead of raising unhandled ValueError.
Copilot AI review requested due to automatic review settings March 18, 2026 17:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two detector-related robustness bugs by tightening BaseDetector config validation and making ToolCallDetector’s numeric comparisons resilient to non-numeric inputs, with new unit tests covering both regressions.

Changes:

  • Add TypeError validation in BaseDetector.__init__ when config is non-dict.
  • Update ToolCallDetector._check_condition numeric operators (gt/gte/lt/lte) to return False instead of raising on non-numeric values.
  • Add unit tests for both bug fixes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
finbot/ctf/detectors/base.py Adds early type validation for config to fail fast with a clear error.
finbot/ctf/detectors/primitives/tool_call.py Hardens numeric operator handling by guarding float conversion and returning False on invalid inputs.
tests/unit/ctf/test_base_detector.py Adds regression tests for BaseDetector config validation behavior.
tests/unit/ctf/test_tool_call_detector.py Adds regression tests for numeric operator handling in _check_condition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Remove unused MagicMock imports from both test files
- Use real ToolCallDetector constructor instead of __new__ bypass
- Catch TypeError in create_detector() so non-dict config returns None
  with a log instead of crashing ChallengeService
Bug 033: contains operator lowercased actual but not expected, so
search terms like "Gambling" never matched "gambling services".
Now both sides are lowercased.

Also fixes GenAI-Security-Project#130.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment