跳到主要内容

6. Syntax (语法)

HSTS 使用 HTTP response header field Strict-Transport-Security 表达 policy. 该 header 只在通过 secure transport 接收时才对 UA 有效.

基本形式如下:

Strict-Transport-Security: max-age=31536000
Strict-Transport-Security: max-age=31536000; includeSubDomains

max-age directive 是 REQUIRED, 值为 non-negative decimal integer, 表示 policy 从 UA 接收 header 时起的有效秒数. includeSubDomains directive 是 OPTIONAL, 表示 policy 还应用到该 host 的所有子域.

UA 解析 directive name 时使用 ASCII case-insensitive comparison. 未识别的 directive 可以忽略, 但不能影响已识别 directive 的处理. 如果同一 response 中出现多个 HSTS header 或重复 directive, UA 应按规范定义的解析规则处理, 避免因为歧义放宽安全策略.