Parcourir la source

log: added a debug log if detecting a potential prompt injection attack

thiswillbeyourgithub il y a 7 mois
Parent
commit
e872f5dc78
1 fichiers modifiés avec 6 ajouts et 0 suppressions
  1. 6 0
      backend/open_webui/apps/rag/utils.py

+ 6 - 0
backend/open_webui/apps/rag/utils.py

@@ -198,6 +198,12 @@ def rag_template(template: str, context: str, query: str):
         f"RAG template contains an unexpected number of '[context]' : {count}"
     )
     assert "[context]" in template, "RAG template does not contain '[context]'"
+    if "<context>" in context and "</context>" in context:
+        log.debug(
+            "WARNING: Potential prompt injection attack: the RAG "
+            "context contains '<context>' and '</context>'. This might be "
+            "nothing, or the user might be trying to hack something."
+        )
 
     if "[query]" in context:
         query_placeholder = str(uuid.uuid4())