security - 谷歌应用引擎 : security of cron jobs

标签 security google-app-engine cron

GAE 为预定作业提供 cron 作业。如何设置一些安全措施以防止有人直接执行 http GET?在下面的示例中,我可以随时在浏览器的 url 字段中键入/updateData 以按照以下设置执行作业:

cron:
- description: daily update of the data in the datastore
  url: /updateData
  schedule: every day 00:00
  timezone: ...

最佳答案

除了 Paul C 所说的之外,您还可以创建一个装饰器来检查 X-Appengine-Cron header ,如下所示。顺便说一句, header 不能被欺骗,这意味着如果不是来自 cron 作业的请求具有此 header ,App Engine 将更改 header 的名称。您还可以为任务编写类似的方法,在本例中检查 X-AppEngine-TaskName

"""
Decorator to indicate that this is a cron method and applies request.headers check
"""
def cron_method(handler):
    def check_if_cron(self, *args, **kwargs):
        if self.request.headers.get('X-AppEngine-Cron') is None:
            self.error(403)
        else:
            return handler(self, *args, **kwargs)
    return check_if_cron

并将其用作:

class ClassName(webapp2.RequestHandler):
    @cron_method
    def get(self):
        ....

关于security - 谷歌应用引擎 : security of cron jobs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14193816/

相关文章:

security - 是否可以在 Azure 搜索上实现基于用户的安全性?

java - 使用 java api 和 epass2003 token 的 pdf 数字签名

mysql - 如何增加 App Engine 请求处理程序的时间,因为它会在 60 秒内中止每个请求?

linux - 具有文件过滤功能的 Cron tar

javascript - Ajax 安全

security - 在 firebase 中,我应该编写哪些安全规则来只允许推送到对象

google-app-engine - 延迟的 API 调用似乎无法在正常的前端实例上运行

python - 使用动态属性名称调用 GAE NDB 查询

java - 如何制作一个特殊的 cron 作业?

linux - 每 x 天与每月第 n 天