I'm trying to find a way to allow my users to request arbitrary portions of a Python object, and have the server return that data without accidentally allowing them to request stuff they're not allowed to have or do things they're not allowed to do.
For example, say the server has this data:
my_stuff = {"alpha": ["bravo", "charlie", {"delta": "echo"}], "foxtrot": "golf"}
I want to allow the user to send an HTTP request like:
/path/to/my/script/?gimme=my_stuff[alpha][2][delta]
and have the request return echo
. Similarly, if gimme=foxtrot
, I want to return golf
.
I can't just pass this off to eval() right? The security implications alone would be Very Bad, but I can't imagine the performance being very good either.
The syntax of the request can change entirely, the requirement is that I allow users to request arbitrary portions of a server-side object.... but just that object, read-only.
Is there a safe/smart way to do this, or am I crazy?