Validate client_config path expression

This commit is contained in:
billz 2024-03-08 09:08:53 +01:00
parent b567f565d9
commit 95ad90063b

View file

@ -1,4 +1,5 @@
import subprocess import subprocess
import re
def configs(): def configs():
#ignore symlinks, because wg0.conf is in production the main config, but in insiders it is a symlink #ignore symlinks, because wg0.conf is in production the main config, but in insiders it is a symlink
@ -19,6 +20,10 @@ def client_config_active():
return(active_config[1]) return(active_config[1])
def client_config_list(client_config): def client_config_list(client_config):
pattern = r'^[a-zA-Z0-9_-]+$'
if not re.match(pattern, client_config):
raise ValueError("Invalid client_config")
config_path = f"/etc/wireguard/{client_config}" config_path = f"/etc/wireguard/{client_config}"
try: try:
with open(config_path, 'r') as f: with open(config_path, 'r') as f: