-
Notifications
You must be signed in to change notification settings - Fork 79
fix: Require an explicit opt in to unsafety; defer decision to call time #246
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
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 |
|---|---|---|
|
|
@@ -23,7 +23,13 @@ | |
|
|
||
| # Set this to True to log all the code and globals being executed. | ||
| LOG_ALL_CODE = False | ||
| # Set this to True to use the unsafe code, so that you can debug it. | ||
|
|
||
| # Set this to True to run submitted code with no confinement and no sandbox. | ||
| # | ||
| # WARNING: This is deeply dangerous; anyone who can submit code can take | ||
| # over the computer immediately and entirely. | ||
| # | ||
| # The only purpose of this setting is for local debugging. | ||
| ALWAYS_BE_UNSAFE = False | ||
|
Contributor
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. is there a code path that sets this to True somewhere?
Contributor
Author
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. Not an existing one, no. This would be in case some application that was integrating codejail needed to enable unsafe mode. |
||
|
|
||
|
|
||
|
|
@@ -80,8 +86,22 @@ def safe_exec( | |
| the code raises an exception, this function will raise `SafeExecException` | ||
| with the stderr of the sandbox process, which usually includes the original | ||
| exception message and traceback. | ||
|
|
||
| """ | ||
| if ALWAYS_BE_UNSAFE: | ||
| not_safe_exec( | ||
| code, | ||
| globals_dict, | ||
| files=files, | ||
| python_path=python_path, | ||
| limit_overrides_context=limit_overrides_context, | ||
| slug=slug, | ||
| extra_files=extra_files, | ||
| ) | ||
| return | ||
|
|
||
| if not jail_code.is_configured('python'): | ||
| raise RuntimeError("safe_exec has not been configured for Python") | ||
robrap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| the_code = [] | ||
|
|
||
| files = list(files or ()) | ||
|
|
@@ -257,6 +277,11 @@ def not_safe_exec( | |
| Note that `limit_overrides_context` is ignored here, because resource limits | ||
| are not applied. | ||
| """ | ||
| # Because it would be bad if this function were used in production, | ||
| # let's log a warning when it is used. Developers can live with | ||
| # one more log line. | ||
| log.warning("DANGER: Executing code with `not_safe_exec` for %s", slug) | ||
robrap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| g_dict = json_safe(globals_dict) | ||
|
|
||
| with temp_directory() as tmpdir: | ||
|
|
@@ -286,22 +311,3 @@ def not_safe_exec( | |
| sys.path = original_path | ||
|
|
||
| globals_dict.update(json_safe(g_dict)) | ||
|
|
||
|
|
||
| # If the developer wants us to be unsafe (ALWAYS_BE_UNSAFE), or if there isn't | ||
| # a configured jail for Python, then we'll be UNSAFE. | ||
| UNSAFE = ALWAYS_BE_UNSAFE or not jail_code.is_configured("python") | ||
|
|
||
| if UNSAFE: # pragma: no cover | ||
| # Make safe_exec actually call not_safe_exec, but log that we're doing so. | ||
|
|
||
| def safe_exec(*args, **kwargs): # pylint: disable=E0102 | ||
| """An actually-unsafe safe_exec, that warns it's being used.""" | ||
|
|
||
| # Because it would be bad if this function were used in production, | ||
| # let's log a warning when it is used. Developers can live with | ||
| # one more log line. | ||
| slug = kwargs.get('slug', None) | ||
| log.warning("Using codejail/safe_exec.py:not_safe_exec for %s", slug) | ||
|
|
||
| return not_safe_exec(*args, **kwargs) | ||
Uh oh!
There was an error while loading. Please reload this page.