Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
fix: disable Plex plugin framework sandbox and add back all missing b…
Browse files Browse the repository at this point in the history
…uiltins (#228)
  • Loading branch information
zdimension authored Nov 21, 2023
1 parent eb07188 commit 3180e9c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

# standard imports
import inspect
import re

# plex debugging
Expand All @@ -24,6 +25,21 @@
# imports from Libraries\Shared
from typing import Optional

try:
# get the original Python builtins module
python_builtins = inspect.getmodule(object)

# get the Sandbox instance
sandbox = inspect.stack()[1][0].f_locals["self"]

# bypass RestrictedPython
getattr(sandbox, "_core").loader.compile = lambda src, name, _=False: python_builtins.compile(src, name, "exec")

# restore Python builtins
sandbox.environment.update(python_builtins.vars(python_builtins))
except Exception as e:
Log.Exception("Failed to bypass RestrictedPython: {}".format(e))

# local imports
from default_prefs import default_prefs
from constants import contributes_to, version
Expand Down

0 comments on commit 3180e9c

Please sign in to comment.