I’m looking at several cases where it would be far, far, far easier to accept nearly-raw code. So,
- What’s the worst you can do with an expression if you can’t lambda, and how?
- What’s the worst you can do with executed code if you can’t use import and how?
(can’t use X == string is scanned for X)
Also, B is unecessary if someone can think of such an expr that given d = {key:value,…}:
expr.format(key) == d[key]
Without changing the way the format looks.
The worst you can do with an expression is on the order of
if the server process is running as
root. Otherwise, you can fill up memory and crash the process withor bring the server to a grinding halt by executing a shell fork bomb:
or execute a temporary (but destructive enough) fork bomb in Python itself:
Scanning for
__import__won’t help, since there’s an infinite number of ways to get to it, includingNote that the
evalandexecfunctions can also be used to create any of the above in an indirect way. If you want safe expression evaluation on a server, useast.literal_eval.