Path: csiph.com!news.swapon.de!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'properly.': 0.07; 'cc:addr:python-list': 0.09; '*is*': 0.09; 'builtins': 0.09; 'operator,': 0.09; 'do,': 0.15; '"use': 0.16; '23,': 0.16; 'attributes.': 0.16; 'eval': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'literal,': 0.16; 'stuff.': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'proposed': 0.20; 'lawrence': 0.22; 'please?': 0.22; 'sorry,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'end,': 0.29; "i'm": 0.30; 'code': 0.30; "can't": 0.32; 'maybe': 0.33; 'received:google.com': 0.35; 'but': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'mark': 0.40; 'still': 0.40; 'more': 0.63; 'safe': 0.63; 'believe': 0.66; 'here': 0.66; 'talking': 0.67; 'url:r': 0.67; 'subject': 0.70; 'led': 0.72; 'chrisa': 0.84; 'to:none': 0.91; 'safe.': 0.93; 'url:comments': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=JkBrPgrbHfSHUUTT11VVaATkug23nvGdwonGv5DMVgw=; b=weQ5PSKICCVD7g1YeFTSYeyAw/bd6+pHnoFhLvwJaTF8MgCZ/Iigk04r4m6/pD/gZa dtikJOZxbzEIeOiWIXfKjBx+QSjjrCb2r+28P+Ivamf2+9kQuZEhchf6sBSNsfJkn9v0 aWOxVBGobrJ93NAWA2YLIlyw9n52h2WoaSuXBfRwfIKYfbtUqBuS+9JPNJ1HGgw9fAdF Y/FOFx5s0s2Pyx4kFUPPCBSFeo1bxZS+OkhHzFTp9DQSkuz6kfZfF0u2tVH4YyIN8+PY roWgrxZYSuf7Tuq9EBLoBA6VTxqckrT+JluMCc0W9WJu50nSeGuzuB/4dGIyc3pnZkTN DLPQ== MIME-Version: 1.0 X-Received: by 10.107.12.166 with SMTP id 38mr12420073iom.157.1440287099188; Sat, 22 Aug 2015 16:44:59 -0700 (PDT) In-Reply-To: References: Date: Sun, 23 Aug 2015 09:44:59 +1000 Subject: Re: Sandboxing Python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440287102 news.xs4all.nl 23810 [2001:888:2000:d::a6]:35252 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95570 On Sun, Aug 23, 2015 at 9:25 AM, Mark Lawrence wrote: > I was always led to believe that the subject was a difficult thing to do, > but here > https://www.reddit.com/r/learnpython/comments/3huz4x/how_to_do_math_inside_raw_input/ > is a safe solution in only 23 characters, or are there any discernable flaws > in it? I'm sorry, I can't see which solution you're talking about there - maybe I just don't know how to read reddit properly. Can you paste the proposed code please? The best I can see there is "use eval but with no builtins". That's fundamentally flawed because you don't need builtins to break stuff. All you need is a literal, from which you can snag everything else via its attributes. However, for this situation, I would be recommending ast.literal_eval, which *is* safe. It's a lot more powerful than "split it into number, operator, number" as mentioned at the end, but still can't majorly break anything. ChrisA