Skip to content

Codejail safe_exec makes "unsafe=true" decision at startup #225

@timmc-edx

Description

@timmc-edx

When the codejail.safe_exec module is imported, it decides immediately whether to run in unsafe mode:

UNSAFE = ALWAYS_BE_UNSAFE or not jail_code.is_configured("python")

This means that codejail must be fully configured before it is imported. Any module that imports this one (usually for safe_exec or SafeExecException) must itself be imported after this point. This might work if the relying code is a Django app and if the ConfigureCodeJailMiddleware is in effect, but a small change could still cause codejail to start loading in unsafe mode.

It would likely be better to have the safe_exec function decide at call-time whether to branch to not_safe_exec, as this would allow service startup to occur in any order (as long as codejail.jail_code.configure is called at some point before safe_exec starts being called).

This change could be made as part of an unsafe-mode deprecation, which would likely entail requiring an explicit opt-in for unsafe-exec (only used for unit tests) rather than defaulting to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions