Advisory

PYSEC-2026-3503

Details, part 2 of 2. The advisory

Details

Suggested Fix

Escape every untrusted value before inserting it into the approval HTML:

  • tool_name
  • risk_level
  • agent_name
  • every argument key
  • every argument value

For example, use html.escape(str(value), quote=True) or a template engine that
auto-escapes by default. Add regression tests that include </code><script>...
in tool arguments and assert that the rendered page contains escaped text, not a
script element.

Minimal patch shape:

from html import escape


def h(value: object) -> str:
    return escape(str(value), quote=True)


tool_name = h(info.get("tool_name", "unknown"))
risk_level = h(info.get("risk_level", "unknown"))
agent_name = h(info.get("agent_name", ""))

args_html = ""
for k, v in arguments.items():
    val_str = str(v)
    if len(val_str) > 200:
        val_str = val_str[:197] + "..."
    args_html += (
        f"<tr><td><code>{h(k)}</code></td>"
        f"<td><code>{h(val_str)}</code></td></tr>"
    )

Additional hardening:

  • avoid inline JavaScript and add a restrictive Content Security Policy;
  • keep the request id as an unguessable capability, but do not rely on it as an XSS defense;
  • consider requiring a per-request decision token outside attacker-controlled rendered argument fields.

Sources & licences