Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,9 @@ import os
|
|
6 |
import sys
|
7 |
import psutil # Added missing import
|
8 |
from urllib.parse import urlparse
|
|
|
|
|
|
|
9 |
|
10 |
# Configure logging
|
11 |
logging.basicConfig(
|
@@ -31,7 +34,13 @@ def is_valid_url(url):
|
|
31 |
|
32 |
def sanitize_query(query):
|
33 |
"""Sanitize user input to prevent injection attacks"""
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Diagnostics integration
|
37 |
try:
|
|
|
6 |
import sys
|
7 |
import psutil # Added missing import
|
8 |
from urllib.parse import urlparse
|
9 |
+
import threading
|
10 |
+
import re
|
11 |
+
|
12 |
|
13 |
# Configure logging
|
14 |
logging.basicConfig(
|
|
|
34 |
|
35 |
def sanitize_query(query):
|
36 |
"""Sanitize user input to prevent injection attacks"""
|
37 |
+
try:
|
38 |
+
# Remove non-alphanumeric characters except spaces and hyphens
|
39 |
+
clean_query = re.sub(r'[^\w\s-]', '', query)
|
40 |
+
return clean_query[:256] # Truncate to prevent long queries
|
41 |
+
except Exception as e:
|
42 |
+
logger.error(f"Query sanitization failed: {str(e)}")
|
43 |
+
return query[:256] # Fallback truncation
|
44 |
|
45 |
# Diagnostics integration
|
46 |
try:
|