mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
updated link
This commit is contained in:
@@ -528,7 +528,7 @@ for guess in itertools.permutations(digits, len(characters)):
|
||||
|
||||
<p class=xxxl>eval() is EVIL
|
||||
|
||||
<p>Well, the evil part is evaluating arbitrary expressions from untrusted sources. You should only use <code>eval()</code> on trusted input. Of course, the trick is figuring out what’s “trusted.” But here’s something I know for certain: you should <b>NOT</b> take this alphametics solver and put it on the internet as a fun little web service. Don’t make the mistake of thinking, “Gosh, the function does a lot of string manipulation before getting a string to evaluate; <em>I can’t imagine</em> how someone could exploit that.” Someone <b>WILL</b> figure out how to sneak nasty executable code past all that string manipulation (<a href=http://www.matasano.com/log/1032/this-new-vulnerability-dowds-inhuman-flash-exploit/>stranger things have happened</a>), and then you can kiss your server goodbye.
|
||||
<p>Well, the evil part is evaluating arbitrary expressions from untrusted sources. You should only use <code>eval()</code> on trusted input. Of course, the trick is figuring out what’s “trusted.” But here’s something I know for certain: you should <b>NOT</b> take this alphametics solver and put it on the internet as a fun little web service. Don’t make the mistake of thinking, “Gosh, the function does a lot of string manipulation before getting a string to evaluate; <em>I can’t imagine</em> how someone could exploit that.” Someone <b>WILL</b> figure out how to sneak nasty executable code past all that string manipulation (<a href=http://www.securityfocus.com/blogs/746>stranger things have happened</a>), and then you can kiss your server goodbye.
|
||||
|
||||
<p>But surely there’s <em>some</em> way to evaluate expressions safely? To put <code>eval()</code> in a sandbox where it can’t access or harm the outside world? Well, yes and no.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user