Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def check_env_permissions(env_path: str = ".env") -> None:
API_BASE = "https://api.controld.com/profiles"
USER_AGENT = "Control-D-Sync/0.1.0"

# Pre-compile regex for performance
RULE_PATTERN = re.compile(r"^[a-zA-Z0-9.\-_:*\/]+$")


def sanitize_for_log(text: Any) -> str:
"""Sanitize text for logging, ensuring TOKEN is redacted and control chars are escaped."""
Expand Down Expand Up @@ -427,7 +430,8 @@ def is_valid_rule(rule: str) -> bool:

# Strict whitelist to prevent injection
# ^[a-zA-Z0-9.\-_:*\/]+$
if not re.match(r"^[a-zA-Z0-9.\-_:*\/]+$", rule):
# Optimization: Use pre-compiled regex to save compilation overhead
if not RULE_PATTERN.match(rule):
return False

return True
Expand Down
Loading