Open
Conversation
| 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
Show autofix suggestion
Hide autofix suggestion
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:
- Define a whitelist of acceptable configuration file names or paths.
- Validate the
config_fileparameter against the whitelist. - If the input is invalid, return an error message to the user instead of executing the command.
- 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
| @@ -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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.