Skip to content

Commit 065774a

Browse files
zimingttkxClaude Opus 4.6
andcommitted
MAESTRO: Fix SQL injection vulnerability in order_by parameter
SEC-001: SQL Injection via order_by Parameter (HIGH severity) Added ALLOWED_ORDER_COLUMNS frozenset as an allowlist for permitted column names in the ORDER BY clause. The query() method now validates order_by against this allowlist and defaults to "timestamp" if an invalid value is provided. This prevents SQL injection attacks where malicious input like 'timestamp; DROP TABLE traffic_logs; --' could be injected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dcc0401 commit 065774a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

networksecurity/stats/traffic_logger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class TrafficLogger:
2323
流量日志记录器
2424
使用SQLite存储日志,支持高并发写入和查询
2525
"""
26+
27+
# Allowlist of permitted column names for ORDER BY clause (prevents SQL injection)
28+
ALLOWED_ORDER_COLUMNS = frozenset([
29+
'id', 'timestamp', 'source_ip', 'dest_ip', 'dest_port', 'protocol',
30+
'method', 'threat_type', 'risk_level', 'risk_score', 'action',
31+
'processing_time_ms'
32+
])
2633

2734
def __init__(self, db_path: str = None):
2835
"""
@@ -307,6 +314,10 @@ def query(
307314

308315
where_clause = " AND ".join(conditions) if conditions else "1=1"
309316
order_direction = "DESC" if order_desc else "ASC"
317+
318+
# Validate order_by against allowlist to prevent SQL injection
319+
if order_by not in self.ALLOWED_ORDER_COLUMNS:
320+
order_by = "timestamp"
310321

311322
query = f'''
312323
SELECT * FROM traffic_logs

0 commit comments

Comments
 (0)