security - 谷歌应用引擎 : secure inter-app communication

标签 security google-app-engine http

我在 Google App Engine 上有两个应用,都在同一个帐户下运行,一个通过 HTTPS 调用另一个提供的服务。确保只有第一个应用程序被允许调用第二个应用程序的推荐方法是什么?

或者,有没有办法指定给定的端点只能由在同一 GAE 帐户下运行的应用程序调用?

最佳答案

让您的应用检查“X-Appengine-Inbound-Appid” header 并确保应用 ID 正确。此 header 仅在请求由另一个 Google App Engine 应用程序发出且用户无法修改时才存在。

如果您使用的是 Python,您可以执行以下操作:

import webapp2

AUTHORIZED_APPS = ('my-first-app', 'my-other-app')

class MyHandler(webapp2.RequestHandler):
    def dispatch(self):
        app_id = self.request.headers.get('X-Appengine-Inbound-Appid', None)

        if app_id in AUTHORIZED_APPS:   
            super(MyHandler, self).dispatch()
        else:
            self.abort(403)

对于 header 中没有 X-Appengine-Inbound-Appid 的任何请求,这将引发 403。

此外,当使用 urlfetch 从一个应用程序向另一个应用程序发出请求时,请确保您设置了 follow_redirects=False,否则不会添加 header 。

关于security - 谷歌应用引擎 : secure inter-app communication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13245540/

相关文章:

c# - 带盐的 MD5 散列用于在 C# 中将密码保存在数据库中

ruby-on-rails - Rails 的protect_from_forgery 真的有用吗?

python - 谷歌云应用引擎 : 502 Bad Gateway (nginx) error with Flask App

java - 将图像保存到 Google App Engine/Java 时出错

python - 使用 Python 的 BaseHTTPServer 从 POST 请求中获取文件

javascript - 提供 JavaScript 文件时,使用 application/javascript 还是 application/x-javascript 更好

php - mysqli_real_escape_string 存在漏洞

javascript - 为什么浏览器允许onmousedown JS改变href?

http - 如何在 Go 中验证签名证书时间戳 (SCT)

python - 是否可以使用远程数据存储运行 dev_appserver.py?