Skip to content

Feat/vpn interface#2

Open
NamSupawan wants to merge 127 commits intomainfrom
feat/vpn_interface
Open

Feat/vpn interface#2
NamSupawan wants to merge 127 commits intomainfrom
feat/vpn_interface

Conversation

@NamSupawan
Copy link
Copy Markdown

No description provided.

config_file = params[:config_file]
output, status = Open3.capture2e("sudo wg-quick up #{config_file}")

output, status = Open3.capture2e("sudo wg-quick up #{config_file}")

Check failure

Code scanning / CodeQL

Uncontrolled command line Critical

This command depends on a
user-provided value
.

Copilot Autofix

AI 10 months ago

To fix the issue, we need to ensure that the config_file parameter is validated and sanitized before being used in the shell command. The best approach is to whitelist acceptable values for config_file and reject any input that does not match the whitelist. This ensures that only predefined, safe values can be used in the command.

Steps to implement the fix:

  1. Define a whitelist of acceptable configuration file names or paths.
  2. Validate the config_file parameter against the whitelist.
  3. If the input is invalid, return an error message to the user instead of executing the command.
  4. Use hard-coded string literals for the command whenever possible, avoiding direct interpolation of user input.

Suggested changeset 1
app/controllers/vpn_devices_controller.rb

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/controllers/vpn_devices_controller.rb b/app/controllers/vpn_devices_controller.rb
--- a/app/controllers/vpn_devices_controller.rb
+++ b/app/controllers/vpn_devices_controller.rb
@@ -73,7 +73,12 @@
     config_file = params[:config_file]
-    output, status = Open3.capture2e("sudo wg-quick up #{config_file}")   
-    if status.success?
-      redirect_to vpn_devices_path, notice: 'WireGuard interface created successfully.'
+    allowed_files = ['wg0.conf', 'wg1.conf'] # Example whitelist of allowed config files
+    if allowed_files.include?(config_file)
+      output, status = Open3.capture2e("sudo wg-quick up #{config_file}")
+      if status.success?
+        redirect_to vpn_devices_path, notice: 'WireGuard interface created successfully.'
+      else
+        redirect_to new_vpn_device_path, alert: "Failed to create WireGuard interface:\n#{output}"
+      end
     else
-      redirect_to new_vpn_device_path, alert: "Failed to create WireGuard interface:\n#{output}"
+      redirect_to new_vpn_device_path, alert: 'Invalid configuration file specified.'
     end
EOF
@@ -73,7 +73,12 @@
config_file = params[:config_file]
output, status = Open3.capture2e("sudo wg-quick up #{config_file}")
if status.success?
redirect_to vpn_devices_path, notice: 'WireGuard interface created successfully.'
allowed_files = ['wg0.conf', 'wg1.conf'] # Example whitelist of allowed config files
if allowed_files.include?(config_file)
output, status = Open3.capture2e("sudo wg-quick up #{config_file}")
if status.success?
redirect_to vpn_devices_path, notice: 'WireGuard interface created successfully.'
else
redirect_to new_vpn_device_path, alert: "Failed to create WireGuard interface:\n#{output}"
end
else
redirect_to new_vpn_device_path, alert: "Failed to create WireGuard interface:\n#{output}"
redirect_to new_vpn_device_path, alert: 'Invalid configuration file specified.'
end
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants