我正在编写一个Web应用程序,将用户输入存储在一个对象中,该对象将被pickle。
如果用户能够构造恶意输入,那么在对象被解pickle时可能会执行一些非常严重的操作吗?
这里有一个非常基本的代码示例,它忽略了封装等优秀原则,但是代表了我的研究重点:
import pickle
class X(object):
some_attribute = None
x = X()
x.some_attribute = 'insert some user input that could possibly be bad'
p = pickle.dumps(x)
# Can bad things happen here if the object, before being picked, contained
# potentially bad data in some_attribute?
x = pickle.loads(p)
pickle.loads()
以表现出邪恶的eval()
并执行任意代码或造成其他不良影响。 - Matty