Skip to content

Commit 6f71f5f

Browse files
committed
fix(agent): escape XML values, CDATA content, generic corrective message
- Add html.escape() to target values in <scan_task> (URLs, paths, IPs) - Escape sender_name/sender_id in <agent_message> attributes - CDATA-wrap message content in <agent_message> to handle any text - Make corrective message generic (no StrixAgent-specific tool names)
1 parent 1ca72c0 commit 6f71f5f

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

strix/agents/StrixAgent/strix_agent.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Any
22

3+
import html
4+
35
from strix.agents.base_agent import BaseAgent
46
from strix.llm.config import LLMConfig
57

@@ -59,24 +61,24 @@ async def execute_scan(self, scan_config: dict[str, Any]) -> dict[str, Any]: #
5961

6062
target_lines = []
6163

62-
if repositories:
64+
if repositories:
6365
for repo in repositories:
6466
if repo["workspace_path"]:
65-
target_lines.append(f' <target type="repository">{repo["url"]} (code at: {repo["workspace_path"]})</target>')
67+
target_lines.append(f' <target type="repository">{html.escape(repo["url"])} (code at: {html.escape(repo["workspace_path"])})</target>')
6668
else:
67-
target_lines.append(f' <target type="repository">{repo["url"]}</target>')
69+
target_lines.append(f' <target type="repository">{html.escape(repo["url"])}</target>')
6870

6971
if local_code:
7072
for code in local_code:
71-
target_lines.append(f' <target type="local_code">{code["path"]} (code at: {code["workspace_path"]})</target>')
73+
target_lines.append(f' <target type="local_code">{html.escape(code["path"])} (code at: {html.escape(code["workspace_path"])})</target>')
7274

7375
if urls:
7476
for url in urls:
75-
target_lines.append(f' <target type="url">{url}</target>')
77+
target_lines.append(f' <target type="url">{html.escape(url)}</target>')
7678

7779
if ip_addresses:
7880
for ip in ip_addresses:
79-
target_lines.append(f' <target type="ip">{ip}</target>')
81+
target_lines.append(f' <target type="ip">{html.escape(ip)}</target>')
8082

8183
targets_block = "\n".join(target_lines)
8284

strix/agents/base_agent.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import contextlib
3+
import html
34
import logging
45
from typing import TYPE_CHECKING, Any, Optional
56

@@ -413,11 +414,7 @@ async def _process_iteration(self, tracer: Optional["Tracer"]) -> bool | None:
413414
corrective_message = (
414415
"You responded with plain text instead of a tool call. "
415416
"While the agent loop is running, EVERY response MUST be a tool call. "
416-
"Do NOT send plain text messages. Act via tools:\n"
417-
"- Use the think tool to reason through problems\n"
418-
"- Use create_agent to spawn subagents for testing\n"
419-
"- Use terminal_execute to run commands\n"
420-
"- Use wait_for_message ONLY when waiting for subagent results\n"
417+
"Do NOT send plain text messages. Act via your available tools. "
421418
"Review your task and take action now."
422419
)
423420
self.state.add_message("user", corrective_message)
@@ -499,12 +496,13 @@ def _check_agent_messages(self, state: AgentState) -> None: # noqa: PLR0912
499496
if sender_id and sender_id in _agent_graph.get("nodes", {}):
500497
sender_name = _agent_graph["nodes"][sender_id]["name"]
501498

499+
content = message.get("content", "")
502500
message_content = f"""<agent_message
503-
from="{sender_name}"
504-
id="{sender_id}"
505-
type="{message.get("message_type", "information")}"
506-
priority="{message.get("priority", "normal")}">
507-
{message.get("content", "")}
501+
from="{html.escape(sender_name)}"
502+
id="{html.escape(str(sender_id))}"
503+
type="{html.escape(message.get("message_type", "information"))}"
504+
priority="{html.escape(message.get("priority", "normal"))}">
505+
<![CDATA[{content}]]>
508506
</agent_message>"""
509507
state.add_message("user", message_content.strip())
510508

0 commit comments

Comments
 (0)