Sanitize path to prevent directory traversal

This commit is contained in:
billz 2024-03-08 11:15:31 +01:00
parent ef7b67a445
commit 2cdf6ef53e
2 changed files with 10 additions and 7 deletions

1
.gitignore vendored
View file

@ -5,4 +5,3 @@ yarn-error.log
includes/config.php includes/config.php
rootCA.pem rootCA.pem
vendor vendor
.env

View file

@ -1,5 +1,6 @@
import subprocess import subprocess
import re import re
import os
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
@ -24,13 +25,16 @@ def client_config_list(client_config):
if not re.match(pattern, client_config): if not re.match(pattern, client_config):
raise ValueError("Invalid client_config") raise ValueError("Invalid client_config")
config_path = f"/etc/wireguard/{client_config}" # sanitize path to prevent directory traversal
try: client_config = os.path.basename(client_config)
with open(config_path, 'r') as f:
output = f.read().strip() config_path = os.path.join("/etc/wireguard/", client_config)
return output.split('\n') if not os.path.exists(config_path):
except FileNotFoundError:
raise FileNotFoundError("Client configuration file not found") raise FileNotFoundError("Client configuration file not found")
with open(config_path, 'r') as f:
output = f.read().strip()
return output.split('\n')
#TODO: where is the logfile?? #TODO: where is the logfile??
#TODO: is service connected? #TODO: is service connected?