Skip to content

UserCodeService.is_execution_allowed() allows invalid output policy execution #9391

@kevinm207

Description

@kevinm207

Description

The UserCodeService.is_execution_allowed() method contains a logic error that causes it to ignore the boolean return value from output_policy.is_valid(). This results in execution being allowed even when the output policy should deny it.

Current Behavior

The method uses a try/except block but only checks for exceptions raised by output_policy.is_valid():

  • Exception is raised → returns IsExecutionAllowedEnum.INVALID_OUTPUT_POLICY
  • No exception is raised → always returns IsExecutionAllowedEnum.ALLOWED

The boolean return value from is_valid() is ignored.

Code Reference:

try:
output_policy.is_valid(context)
except Exception:
return IsExecutionAllowedEnum.INVALID_OUTPUT_POLICY
return IsExecutionAllowedEnum.ALLOWED

Expected Behavior

Based on the method signatures of OutputPolicy classes, the implementation should:

  1. Call output_policy.is_valid() and capture its boolean return value
  2. Return IsExecutionAllowedEnum.ALLOWED only if is_valid() returns True
  3. Return IsExecutionAllowedEnum.INVALID_OUTPUT_POLICY if is_valid() returns False OR raises an exception (e.g., NotImplementedError)

Impact

This bug allows policy violations, including multiple executions of SingleExecutionExactOutput which run without the server returning cached ExecutionOutput values to the client in violation of the intended policy control that should limit execution to a single run

Suggested Fix

Modify the method to check the boolean return value:

try:
    is_valid = output_policy.is_valid()
    if not is_valid:
        return IsExecutionAllowedEnum.INVALID_OUTPUT_POLICY
    return IsExecutionAllowedEnum.ALLOWED
except Exception:
    return IsExecutionAllowedEnum.INVALID_OUTPUT_POLICY

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