-
Notifications
You must be signed in to change notification settings - Fork 0
Codescanning fix march8 #59
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
os.makedirs(save_path, exist_ok=True) | ||
with open(os.path.join(save_path, "config.json"), "w") as f: | ||
with open(f"{save_path}/config.json", "w") as f: |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 months ago
To fix the problem, we need to validate and sanitize the user-provided aml_dataset
before using it to construct the file path. We can use os.path.normpath
to normalize the path and ensure it does not contain any malicious segments. Additionally, we can check that the resulting path is within a safe root directory.
- Normalize the
aml_dataset
value usingos.path.normpath
. - Ensure that the normalized path does not contain any segments that could lead to directory traversal.
- Construct the
experiment_id
andsave_path
using the sanitizedaml_dataset
.
-
Copy modified lines R175-R177
@@ -174,3 +174,5 @@ | ||
current_time = pd.Timestamp.now().strftime("%Y-%m-%d_%H%M%S") | ||
aml_dataset = parsed_config.aml_dataset | ||
aml_dataset = os.path.normpath(parsed_config.aml_dataset) | ||
if os.path.isabs(aml_dataset) or ".." in aml_dataset.split(os.path.sep): | ||
raise ValueError("Invalid aml_dataset value.") | ||
experiment_id = f"RAG-Bot-Eval_Dataset_eq_{aml_dataset}_Start_eq_{current_time}" |
@@ -719,14 +713,11 @@ | |||
|
|||
combined_results = { | |||
"config": config.__dict__, | |||
"metrics": json.load(open(os.path.normpath(os.path.join(current_dir, "results", config.experiment_id, "run_metrics.json")))), | |||
"answers": pd.read_csv(os.path.normpath(os.path.join(current_dir, "results", config.experiment_id, "run_details.csv"))).to_dict(), | |||
"metrics": json.load(open(f"{current_dir}/results/{config.experiment_id}/run_metrics.json")), |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
json.dump( | ||
combined_results, open(metrics_path, "w"), indent=4 | ||
combined_results, open(f"{current_dir}/results/{config.experiment_id}/combined_results.json", "w"), indent=4 |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
Purpose
Does this introduce a breaking change?
Pull Request Type
What kind of change does this Pull Request introduce?
How to Test
What to Check
Verify that the following are valid
Other Information