Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/simultaneous_queues] Improved version for scenario management #29

Merged
merged 39 commits into from
Dec 16, 2024

Conversation

enriquetomasmb
Copy link
Collaborator

No description provided.

FerTV and others added 30 commits November 21, 2024 19:31
@enriquetomasmb enriquetomasmb requested a review from FerTV December 16, 2024 10:27
scenario_commands_file = os.path.join(
nebula_config_dir, scenario_name, "current_scenario_commands.sh"
)
if os.path.exists(scenario_commands_file):

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to validate the scenario_name before using it to construct file paths. We can use the os.path.normpath function to normalize the path and ensure it is contained within a safe root directory. Additionally, we can use a whitelist of allowed characters to further sanitize the scenario_name.

  1. Normalize the scenario_name using os.path.normpath.
  2. Ensure the normalized path starts with the expected base directory.
  3. Optionally, sanitize the scenario_name to allow only specific characters.
Suggested changeset 1
nebula/scenarios.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/nebula/scenarios.py b/nebula/scenarios.py
--- a/nebula/scenarios.py
+++ b/nebula/scenarios.py
@@ -397,2 +397,6 @@
             if scenario_name:
+                # Normalize and validate scenario_name
+                scenario_name = os.path.normpath(scenario_name)
+                if not scenario_name.startswith(nebula_config_dir):
+                    raise Exception("Invalid scenario name")
                 if os.environ.get("NEBULA_HOST_PLATFORM") == "windows":
EOF
@@ -397,2 +397,6 @@
if scenario_name:
# Normalize and validate scenario_name
scenario_name = os.path.normpath(scenario_name)
if not scenario_name.startswith(nebula_config_dir):
raise Exception("Invalid scenario name")
if os.environ.get("NEBULA_HOST_PLATFORM") == "windows":
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
nebula_config_dir, scenario_name, "current_scenario_commands.sh"
)
if os.path.exists(scenario_commands_file):
os.remove(scenario_commands_file)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
This path depends on a
user-provided value
.

Copilot Autofix AI 3 months ago

To fix the problem, we need to validate the scenario_name before using it to construct file paths. We can use the os.path.normpath function to normalize the path and ensure it is contained within a safe root directory. Additionally, we can use a whitelist of allowed characters to further sanitize the scenario_name.

  1. Normalize the scenario_name using os.path.normpath.
  2. Ensure the normalized path starts with the expected base directory.
  3. Use a whitelist of allowed characters to sanitize the scenario_name.
Suggested changeset 1
nebula/scenarios.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/nebula/scenarios.py b/nebula/scenarios.py
--- a/nebula/scenarios.py
+++ b/nebula/scenarios.py
@@ -397,2 +397,6 @@
             if scenario_name:
+                # Normalize and validate scenario_name
+                scenario_name = os.path.normpath(scenario_name)
+                if not scenario_name.isalnum():
+                    raise ValueError("Invalid scenario name")
                 if os.environ.get("NEBULA_HOST_PLATFORM") == "windows":
EOF
@@ -397,2 +397,6 @@
if scenario_name:
# Normalize and validate scenario_name
scenario_name = os.path.normpath(scenario_name)
if not scenario_name.isalnum():
raise ValueError("Invalid scenario name")
if os.environ.get("NEBULA_HOST_PLATFORM") == "windows":
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@enriquetomasmb enriquetomasmb merged commit aebcbbb into main Dec 16, 2024
2 of 5 checks passed
@enriquetomasmb enriquetomasmb deleted the feature/simultaneous_queues branch January 27, 2025 17:17
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