您如何进一步锁定执行不受信任代码的Google App Engine应用程序?

时间:2010-01-30 02:53:32

标签: python google-app-engine

我们目前正在使用Google App Engine来评估学生提交的Python问题的解决方案。我们已将所有不受信任的代码执行移至不使用数据存储区的单独GAE应用程序。对于我们上传的50多个问题,一切似乎都运行正常,但我很好奇那些勤劳的学生会发现什么样的安全漏洞。我们应该如何进一步保护此代码免受其在GAE中执行的不受信任的代码的影响?

#The solution and doctest are untrusted code passed in to the GAE app. 
solution = 'b=5'
doctest = '>>> b \n 5'

#Compile and exec the untrusted solution provided by the user. 
compiled = compile(solution, 'submitted code', 'exec')
sandbox = {}
exec compiled in sandbox

#Compile and exec each of the doctests
test_cases = doctest.DocTestParser().get_examples(doctest)
for test in test_cases:
  if not test.want:
    exec test.source in sandbox

1 个答案:

答案 0 :(得分:3)

查看shell.appspot.com's source - 它实际上甚至使用数据存储区(用于会话持久性)。核心基本上就是像你一样做一个简单的exec - 还有其他的改进,但与不受信任的代码的“锁定”没什么特别之处。据推测,发布此示例代码的Google工程师(在App Engine团队中)对于不受信任的代码的安全性感觉相当不错。

我能想到的一个可行的“攻击”是“拒绝服务”攻击,它会反复淹没资源并导致您的帐户被收费(如果启用了超出免费配额使用费用) - - 只要你在某个安全的地方(在另一个应用程序中)存储了上传某段代码的人的身份,我就不明白为什么学生应该尝试这样的恶作剧并冒着冒险或其他事情。