【问题标题】:Adding HSTS headers in app.yaml (Google App Engine)在 app.yaml (Google App Engine) 中添加 HSTS 标头
【发布时间】:2016-09-17 07:36:45
【问题描述】:

我的app.yaml 中有以下处理程序部分:

handlers:
  - url: /(robots\.txt|sitemap\.xml)
    static_files: \1
    upload: (robots\.txt|sitemap\.xml)
    secure: always
    http_headers:
      Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'
  - url: /.*
    script: main.app
    secure: always
    http_headers:
      Strict-Transport-Security: 'max-age=63072000; includeSubDomains; preload'

由另一个子模块 (static.yaml) 提供服务的另一个子域具有以下内容:

handlers:
  - url: /
    static_dir: files
    secure: always
    http_headers:
      Access-Control-Allow-Origin: '*'
      Strict-Transport-Security: 'max-age=63072000; preload'

我能够部署 static.yaml,而对 appengine 没有任何问题:

$ appcfg.py update static.yaml
12:48 PM Host: appengine.google.com
12:48 PM Application: XXXXXX; module: static; version: 1
12:48 PM
Starting update of app: XXXXXXXX, module: static, version: 1
12:48 PM Getting current resource limits.
12:48 PM Scanning files on local disk.
[...]
[...]
12:49 PM Checking if updated app version is serving.
12:49 PM Completed update of app: XXXXXX, module: static, version: 1

然而,当我尝试更新 app.yaml 配置时,我得到:

$ appcfg.py update app.yaml
12:48 PM Host: appengine.google.com
Usage: appcfg.py [options] update <directory> | [file, ...]

appcfg.py: error: Error parsing .\app.yaml: Unexpected attribute "http_headers" for mapping type script.
  in ".\app.yaml", line 31, column 1.

我知道这意味着我必须在我的 python 脚本本身中处理 HSTS 配置。但是,我在 main.app 接口中有大约 10 个处理程序。除了更新其中的每一个来添加 STS 标头之外,还有其他方法可以在 app.yaml 级别本身这样做吗?

查看app.yaml reference on GAE,在script类型映射中没有提到http_header指令的限制。

【问题讨论】:

    标签: google-app-engine https http-headers app.yaml hsts


    【解决方案1】:

    您可以使用 app.yaml 来控制 HTTP headers 用于静态文件处理程序而不是动态处理程序。您需要在应用代码中设置标题。

    【讨论】:

    • 这由 KB 支持:“为了将 HTTP Strict-Transport-Security 标头 (HSTS) 添加到您的应用程序,您必须在您的应用程序代码中实现这些标头,而不是在您的应用程序的配置中文件” - cloud.google.com/appengine/kb
    【解决方案2】:

    作为文档: https://cloud.google.com/appengine/docs/flexible/nodejs/using-custom-domains-and-ssl

    除非您的域被列入白名单,否则您不能使用 Strict-Transport-Security 标头。要将您的域加入白名单,请联系 ...

    更新

    自 2018 年起,自定义域无需列入白名单。换句话说,HSTS 标头不再被剥离。

    【讨论】:

    【解决方案3】:

    我今天在 app.yaml 中查看 http 标头并看到了这个。它似乎与您的问题有关。

    此外,标头 Strict-Transport-Security 已从 来自 *.appspot.com 以外的任何域的响应。

    https://cloud.google.com/appengine/docs/python/how-requests-are-handled#Python_Responses

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 2014-02-13
      • 2015-05-15
      • 2015-01-28
      • 2019-06-13
      • 2017-02-02
      • 1970-01-01
      相关资源
      最近更新 更多