[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Python bots in Galcon (or your game!) safe_eval
- To: pygame <pygame-users@xxxxxxxx>
- Subject: [pygame] Python bots in Galcon (or your game!) safe_eval
- From: Phil Hassey <philhassey@xxxxxxxxx>
- Date: Wed, 7 Mar 2007 20:46:13 -0800 (PST)
- Delivered-to: firstname.lastname@example.org
- Delivered-to: email@example.com
- Delivered-to: firstname.lastname@example.org
- Delivery-date: Wed, 07 Mar 2007 23:46:23 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=0eo1nuwdGXSvB8tCZFG3jmy3yU9IICbhQimIx/xxhYUaNyT4rAQz5K/GJ1TFbMmGK1qDQwrjQWrAbf988ODUhcWpzbvuGD+3XOmEm0ZyiCbXAZMbUUkzw3fiWigCWjcc6DWU825SrMQpxtdYcI6MgyzEMniSnxsHkaVKkb70cSA=;
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I spent some time today working on building a safe_eval function that would make it "safe" to run user submitted bots in games (Galcon, being that game ;)
The file includes links to a number of references on the topic, and why likely this won't work. Anyway - I know a lot of you wanted to make bots for Galcon, so that's why I'm trying to put this together. So if anyone can find security holes in my implementation, it would be a huge help - the more I find and get patched the more likely I am to actually release Galcon with ability for bot-plugins.
The known limitations at the top are things that I don't really want to fix - they are just limitations. :) I'm mainly interested in limiting what a bot can access (say other parts of the game code) and keeping them from using builtins like files, etc.
The two things I do in this script are:
- Step through the AST tree
and reject scripts that use any non-whitelisted node types. A lot of python features are dropped, but enough are kept for building decent bots (the main bot from Galcon is "ok" as far as safe.py is concerned.) I pretty much reject anything that falls into the magic category - generators, imports, execs, exceptions, etc...
- Replace non-whitelisted builtins with a function that raises an exception "you used a bad builtin!", runs "exec code in context" and then restores all the builtins.
Anyway, feel free to poke around the code. I think a working safe_eval would be a huge asset for games developed in python that want to have user submitted mods / bots.
It's here! Your new message!
new email alerts with the free Yahoo! Toolbar.