Skip to content

Commit 9dc0d66

Browse files
authored
Merge pull request #5222 from RaresKeY/fix/chat-web-search-deny-20260704
fix(chat): honor explicit web search denial
2 parents a052215 + 264da65 commit 9dc0d66

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

routes/chat_routes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,9 @@ async def chat_stream(request: Request) -> StreamingResponse:
781781
# by default without having to send allow_bash in every request.
782782
if allow_bash is not None and str(allow_bash).lower() != "true":
783783
disabled_tools.add("bash")
784-
_explicit_web_intent = bool(_tool_intent and _tool_intent.category == "web")
785784
if (
786785
allow_web_search is not None
787786
and str(allow_web_search).lower() != "true"
788-
and not _explicit_web_intent
789787
):
790788
disabled_tools.add("web_search")
791789
disabled_tools.add("web_fetch")

tests/test_chat_route_tool_policy.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import pytest
1616

17+
from src.action_intents import classify_tool_intent
18+
1719
_CHAT_ROUTES = Path(__file__).resolve().parent.parent / "routes" / "chat_routes.py"
1820

1921

@@ -73,7 +75,7 @@ def test_allow_web_search_reads_from_body_as_fallback():
7375
)
7476

7577

76-
def test_disabled_tools_does_not_bash_when_allow_bash_is_none():
78+
def test_disabled_tools_respects_missing_vs_explicit_toggles():
7779
"""When allow_bash is not set (None), bash must NOT be unconditionally
7880
added to disabled_tools. The per-user privilege check handles it.
7981
"""
@@ -89,8 +91,8 @@ def test_disabled_tools_does_not_bash_when_allow_bash_is_none():
8991
assert "allow_web_search is not None" in source, (
9092
"disabled_tools check must guard against allow_web_search being None"
9193
)
92-
assert "_explicit_web_intent" in source and "not _explicit_web_intent" in source, (
93-
"explicit web-search requests must override an off web toggle for that turn"
94+
assert "and not _explicit_web_intent" not in source, (
95+
"explicit allow_web_search=false must not be overridden by prompt web intent"
9496
)
9597

9698

@@ -116,7 +118,6 @@ def _build_disabled_tools(
116118
if (
117119
allow_web_search is not None
118120
and str(allow_web_search).lower() != "true"
119-
and not explicit_web_intent
120121
):
121122
disabled_tools.add("web_search")
122123
disabled_tools.add("web_fetch")
@@ -156,15 +157,27 @@ def test_json_body_allow_web_search_false_disables_web():
156157
assert "web_fetch" in disabled
157158

158159

159-
def test_explicit_web_intent_overrides_false_web_toggle_for_turn():
160-
"""A stale/off web toggle must not remove web tools when the message
161-
explicitly asks to use web search."""
160+
@pytest.mark.parametrize(
161+
"message",
162+
[
163+
"please use web search for current CVEs",
164+
"search the web for current CVEs",
165+
"can you look up the latest docs",
166+
],
167+
)
168+
def test_explicit_false_disables_web_despite_prompt_web_intent(message):
169+
"""Explicit allow_web_search=false is a hard deny even when the prompt
170+
asks for web search."""
171+
intent = classify_tool_intent(message)
172+
assert intent is not None
173+
assert intent.category == "web"
174+
162175
disabled = _build_disabled_tools(
163176
allow_web_search="false",
164177
explicit_web_intent=True,
165178
)
166-
assert "web_search" not in disabled
167-
assert "web_fetch" not in disabled
179+
assert "web_search" in disabled
180+
assert "web_fetch" in disabled
168181

169182

170183
def test_admin_user_gets_bash_enabled_by_default():

0 commit comments

Comments
 (0)