Fix(tool-call-detector): handle non-numeric strings in numeric operators#259
Open
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Open
Fix(tool-call-detector): handle non-numeric strings in numeric operators#259Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Jean-Regis-M wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
Root cause: Numeric operators (gt, gte, lt, lte) call float(actual) without try/except, causing unhandled ValueError when actual is a non-numeric string, crashing the detector. Solution: Wrap float conversions in try/except, return False on conversion error. Group operators to avoid duplication. This ensures the detector gracefully handles malformed input and continues processing. Impact: No breaking changes. Minimal diff. Improves robustness against invalid input without affecting valid numeric comparisons. Signed-off-by: JEAN REGIS <240509606@firat.edu.tr>
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
Fixes #131: Prevents unhandled
ValueErrorwhenactualvalue is a non‑numeric string in numeric operator conditions.Problem
In
_check_condition, numeric operators (gt,gte,lt,lte) directly convertactualandexpectedto float. Ifactualis a non‑numeric string like"pending",float(actual)raisesValueError, crashing the detector coroutine. This allows an attacker to cause denial‑of‑detection by sending a single malformed event.Root Cause
The code lacks exception handling for float conversion. The earlier
Noneguard does not protect against non‑numeric strings. This leads to uncaughtValueErrorpropagating through_check_parameterstocheck_event, stopping all subsequent event evaluations.Solution
Wrap the float conversions in a
try/exceptblock that catchesTypeErrorandValueError. On exception, returnFalse(non‑numeric cannot satisfy a numeric condition). The operators are grouped to compute floats once, minimising changes. This preserves existing behaviour for valid numeric inputs.