Skip to content

security: fix reverse shell vulnerability in function library. #2830

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

Conversation

shaohuzhang1
Copy link
Contributor

security: fix reverse shell vulnerability in function library.

Copy link

f2c-ci-robot bot commented Apr 9, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Apr 9, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -88,7 +88,7 @@ def _exec_sandbox(self, _code, _id):
os.system(f"chown {self.user}:{self.user} {exec_python_file}")
kwargs = {'cwd': BASE_DIR}
subprocess_result = subprocess.run(
['su', '-c', python_directory + ' ' + exec_python_file, self.user],
['su', '-s', python_directory, '-c', "exec(open('" + exec_python_file + "').read())", self.user],
text=True,
capture_output=True, **kwargs)
os.remove(exec_python_file)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided `su` command is incorrect because it uses `-s`, which changes the shell to `/bin/sh`. To execute Python directly from a file, use `'bash'` instead of specifying the shell separately.

Here's an optimized version:

```python
subprocess.run(
    ['su', '-c', f"exec(open('{exec_python_file}').read())", self.user],
    text=True,
    capture_output=True, **kwargs)

This assumes that you are using Linux with Bash. If your system uses a different default shell, adjust the arguments accordingly.

@liqiang-fit2cloud liqiang-fit2cloud merged commit 4ae02c8 into main Apr 9, 2025
4 of 5 checks passed
@liqiang-fit2cloud liqiang-fit2cloud deleted the pr@main@fix_reverse_shell_vulnerability_in_function_library branch April 9, 2025 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants