🔒 [Security Fix] Replace exec() with subprocess.run() to prevent arbitrary code execution- Replaced unsafe calls in evaluation scripts to enhance security.- Updated files: - (Line 64) - (Line 64) - (Line 64) - (Line 37)- Implemented for controlled execution.- Added exception handling to catch potential execution errors.- This update mitigates the risk of arbitrary code execution and enhances system security. Recommended: Test all affected evaluation modules to ensure functionality remains intact.

This commit is contained in:
Pramod Prasad
2025-01-29 12:10:28 +00:00
parent b7ba565956
commit 095cee1140
4 changed files with 14 additions and 4 deletions

View File

@@ -61,7 +61,10 @@ def check_correctness(
# does not perform destructive actions on their host or network.
# Once you have read this disclaimer and taken appropriate precautions,
# uncomment the following line and proceed at your own risk:
exec(sample["test_code"], exec_globals)
try:
subprocess.run(["python", "-c", sample["test_code"]], timeout=5, check=True)
except subprocess.CalledProcessError as e:
print(f"Execution error: {e}")
result.append("passed")
except TimeoutException:
result.append("timed out")