Skip to content

Commit

Permalink
Patched /private/var/folders/19/08z9_xys69v3f1xfqtyn9jyw0000gn/T/tmpx…
Browse files Browse the repository at this point in the history
…nth_zxf/system_prompt.examples/weak_system_prompt.txt
  • Loading branch information
patched.codes[bot] committed Nov 13, 2024
1 parent d33f6da commit 00be82e
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion system_prompt.examples/weak_system_prompt.txt
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 00be82e

Please sign in to comment.