https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security

【阅读理解式翻译,非严格遵循原始文档,以更生动表现出文章本义】

HTTP Strict Transport Security

HTTP Strict Transport Security (often abbreviated as HSTS) is a security feature that lets a web site tell browsers that it should only be communicated with using HTTPS, instead of using HTTP.

HSTS 是这样一种功能, 其让网站可以告知浏览器, 此网站的访问只能通过HTTPS, 以彻底替换HTTP协议。

理解: 因为HTTP是明文的协议,容易泄露内容,  在网络上容易被黑客截获报文, 或者访问被欺骗到钓鱼网站, 所以使用HTTPS访问目标网站可以解决上面两个风险。

HSTS能起到怎样的作用?

If a web site accepts a connection through HTTP and redirects to HTTPS, the user in this case may initially talk to the non-encrypted version of the site before being redirected, if, for example, the user types http://www.foo.com/ or even just foo.com.

This opens up the potential for a man-in-the-middle attack, where the redirect could be exploited to direct a user to a malicious site instead of the secure version of the original page.

The HTTP Strict Transport Security feature lets a web site inform the browser that it should never load the site using HTTP, and should automatically convert all attempts to access the site using HTTP to HTTPS requests instead.

众所周知, https功能可以认证目标网站的真实性, 并且可以保证传输数据的不被偷窥。

所以很多网站(包括现在的baidu.com)都是使用http跳转到https, 此不跳转使用 http协议的 302 等状态。

这种跳转方式, 开启了中间人攻击的可能(中间人攻击, 可以理解为 本次访问到目标网站上的链路上, 所有涉及到HTTP应用节点都可能作为中间人角色出现, 例如公司搭建的上网代理服务器, 请求访问经过的路由器网关)。

因为对于第一次使用 http 访问, 有可能被中间人利用跳转到 一个恶意的网站上, 而不是目标网站的https访问方式。

HSTS功能给了网站主动告知浏览器, 浏览器应该从不使用http方式访问我这个网站, 应该自动切换所有使用http访问本网站的请求, 为https方案。

一个实例场景

You log into a free WiFi access point at an airport and start surfing the web, visiting your online banking service to check your balance and pay a couple of bills. Unfortunately, the access point you're using is actually a hacker's laptop, and they're intercepting your original HTTP request and redirecting you to a clone of your bank's site instead of the real thing. Now your private data is exposed to the hacker.

Strict Transport Security resolves this problem; as long as you've accessed your bank's web site once using HTTPS, and the bank's web site uses Strict Transport Security, your browser will know to automatically use only HTTPS, which prevents hackers from performing this sort of man-in-the-middle attack.

你在机场使用无线上网, 接入了一个黑客设置的无线SSID, 你开始浏览web, 去访问在线银行服务, 检查余额并支付一些账单。

非常不幸,你正在使用的接入点, 实际上一个黑客的笔记本, 他们接活了你的原始 http请求, 并将此请求跳转到了 他们精心制作的 你的银行网站的 一个副本, 但这绝不是你的银行, 很危险吧 , 在副本网站上, 你提交的一切信息都将被暴漏给 黑客。

【 现在国内银行信用卡消费, 对于网站的消费支付, 都会要求要求手机即时验证码, 这样可以避免钓鱼网站盗取到你的信用卡密码后, 进行网络消费。 同时黑客也无法在实体店的POS机器上消费, 他没有卡,  如果他有你的卡的副本, 那就危险了。 】

HSTS解决了此问题, 一旦你使用曾经使用https访问过你的银行网站, 并且此银行网站启用了 Strict Transport Security(严格传输安全), 你的浏览器将自动只使用https协议访问网站, 这样阻止了黑客执行这种类型的中间人攻击。

ps: 浏览器启动此功能后,  无论用户输入http地址, 还是html和脚本使用使用的http地址, 浏览器都作为https地址访问。

这里说明, hsts有缺点, 必须让用户https访问过, 是否可以这个第一次也可以省去? 且看后来描述。

Enabling Strict Transport Security

Enabling this feature for your site is as simple as returning the Strict-Transport-Security HTTP header when your site is accessed over HTTPS:

Strict-Transport-Security: max-age=expireTime [; includeSubDomains] [; preload]
max-age
The time, in seconds, that the browser should remember that this site is only to be accessed using HTTPS.
includeSubDomains Optional
If this optional parameter is specified, this rule applies to all of the site's subdomains as well.
preload Optional
See Preloading Strict Transport Security for details. Not part of the specification.
Note: The Strict-Transport-Security header is ignored by the browser when your site is accessed using HTTP; this is because an attacker may intercept HTTP connections and inject the header or remove it.  When your site is accessed over HTTPS with no certificate errors, the browser knows your site is HTTPS capable and will honor the Strict-Transport-Security header.

启用网站的此功能是简单的, 仅仅在响应报文头中 添加  Strict-Transport-Security 头域, 当你的网站使用https协议访问的时候。

此头域值, 可以包括 超期时间, 是否作用于子域名, 是否支持 preload STS功能。

请注意, 为什么不在http请求的的响应报文中? 有两个原因:

1、添加此报文, 因为作为中间人攻击, 黑客可以获取此响应的全部内容, 将此头域删除, 所以没有根本没有作用。

2、 同时当网站被https访问, 并且没有证书错误, 浏览器知道你的网站是支持 https协议的, 将会遵守此头域, 实施hsts策略。

浏览器如何处理此头域?

The first time your site is accessed using HTTPS and it returns the Strict-Transport-Security header, the browser records this information, so that future attempts to load the site using HTTP will automatically use HTTPS instead.

When the expiration time specified by the Strict-Transport-Security header elapses, the next attempt to load the site via HTTP will proceed as normal instead of automatically using HTTPS.

Whenever the Strict-Transport-Security header is delivered to the browser, it will update the expiration time for that site, so sites can refresh this information and prevent the timeout from expiring. Should it be necessary to disable Strict Transport Security, setting the max-age to 0 (over a https connection) will immediately expire the Strict-Transport-Security header, allowing access via http.

正常流程: 浏览器第一次访问你的网站使用https协议, 返回了 此头域, 浏览器会记录此信息, 一遍将来的加载此网站的请求,都自动使用https替代。

关于超期: 如果此头域指定了超期时间, 并且此超期时间已经到期, 则下次的http访问将被允许, 而不是自动使用https替代。

超期延迟: 如果网站想延长浏览器的超期时限, 则网站在后续过访问中, 可以继续设置此头域, 并设置新的超期时间, 则浏览器使用此策略的超期时间, 从这次网站设置时刻起计算。  如果网站想关闭此策略, 设置 max-age为 0.

Preloading Strict Transport Security

Google maintains an HSTS preload service. By following the guidelines and successfully submitting your domain browsers will never connect to your domain using an insecure connection. While the service is hosted by Google, all browsers have stated to use (or start using) the submitted domains.

谷歌维护一个 hsts 预加载服务。 按照指南, 成功提交你的域名, 浏览器将从不连接你的  域名, 使用http连接。 尽管此服务是谷歌管理, 所有的浏览器都可以使用。

Specifications

Specification Status Comment
HTTP Strict Transport Security (HSTS) IETF RFC Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 4.0 (2.0) 11[1] 12 7

[1] Added with KB 3058515 in June 2015

See also

进阶:

https://www.eff.org/deeplinks/2014/02/websites-hsts

https://blog.mozilla.org/security/2012/11/01/preloading-hsts/

https://www.owasp.org/index.php/HTTP_Strict_Transport_Security

HTTPS强制安全策略-HSTS协议阅读理解的更多相关文章

  1. 从 HTTP 到 HTTPS 再到 HSTS

    近些年,随着域名劫持.信息泄漏等网络安全事件的频繁发生,网站安全也变得越来越重要,也促成了网络传输协议从 HTTP 到 HTTPS 再到 HSTS 的转变. HTTP HTTP(超文本传输协议) 是一 ...

  2. 用Keras搞一个阅读理解机器人

    catalogue . 训练集 . 数据预处理 . 神经网络模型设计(对话集 <-> 问题集) . 神经网络模型设计(问题集 <-> 回答集) . RNN神经网络 . 训练 . ...

  3. Tensorflow做阅读理解与完形填空

    catalogue . 前言 . 使用的数据集 . 数据预处理 . 训练 . 测试模型运行结果: 进行实际完形填空 0. 前言 开始写这篇文章的时候是晚上12点,突然想到几点新的理解,赶紧记下来.我们 ...

  4. 阅读关于DuReader:百度大规模的中文机器阅读理解数据集

    很久之前就得到了百度机器阅读理解关于数据集的这篇文章,今天才进行总结!.... 论文地址:https://arxiv.org/abs/1711.05073 自然语言处理是人工智能皇冠上的明珠,而机器阅 ...

  5. 机器阅读理解(看各类QA模型与花式Attention)

    目录 简介 经典模型概述 Model 1: Attentive Reader and Impatient Reader Model 2: Attentive Sum Reader Model 3: S ...

  6. 机器阅读理解综述Neural Machine Reading Comprehension Methods and Trends(略读笔记)

    标题:Neural Machine Reading Comprehension: Methods and Trends 作者:Shanshan Liu, Xin Zhang, Sheng Zhang, ...

  7. UINavigationController+FDFullscreenPopGesture全屏回滑手势阅读理解

    滑动返回纯oc.纯swifthttps://github.com/Bonway/BBGestureBack UINavigationController+FDFullscreenPopGesture全 ...

  8. 机器阅读理解(看各类QA模型与花式Attention)(转载)

    目录 简介 经典模型概述 Model 1: Attentive Reader and Impatient Reader Attentive Reader Impatient Reader Model ...

  9. Codeforces#543 div2 A. Technogoblet of Fire(阅读理解)

    题目链接:http://codeforces.com/problemset/problem/1121/A 真·阅读理解 题意就是 有n个人 pi表示他们的强度 si表示他们来自哪个学校 现在Arkad ...

随机推荐

  1. ACM Yougth的最大化

    Yougth的最大化 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价 ...

  2. 集成IOS 环信SDK

    集成IOS SDK 在您阅读此文档时,我们假定您已经具备了基础的 iOS 应用开发经验,并能够理解相关基础概念. 下载SDK 通过Cocoapods下载地址 不包含实时语音版本SDK(EaseMobC ...

  3. 隐藏Jquery dialog 按钮

    $(".ui-dialog-buttonpane button").hide(); //隐藏dialog中所有button $(".ui-dialog-buttonpan ...

  4. C#常用方法集合

    public class Utility:Page { #region 数据转换 /// <summary> /// 返回对象obj的String值,obj为null时返回空值. /// ...

  5. pr高的2级域名站点如何做优化?

    优化方法: 二级域名的内容建设也需要细致化 很多人认为,优化二级域名没有优化顶级域名那么多工作,只需要发发外链就可以了,这可以说是一个误区.我们的目的是要优化二级域名到首页,让用户能够看到,如果我们的 ...

  6. html2canvas根据DOM元素样式实现网页截图

    html2canvas是一个相当不错的JavaScript类库,它使用了html5和css3的一些新功能特性,实现了在客户端对网页进行截图的功 能.html2canvas通过获取页面的DOM和元素的样 ...

  7. java解析xml文档(dom)

    DOM解析XML文档 读取本地的xml文件,通过DOM进行解析,DOM解析的特点就是把整个xml文件装载入内存中,形成一颗DOM树形结构,树结构是方便遍历和和操纵. DOM解析的特性就是读取xml文件 ...

  8. [CareerCup] 18.13 Largest Rectangle of Letters

    18.13 Given a list of millions of words, design an algorithm to create the largest possible rectangl ...

  9. 【转】Selenium WebDriver + Python 环境

    转自:http://www.myext.cn/webkf/a_11878.html 1. 下载必要工具及安装包 1.1 [Python开发环境] 下载并安装Python 2.7.x版本 下载地址:ht ...

  10. (转)实例分析:MySQL优化经验

    [IT专家网独家]同时在线访问量继续增大,对于1G内存的服务器明显感觉到吃力,严重时甚至每天都会死机,或者时不时的服务器卡一下,这个问题曾经困扰了我半个多月.MySQL使用是很具伸缩性的算法,因此你通 ...