fix(agent): call scan_for_threats on untrusted tool results to log promptware hits - #32793
Closed
sprmn24 wants to merge 1 commit into
Closed
fix(agent): call scan_for_threats on untrusted tool results to log promptware hits#32793sprmn24 wants to merge 1 commit into
sprmn24 wants to merge 1 commit into
Conversation
Contributor
|
Thanks for identifying the observability gap. This is already implemented on current
Closing as implemented on main. |
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.
What does this PR do?
tools/threat_patterns.pywas introduced with documentation stating it is"shared with the tool-result delimiter system", but
tool_dispatch_helpers.pynever imported or called
scan_for_threats(). As a result, tool resultsfrom
web_extract,web_search, andbrowser_*were wrapped in<untrusted_tool_result>delimiters but never scanned — known C2 heartbeat,role-hijack, and promptware patterns passed through silently with no log entry.
This PR wires the missing call: after confirming the content is long enough to
wrap,
scan_for_threats(content, scope="context")is called. Any matchesare logged at WARNING level so operators can detect injection attempts in
production logs. The import is guarded with a
try/except ImportErrorsothe module remains functional even if
tools.threat_patternsis unavailable.Note: logging does not block the request — the
<untrusted_tool_result>wrapper is the primary architectural defence; threat scanning adds observability.
Related Issue
Type of Change
Changes Made
agent/tool_dispatch_helpers.py: added guarded import oftools.threat_patterns.scan_for_threats; in_maybe_wrap_untrusted()call
_scan_threats(content, scope="context")and log a WARNING whenthreat patterns are detected; updated docstring.
How to Test
ignore previous instructions)as the result of a
web_extracttool callUntrusted tool 'web_extract' returned content matching threat patterns: [...]<untrusted_tool_result>as beforepytest tests/ -qChecklist
Code
fix(skills_guard): pre-compile THREAT_PATTERNS) touches the same module but is an unrelated optimisationpytest tests/ -qand all tests passDocumentation & Housekeeping
Screenshots / Logs