From 79d33db2bf3490e32a613499b4ad0a95bc7a8016 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 8 Mar 2024 11:27:44 +0100 Subject: [PATCH] Revert "Sanitize path to prevent directory traversal" This reverts commit 2cdf6ef53e8c5ee2f48da652143fdfe5776d1663. --- .gitignore | 1 + api/modules/wireguard.py | 16 ++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index a2a77b49..245d6fa4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ yarn-error.log includes/config.php rootCA.pem vendor +.env diff --git a/api/modules/wireguard.py b/api/modules/wireguard.py index d7470e69..904d87bb 100644 --- a/api/modules/wireguard.py +++ b/api/modules/wireguard.py @@ -1,6 +1,5 @@ import subprocess import re -import os def configs(): #ignore symlinks, because wg0.conf is in production the main config, but in insiders it is a symlink @@ -25,16 +24,13 @@ def client_config_list(client_config): if not re.match(pattern, client_config): raise ValueError("Invalid client_config") - # sanitize path to prevent directory traversal - client_config = os.path.basename(client_config) - - config_path = os.path.join("/etc/wireguard/", client_config) - if not os.path.exists(config_path): + config_path = f"/etc/wireguard/{client_config}" + try: + with open(config_path, 'r') as f: + output = f.read().strip() + return output.split('\n') + except FileNotFoundError: 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: is service connected?