Strict-Transport-Security (HSTS)

回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

Strict-Transport-Security (HSTS)

文章 yehlu »

https://www.peterdavehello.org/2015/10/ ... e-version/

我們應該要在 Response Header 裡面設定一個叫做 Strict-Transport-Security (HSTS) 的玩意兒,來告訴 client 說我們接下來的溝通都使用 https 吧,透過 HSTS header,接下來的特定時間長度內(max-age)的連線將會自動採用 https,如以一來可以:

避免中間人攻擊
使用者通常不會自行指定使用 https,而是透過 http 再 redirect,此階段是不安全的
中間人攻擊雖然很有可能造成憑證無效,但通常使用者會自行忽略警告 … 透過 HSTS 設定,使用者將不再被允許忽略警告
省去 redirect 成本
在 nginx 裡面的設定方法為在設定檔的 server 區段插入下列設定(max-age為設定有效的秒數,建議至少半年以上):

代碼: 選擇全部

add_header Strict-Transport-Security "max-age=63072000;";
如果確認所有子網域也已經啟用 https,可以改使用:

add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
回覆文章

回到「nginx」