Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30871 > unrolled thread

Re: Executing untrusted scripts in a sandboxed environment

Started byChris Angelico <rosuav@gmail.com>
First post2012-10-06 17:19 +1000
Last post2012-10-06 19:23 +1000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Executing untrusted scripts in a sandboxed environment Chris Angelico <rosuav@gmail.com> - 2012-10-06 17:19 +1000
    Re: Executing untrusted scripts in a sandboxed environment Ramchandra Apte <maniandram01@gmail.com> - 2012-10-06 02:10 -0700
      Re: Executing untrusted scripts in a sandboxed environment Chris Angelico <rosuav@gmail.com> - 2012-10-06 19:23 +1000

#30871 — Re: Executing untrusted scripts in a sandboxed environment

FromChris Angelico <rosuav@gmail.com>
Date2012-10-06 17:19 +1000
SubjectRe: Executing untrusted scripts in a sandboxed environment
Message-ID<mailman.1894.1349507969.27098.python-list@python.org>
On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl <me@robin-krahl.de> wrote:
> Hi all,
>
> I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting.
>
> I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide?

With extreme difficulty. A while back (couple years maybe? I don't
remember), I ignored everyone's warnings and tried to make a sandboxed
Python, embedded in a C++ application. It failed in sandboxing. With
just some trivial tinkering using Python's introspection facilities, a
couple of python-list people managed to read and write files, and
other equally dangerous actions. Shortly thereafter, we solved the
problem completely... by switching to JavaScript.

Embedding CPython in an application simply doesn't afford sandboxing.
To what extent do you actually need to run untrusted Python? Can you,
for instance, sandbox the entire process (which wasn't an option for
what we were doing)? Perhaps chrooting the Python interpreter will do
what you need. But there may still be leaks, I don't know.

ChrisA

[toc] | [next] | [standalone]


#30876

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-10-06 02:10 -0700
Message-ID<3585c6f6-4152-4163-873b-396a0f73ba3b@googlegroups.com>
In reply to#30871
On Saturday, 6 October 2012 12:49:29 UTC+5:30, Chris Angelico  wrote:
> On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl <me@robin-krahl.de> wrote:
> 
> > Hi all,
> 
> >
> 
> > I need to execute untrusted scripts in my Python application. To avoid security issues, I want to use a sandboxed environment. This means that the script authors have no access to the file system. They may only access objects, modules and classes that are "flagged" or "approved" for scripting.
> 
> >
> 
> > I read that I will not be able to do this with Python scripts. (See SandboxedPython page in the Python wiki [0] and several SE.com questions, e. g. [1].) So my question is: What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide?
> 
> 
> 
> With extreme difficulty. A while back (couple years maybe? I don't
> 
> remember), I ignored everyone's warnings and tried to make a sandboxed
> 
> Python, embedded in a C++ application. It failed in sandboxing. With
> 
> just some trivial tinkering using Python's introspection facilities, a
> 
> couple of python-list people managed to read and write files, and
> 
> other equally dangerous actions. Shortly thereafter, we solved the
> 
> problem completely... by switching to JavaScript.
> 
> 
> 
> Embedding CPython in an application simply doesn't afford sandboxing.
> 
> To what extent do you actually need to run untrusted Python? Can you,
> 
> for instance, sandbox the entire process (which wasn't an option for
> 
> what we were doing)? Perhaps chrooting the Python interpreter will do
> 
> what you need. But there may still be leaks, I don't know.
> 
> 
> 
> ChrisA

Something like ast.literal_eval may be useful.

[toc] | [prev] | [next] | [standalone]


#30879

FromChris Angelico <rosuav@gmail.com>
Date2012-10-06 19:23 +1000
Message-ID<mailman.1897.1349515398.27098.python-list@python.org>
In reply to#30876
On Sat, Oct 6, 2012 at 7:10 PM, Ramchandra Apte <maniandram01@gmail.com> wrote:
> On Saturday, 6 October 2012 12:49:29 UTC+5:30, Chris Angelico  wrote:
>> On Sat, Oct 6, 2012 at 8:22 AM, Robin Krahl <me@robin-krahl.de> wrote:
>> > What is the best way to "embed" a script engine in a sandboxed environment that has access to the Python modules and classes that I provide?
>>
>> With extreme difficulty.
>
> Something like ast.literal_eval may be useful.

Not really; it's hardly sufficient. That sort of feature is handy for
making an expression evaluator; for instance, you could implement a
powerful calculator with it. But it's far too limited for most
applications.

The main problem is permitting some of the basic builtins (like True,
False, len(), etc), without those objects being used as gateways. Did
you know, for instance, that len.__self__.open() can be used to read
and write files on the file system?

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web