From 00be82ec7812519c8d4bee374425b5aa7fd04179 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:56:10 +0800 Subject: [PATCH] Patched /private/var/folders/19/08z9_xys69v3f1xfqtyn9jyw0000gn/T/tmpxnth_zxf/system_prompt.examples/weak_system_prompt.txt --- system_prompt.examples/weak_system_prompt.txt | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/system_prompt.examples/weak_system_prompt.txt b/system_prompt.examples/weak_system_prompt.txt index 7b6ac3d..6dc74a1 100644 --- a/system_prompt.examples/weak_system_prompt.txt +++ b/system_prompt.examples/weak_system_prompt.txt @@ -1 +1,74 @@ -This conversation is exclusively dedicated to finance-related topics. +# Updated Code Based on the Analysis + +def process_user_input(user_input): + # Define allowed languages and character sets + allowed_languages = ['English'] + restricted_keywords = ['sensitive', 'confidential'] + + # Define a filter for context-related topics + def filter_context(input_text): + # Filter for finance-related terms + finance_terms = ["finance", "investment", "stock", "bank", "currency"] + if any(term in input_text.lower() for term in finance_terms): + return True + return False + + # Preliminary checks for known vector attack patterns + if isinstance(user_input, str): + user_input = user_input.strip() + + # Convert input to lower case for consistent checking + input_lower = user_input.lower() + + # Check for restricted keywords + if any(keyword in input_lower for keyword in restricted_keywords): + raise ValueError("Input contains restricted terms.") + + # Contextual Redirection Prevention + if not filter_context(input_lower): + raise ValueError("Input not related to finance context.") + + # Affirmative Suffix Attack Prevention + if input_lower.endswith(('yes', 'sure', 'okay')): + raise ValueError("Detected potential affirmative suffix attack.") + + # Base64 Encoding Prevention + if is_base64(input_lower): + raise ValueError("Base64 encoded content is not allowed.") + + # Typoglycemia Attack Prevention (Example logic) + if typoglycemia_detector(input_lower): + raise ValueError("Detected typoglycemia attack.") + + # Additional non-English language filtering + if not detect_language(user_input) in allowed_languages: + raise ValueError("Non-English languages are not allowed.") + + return handle_input(user_input) # Passing the input for further processing + else: + raise TypeError("Input needs to be a string.") + + +def is_base64(sb): + """Checks if a string is Base64 encoded.""" + try: + return base64.b64encode(base64.b64decode(sb)).decode('utf-8') == sb + except Exception: + return False + + +def typoglycemia_detector(text): + """Simple typoglycemia attack detector (example logic).""" + # Implement logic to detect scrambled words typical of a typoglycemia attack + return False + + +def handle_input(input_text): + """Handles the valid input post-validation filters.""" + return f"Processed: {input_text}" + + +def detect_language(text): + """Placeholder for detecting language of the text.""" + # Assume a function exists that can detect the language appropriately + return 'English'