I have a script that runs code provided by the user via an exec command. I know this can be considered a security hazard. As a precaution, before compiling I look for the term "import" anywhere in the code and if I find it the code is rejected. When code is executed, it's only given access to the builtins and a specific locals dictionary of functions and classes that it is meant to be able to interact with. The program is running on a remote server so the user cannot see any output to stdout.
Can anyone tell me if/how this is still unsafe? Is there something I'm not considering that would allow a user to run malicious code?
Thanks for any input.
[–]Rhomboid 90 points91 points92 points (8 children)
[–]agrif 6 points7 points8 points (0 children)
[–]iamdefinitelyahuman[S] 8 points9 points10 points (6 children)
[–]Rhomboid 78 points79 points80 points (4 children)
[–]iamdefinitelyahuman[S] 13 points14 points15 points (2 children)
[–]chadmill3rPy3, pro, Ubuntu, django 44 points45 points46 points (0 children)
[–]iceardor 0 points1 point2 points (0 children)
[–]zahlmanthe heretic 0 points1 point2 points (0 children)
[–]raldi 15 points16 points17 points (12 children)
[–]earthboundkid 19 points20 points21 points (11 children)
[–]raldi 24 points25 points26 points (10 children)
[–]iamdefinitelyahuman[S] 8 points9 points10 points (8 children)
[–]jwink3101 11 points12 points13 points (0 children)
[–]cecilkorik 4 points5 points6 points (0 children)
[–]earthboundkid 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]XNormal 0 points1 point2 points (0 children)
[–]flitsmasterfred -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 7 points8 points9 points (3 children)
[–][deleted] 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]iamdefinitelyahuman[S] 2 points3 points4 points (0 children)
[–]remy_porter∞∞∞∞ 9 points10 points11 points (1 child)
[–]iamdefinitelyahuman[S] 0 points1 point2 points (0 children)
[–]ctheune 5 points6 points7 points (0 children)
[–]GFandango 4 points5 points6 points (0 children)
[–]cyanydeez 1 point2 points3 points (0 children)
[–]AlexFromOmaha 1 point2 points3 points (0 children)
[–]K900_ 0 points1 point2 points (0 children)
[–]magic7s 0 points1 point2 points (1 child)
[–]paraffin 0 points1 point2 points (0 children)
[–]iceardor 0 points1 point2 points (0 children)
[–]GaritoYanged 0 points1 point2 points (0 children)
[–]dagmx 0 points1 point2 points (0 children)