[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] pygame web plugin
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] pygame web plugin
- From: "Campbell Barton" <ideasman42@xxxxxxxxx>
- Date: Sat, 6 Sep 2008 14:26:48 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sat, 06 Sep 2008 00:27:23 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=BvNzWcVTNh2NHX5tITQ6Lbr7YiGbGwfJCdBDhs9ytQc=; b=lFICnFXKCNfRXPBYT8UK3ZnQYYp+KqI8oxR2JSyBB3doj2X4DGkQB9aipvM8WmgosZ SKfI4BzxdIhj5dbUf1StFpmZ1PEfOGZKZOX/Ddpy2SZpZ5A+5+HSsN+0zXPZC466glct 896dU3c9HYu8h4A/WwHpVhWJ/lA8qpN3myfn0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=l10RGKKUQfjxxOVrVmELTnvgyRfIVbNDAZTPT+zBdBN9NaUAC3hO46fMUMj/OR2OZA gS2P27gvc5pbUUwsp84N8GzewYzumaHBKy50L6R4s471YzTZCJCuHblF+UXdpfB6LFPe LouOmShC6gI1qIAUgx+vCmslPcFGPzmZXEEAM=
- In-reply-to: <7c3dfb90809051707yf077b20u188ba5d1f81bfcbe@xxxxxxxxxxxxxx>
- References: <7c3dfb90809051707yf077b20u188ba5d1f81bfcbe@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
from talking to the python guys sandboxing python is easy if you use
the C api to overwrite builtins.
(sandboxing issues arise from trying to sandbox python from within python)
You'd need to replace pythons import function with one that checks
only for files in a zip for instance.
Or for starters you could disable import alltogether and only allow C
modules and standalone scripts.
------------------ blenders sandbox code
// Python Sandbox code
// override builtin functions import() and open()
PyObject *KXpy_open(PyObject *self, PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "Sandbox: open() function
disabled!\nGame Scripts should not use this function.");
return NULL;
}
PyObject *KXpy_reload(PyObject *self, PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "Sandbox: reload() function
disabled!\nGame Scripts should not use this function.");
return NULL;
}
PyObject *KXpy_file(PyObject *self, PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "Sandbox: file() function
disabled!\nGame Scripts should not use this function.");
return NULL;
}
PyObject *KXpy_execfile(PyObject *self, PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "Sandbox: execfile() function
disabled!\nGame Scripts should not use this function.");
return NULL;
}
PyObject *KXpy_compile(PyObject *self, PyObject *args) {
PyErr_SetString(PyExc_RuntimeError, "Sandbox: compile() function
disabled!\nGame Scripts should not use this function.");
return NULL;
}
PyObject *KXpy_import(PyObject *self, PyObject *args)
{
char *name;
PyObject *globals = NULL;
PyObject *locals = NULL;
PyObject *fromlist = NULL;
PyObject *l, *m, *n;
if (!PyArg_ParseTuple(args, "s|OOO:m_import",
&name, &globals, &locals, &fromlist))
return NULL;
/* check for builtin modules */
m = PyImport_AddModule("sys");
l = PyObject_GetAttrString(m, "builtin_module_names");
n = PyString_FromString(name);
if (PySequence_Contains(l, n)) {
return PyImport_ImportModuleEx(name, globals, locals, fromlist);
}
/* quick hack for GamePython modules
TODO: register builtin modules properly by ExtendInittab */
if (!strcmp(name, "GameLogic") || !strcmp(name, "GameKeys") ||
!strcmp(name, "PhysicsConstraints") ||
!strcmp(name, "Rasterizer") || !strcmp(name, "Mathutils")) {
return PyImport_ImportModuleEx(name, globals, locals, fromlist);
}
PyErr_Format(PyExc_ImportError,
"Import of external Module %.20s not allowed.", name);
return NULL;
}
static PyMethodDef meth_open[] = {{ "open", KXpy_open, METH_VARARGS,
"(disabled)"}};
static PyMethodDef meth_reload[] = {{ "reload", KXpy_reload,
METH_VARARGS, "(disabled)"}};
static PyMethodDef meth_file[] = {{ "file", KXpy_file, METH_VARARGS,
"(disabled)"}};
static PyMethodDef meth_execfile[] = {{ "execfile", KXpy_execfile,
METH_VARARGS, "(disabled)"}};
static PyMethodDef meth_compile[] = {{ "compile", KXpy_compile,
METH_VARARGS, "(disabled)"}};
static PyMethodDef meth_import[] = {{ "import", KXpy_import,
METH_VARARGS, "our own import"}};
void setSandbox(TPythonSecurityLevel level)
{
PyObject *m = PyImport_AddModule("__builtin__");
PyObject *d = PyModule_GetDict(m);
// functions we cant trust
PyDict_SetItemString(d, "open", PyCFunction_New(meth_open, NULL));
PyDict_SetItemString(d, "reload", PyCFunction_New(meth_reload, NULL));
PyDict_SetItemString(d, "file", PyCFunction_New(meth_file, NULL));
PyDict_SetItemString(d, "execfile", PyCFunction_New(meth_execfile, NULL));
PyDict_SetItemString(d, "compile", PyCFunction_New(meth_compile, NULL));
// our own import
PyDict_SetItemString(d, "__import__", PyCFunction_New(meth_import, NULL));
}
On Sat, Sep 6, 2008 at 10:07 AM, machinimist@xxxxxxxxx
<machinimist@xxxxxxxxx> wrote:
> hi,
>
> i would like to bring up this topic again since a python based open source
> alternative to flash which could be used to create browser games would
> be super awesome. :)
>
> if i understand this correctly then the main problem of something like that
> is security.
>
> i noticed on the blender mailing list that someone started to revive the
> blender game engine web plugin. they use python too and apparently they have
> found a way to sandbox python.
>
> http://lists.blender.org/pipermail/bf-committers/2008-August/021660.html
>
> what do you think about this?
> wouldn't a web plugin be a big opportunity for pygame?
> i am no expert on all of this though... maybe making a web version of
> pygame is totally unfeasible?