mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-10 22:41:06 +00:00
feat(memory_store): add input validation for store_name to prevent SQL injection
This commit is contained in:
parent
05e87afbd2
commit
a1ea1f24b9
1 changed files with 8 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
"""Base storage interface for memory manager."""
|
||||
|
||||
import re
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from ..embedding import BaseEmbeddingModel
|
||||
|
|
@ -19,6 +20,13 @@ class BaseMemoryStore(ABC):
|
|||
**kwargs,
|
||||
):
|
||||
"""Initialize"""
|
||||
# Validate store_name to prevent SQL injection
|
||||
# Only allow alphanumeric characters and underscores
|
||||
if not re.match(r"^[a-zA-Z0-9_]+$", store_name):
|
||||
raise ValueError(
|
||||
f"Invalid store_name: '{store_name}'. "
|
||||
"Only alphanumeric characters and underscores are allowed."
|
||||
)
|
||||
self.store_name: str = store_name
|
||||
self.embedding_model: BaseEmbeddingModel = embedding_model
|
||||
self.fts_enabled: bool = fts_enabled
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue