Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

timmc-edx
Copy link
Contributor

@timmc-edx timmc-edx commented May 9, 2025

Codejail currently makes a decision at module load time of whether it should run all code safely or unsafely, and defaults to unsafely. This causes several problems:

  • Any misconfiguration of codejail (such as a missing Django setting or middleware) results in the application becoming immediately and entirely vulnerable to anyone who can submit code.
  • Codejail's behavior changes depending on when the codejail.safe_exec module is loaded during application initialization. This causes unstable behavior and is confusing for developers.

This change switches the ALWAYS_BE_UNSAFE check to occur only at the time that safe_exec is actually called, rather than at module load time.

The check for whether codejail is configured for Python is also moved to call time, but no longer automatically switches codejail to unsafe mode. Instead, it raises an exception to notify the user of their error.

This addresses #16

@timmc-edx timmc-edx force-pushed the timmc/safe_by_default branch 4 times, most recently from 57aebd3 to 0621d9c Compare May 9, 2025 21:32
@timmc-edx timmc-edx marked this pull request as ready for review May 9, 2025 21:33
@timmc-edx timmc-edx changed the title feat!: Require an explicit opt in to unsafety; defer decision to call time fix: Require an explicit opt in to unsafety; defer decision to call time May 9, 2025
Codejail currently makes a decision at module load time of whether it
should run all code safely or unsafely, and defaults to unsafely. This
causes several problems:

- Any misconfiguration of codejail (such as a missing Django setting or
  middleware) results in the application becoming immediately and entirely
  vulnerable to anyone who can submit code.
- Codejail's behavior changes depending on when the `codejail.safe_exec`
  module is loaded during application initialization. This causes unstable
  behavior and is confusing for developers.

This change switches the `ALWAYS_BE_UNSAFE` check to occur only at the time
that `safe_exec` is actually called, rather than at module load time.

The check for whether codejail is configured for Python is also moved to
call time, but no longer automatically switches codejail to unsafe mode.
Instead, it raises an exception to notify the user of their error.
timmc-edx added 2 commits May 13, 2025 17:10
Code:

- Make log message scarier

Docs:

- Remove now-incorrect description of falling back to unsafe mode
- Add bold warning
- Expand on AppArmor requirements

Tests:

- Add tests for code changes.
- Remove auto-skip based on ALWAYS_BE_UNSAFE, which no longer gets computed
  at module load time; it will always be false unless explicitly set.

Also, add some docs around how testing works.
@timmc-edx timmc-edx requested a review from MoisesGSalas May 14, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants