-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix python.lang.security.audit.exec-detected.exec-detected #1679
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,25 +24,16 @@ def add_to_env(self, key: str, value: Any) -> None: | |
""" | ||
self._environment[key] = value | ||
|
||
def execute(self, code: str) -> dict: | ||
try: | ||
exec(code, self._environment) | ||
except Exception as e: | ||
raise CodeExecutionError("Code execution failed") from e | ||
return self._environment | ||
|
||
def execute_and_return_result(self, code: str) -> Any: | ||
def execute( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add or update unit tests to cover the new |
||
self, code: str, context: Optional[Dict[str, Any]] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newly added |
||
) -> CodeExecutionResult: | ||
""" | ||
Executes the return updated environment | ||
""" | ||
self.execute(code) | ||
|
||
# Get the result | ||
if "result" not in self._environment: | ||
raise NoResultFoundError("No result returned") | ||
Execute the code and return the result. | ||
|
||
return self._environment.get("result", None) | ||
Args: | ||
code (str): The code to execute. | ||
context (Dict[str, Any], optional): The context to execute the code in. | ||
|
||
@property | ||
def environment(self) -> dict: | ||
return self._environment | ||
Returns: | ||
CodeExecutionResult: The result of the code execution. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing import for
Optional
,Dict
, and definition forCodeExecutionResult
. Ensure these types are imported or defined.