fix: redact browser typed text surfaces

This commit is contained in:
rebel 2026-06-24 11:02:35 +05:30 committed by Teknium
parent 5add283ec8
commit 8ff426e53b
8 changed files with 272 additions and 25 deletions

View file

@ -562,13 +562,27 @@ def camofox_type(ref: str, text: str, task_id: Optional[str] = None) -> str:
f"/tabs/{session['tab_id']}/type",
{"userId": session["user_id"], "ref": clean_ref, "text": text},
)
return json.dumps({
from agent.display import (
redact_browser_typed_text_for_display,
redact_tool_args_for_display,
)
display_text = (redact_tool_args_for_display("browser_type", {"text": text}) or {})["text"]
response = {
"success": True,
"typed": text,
# Match browser_tool.browser_type: do not echo raw credentials in
# tool progress or chat history. The raw text is still typed into
# the page; only the returned display value is redacted.
"typed": display_text,
"element": clean_ref,
})
}
response = redact_browser_typed_text_for_display(response, text)
return json.dumps(response)
except Exception as e:
return tool_error(str(e), success=False)
from agent.display import redact_browser_typed_text_for_display
return tool_error(redact_browser_typed_text_for_display(str(e), text), success=False)
def camofox_scroll(direction: str, task_id: Optional[str] = None) -> str:

View file

@ -2758,19 +2758,34 @@ def browser_type(ref: str, text: str, task_id: Optional[str] = None) -> str:
# Use fill command (clears then types)
result = _run_browser_command(effective_task_id, "fill", [ref, text])
from agent.display import (
redact_browser_typed_text_for_display,
redact_tool_args_for_display,
)
display_text = (redact_tool_args_for_display("browser_type", {"text": text}) or {})["text"]
if result.get("success"):
response = {
"success": True,
"typed": text,
# Never echo raw typed text back to tool progress/log surfaces: it
# is commonly a password, API key, or other credential. Redact
# only the returned display value; the original text was already
# sent to the browser command above.
"typed": display_text,
"element": ref
}
return json.dumps(_copy_fallback_warning(response, result), ensure_ascii=False)
response = _copy_fallback_warning(response, result)
response = redact_browser_typed_text_for_display(response, text)
return json.dumps(response, ensure_ascii=False)
else:
response = {
"success": False,
"error": result.get("error", f"Failed to type into {ref}")
}
return json.dumps(_copy_fallback_warning(response, result), ensure_ascii=False)
response = _copy_fallback_warning(response, result)
response = redact_browser_typed_text_for_display(response, text)
return json.dumps(response, ensure_ascii=False)
def browser_scroll(direction: str, task_id: Optional[str] = None) -> str: