fix: taint prefetched web context

This commit is contained in:
RaresKeY
2026-08-15 01:57:09 +00:00
parent fef0e6f3c0
commit 329f9d298d
4 changed files with 46 additions and 3 deletions
+10 -2
View File
@@ -61,7 +61,12 @@ def _sanitize_label(label: str) -> str:
return label
def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
def untrusted_context_message(
label: str,
content: Any,
*,
provenance_origin: str | None = None,
) -> Dict[str, Any]:
"""Return an LLM message that keeps retrieved/source text out of system role.
The template is structured so that *only* the hardcoded
@@ -73,6 +78,9 @@ def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
safe_label = _sanitize_label(label)
text = "" if content is None else str(content)
text = _escape_guard_markers(text)
metadata: Dict[str, Any] = {"trusted": False, "source": label}
if provenance_origin:
metadata["provenance_origin"] = provenance_origin
return {
"role": "user",
"content": (
@@ -82,5 +90,5 @@ def untrusted_context_message(label: str, content: Any) -> Dict[str, Any]:
f"{text}\n"
f"{GUARD_CLOSE}"
),
"metadata": {"trusted": False, "source": label},
"metadata": metadata,
}