在 app.yaml 中添加 HSTS 标头(Google App Engine)

hjp*_*r92 6 https google-app-engine http-headers app.yaml hsts

我的 中有以下处理程序部分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'
Run Code Online (Sandbox Code Playgroud)

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

handlers:
  - url: /
    static_dir: files
    secure: always
    http_headers:
      Access-Control-Allow-Origin: '*'
      Strict-Transport-Security: 'max-age=63072000; preload'
Run Code Online (Sandbox Code Playgroud)

我能够static.yaml在没有任何问题的情况下部署应用程序引擎:

$ 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
Run Code Online (Sandbox Code Playgroud)

然而,当我尝试更新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.
Run Code Online (Sandbox Code Playgroud)

我知道这意味着我必须在 python 脚本本身中处理 HSTS 配置。但是,我的界面中有大约 10 个处理程序main.appapp.yaml是否有其他方法可以在级别本身上执行此操作,而不是更新每个文件以添加 STS 标头?

检查app.yamlGAE 上的参考资料,没有提到类型映射http_header中指令的限制script

小智 5

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


Yao*_* Li 3

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

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

更新

截至 2018 年,自定义域不需要列入白名单。换句话说,HSTS 标头不再被删除。