Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: Untrusted code execution Date: Wed, 06 Apr 2016 09:14:56 -0400 Lines: 36 Message-ID: References: <58de161a-ecdb-4ada-aab5-871876ea1574@googlegroups.com> <570469d7$0$1598$c3e8da3$5496439d@news.astraweb.com> <1459948496.786520.570667177.4C7E8044@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de HfrpabsAP9xP3iaHMqq0kQaaOaIaLLcezYWpitzn2Zdw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'sys': 0.05; 'subject:code': 0.07; 'loaded,': 0.09; 'name)': 0.09; 'received:internal': 0.09; 'def': 0.13; 'argument': 0.15; 'interpreter': 0.15; 'forbid': 0.16; "guido's": 0.16; 'len': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'usability': 0.18; '(in': 0.18; 'language': 0.19; 'load': 0.20; 'library': 0.20; 'features,': 0.22; 'keyerror:': 0.22; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'module': 0.25; 'module.': 0.27; 'code"': 0.29; 'str': 0.29; 'raise': 0.29; 'print': 0.30; 'especially': 0.32; "d'aprano": 0.33; 'int': 0.33; 'steven': 0.33; 'tue,': 0.34; 'except': 0.34; 'could': 0.35; 'too': 0.36; 'modules': 0.36; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'skip:p 20': 0.38; 'to:addr:python.org': 0.40; 'header:Message-Id:1': 0.61; 'real': 0.62; 'useful.': 0.72; '"best': 0.84; 'reducing': 0.93 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=unlNkGleryJuvZd2bfaH9paATHo=; b=ivQqEO JWB9KJjQFwyNzS218EgmAxTueIeT2H8kY06DWsAotHVuxC6fvswkMUaqHlOvmJUN q0E/dnI+gcNx9liF2NgwJ3D0IWyigGsSQB/zF1wt46+3Gcl41lfgdy3gsNXmEa+L tvGNEdfPGVGM9ewMsrc0jeCX5fExklc5fE4ws= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=unlNkGleryJuvZd 2bfaH9paATHo=; b=KFicFaUNOhhgXBujolt61hXpCj3fDmv9SgTRO9ZKZwg/ykz uzeprkA4jDdSvpk9vRvm2x3k9Mnx2f1heKHy3CpnyZmOEVK5NF49dzypvrLMUbGe JCrqsKrS5D+dclf2qvIbQ6OHsu63mUNSn1XUoJcCyBkPyTCErPSHaN2bz+xY= X-Sasl-Enc: ry1Wkh4I8SDHS1JJNZajKZx8vyisUaDkkCAO/OMpX//e 1459948496 X-Mailer: MessagingEngine.com Webmail Interface - ajax-6aa5290f In-Reply-To: <570469d7$0$1598$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1459948496.786520.570667177.4C7E8044@webmail.messagingengine.com> X-Mailman-Original-References: <58de161a-ecdb-4ada-aab5-871876ea1574@googlegroups.com> <570469d7$0$1598$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:106572 On Tue, Apr 5, 2016, at 21:43, Steven D'Aprano wrote: > As Zooko says, Guido's "best argument is that reducing usability (in > terms > of forbidding language features, especially module import) and reducing > the > usefulness of extant library code" would make the resulting interpreter > too > feeble to be useful. You don't have to forbid module import. The sandbox could control what modules can be loaded, and what happens when you try to load a module. import sys module = type(sys) fm = {} def fimp(name, *etc): # In a real implementation, this could also load whitelisted modules try: return fm[name] except KeyError: raise ImportError("Tried to load restricted module " + name) fm['builtins'] = fb = module('builtins') fb.int = int fb.str = str fb.len = len fb.print = print fb.__import__ = fimp fm['sys'] = fsys = module('sys') fsys.modules = fm exec(""" import sys print(sys.modules.keys()) """, {'__builtins__': fb})