From b625906c788f6b3b15b3a5e832750fe22b256405 Mon Sep 17 00:00:00 2001 From: BukeLy Date: Thu, 16 Jul 2026 19:33:27 +0800 Subject: [PATCH] fix(security): harden document boundary validation --- pageindex/page_index.py | 38 +++++++++++++++----------------------- tests/test_page_index.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/pageindex/page_index.py b/pageindex/page_index.py index 8afe4a6..cd5aa6c 100644 --- a/pageindex/page_index.py +++ b/pageindex/page_index.py @@ -26,6 +26,7 @@ def _sanitize_doc_text(text: str) -> str: def _wrap_doc_text(text: str) -> str: """Wrap untrusted document text in delimiter tags so the LLM treats it as data.""" + text = re.sub(r"(?i)<(?=\s*/?\s*user_document\b)", "<", text) return ( "\n" "