HTTP 严格传输安全 (HTTP Strict Transport Security, HSTS) 在指定时间段内仅允许安全的 HTTPS 连接,不允许 HTTP 连接。使用 HSTS 之前,先熟悉 HSTS 先决条件,了解启用了 HSTS 的浏览器行为,然后安装由证书颁发机构签名的证书。
如以下示例中所示,HSTS 将保持启用的默认最大时间长度为 63072000 秒,即 2 年。
请求示例:
GET /api/setting/v2/security HTTP/1.1 Host: alice.example.com:215 Authorization: Basic Tm8gcGVla2luZyE= Accept: application/json
结果示例:
HTTP/1.1 200 OK Date: Fri, 14 May 2021 19:22:27 GMT Content-Type: application/json; charset=utf-8 X-Zfssa-Api-Version: 2.0 X-Zfssa-Setting-Api: 2.0 Content-Length: 109 { "Security settings": { "href": "/api/setting/v2/security", "hsts_enable": false, "hsts_max_age": 63072000 } }
要为此设备启用 HSTS,请将 hsts_enable 属性设置为 true。
PUT /api/setting/v2/security HTTP/1.1 Host: alice.example.com:215 Content-Type: application/json {"hsts_enable": true}