热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Meltdown/Spectre在Web开发中的防范(中英)

原文链接(需越墙):https:developers.google.comwebupdates201802meltdown-spectre原文作者&#x
原文链接(需越墙):https://developers.google.com/web/updates/2018/02/meltdown-spectre

原文作者:Surma  最后更新时间: 2018-2-7

译者:西楼听雨

(转载请注明出处)


Overview 引言

On January 3rd Project Zero revealed vulnerabilities in modern CPUs that a process can use to read (at worst) arbitrary memory — including memory that doesn’t belong to that process. These vulnerabilities have been named Spectre and Meltdown. What is Chrome doing to help keep the web secure, and what should web developers do for their own sites?

1月3号,Project Zero 揭露了在现代 CPU 中存在的一些漏洞,他们可以允许进程读取任意内存(最糟糕情况)——包括那些本身不属于它的内存。 这些漏洞被命名为 Spectre 和 Meltdown。那么,Chrome 该做些什么来保障 Web 的安全呢?Web 开发者们又该为自己的网站做些什么呢?

TL; DR 结论("太长,不看了")

As a user browsing the web, you should make sure you keep your operating system and your browser updated. In addition, Chrome users can consider enabling Site Isolation.

作为一名浏览网页的用户,你应该确保你操作系统以及浏览器时刻保持最新版本。另外,Chrome 的用户可以考虑把“站点隔离”打开。

If you are a web developer, the Chrome team advises:

  • Where possible, prevent COOKIEs from entering the renderer process' memory by using the SameSite and HTTPOnly COOKIE attributes, and by avoiding reading from document.COOKIE.
  • Make sure your MIME types are correct and specify an X-Content-Type-Options: nosniff header for any URLs with user-specific or sensitive content, to get the most out of cross-site document blocking for users who have Site Isolation enabled.
  • Enable Site Isolation and let the Chrome team know if it causes problems for your site.

如果你是一名 Web 开发者,Chrome 团队建议:

  • 在任何可能的地方,通过设置 COOKIE 的 SameSite 和 HTTPOnly 属性,并避免读取 document.COOKIE,来防止 COOKIEs 进入渲染进程的内存。
  • 确保 MIME 类型正确,并对任何与特定用户相关或包含敏感内容的 URL 指定一个X-Content-Type-Options: nosniff 响应头,以此来为那些开启了站点隔离的用户提供最大的跨站点阻隔好处。
  • 启用站点隔离,并让 Chrome 团队知晓这样是否会给你的站点带来一些问题。

If you are wondering why  these steps help, read on!

如果你对上面这些为什们有用感兴趣,请继续往下读!

The risk 风险

There have been a wide variety of explanations of these vulnerabilities, so I am not going to add yet another one. If you are interested in how these vulnerabilities can be exploited, I recommend taking a look at the blog post by my colleagues from the Google Cloud team.

现在已经有很多对这些漏洞的各种解释了,所以,我就不再重复了。如果你对它们可以被如何拿来利用感兴趣,我推荐你看一下我的谷歌云团队的同事写的这篇博客文章。

Both Meltdown and Spectre potentially allow a process to read memory that it is not supposed to be able to. Sometimes, multiple documents from different sites can end up sharing a process in Chrome. This can happen when one has opened the other using window.open, or , or iframes. If a website contains user-specific data, there is a chance that another site could use these new vulnerabilities to read that user data.

Meltdown 和 Spectre 都潜在具备让一个进程读取本意不被允许读取的内存的可能。而在 Chrome 中,有时来自不同站点的多个文档是可能共享一个进程的。这种情况可能会发生在,一个站点使用window.open 或者 ,或者 iframes来打开另一个站点的时候。(这样的话,)如果某个网站含有特定于用户的数据,那么其他站点就有机会利用这些新漏洞来读取用户数据。

Mitigations 缓解措施

There are multiple efforts the Chrome and V8 engineering team is deploying to mitigate this threat.

Chrome 和 V8 工程的团队正在尽各种努力发布部署,来缓解这种威胁。

Site Isolation 站点隔离

The impact of successfully exploiting Spectre can be greatly reduced by preventing sensitive data from ever sharing a process with attacker-controlled code. The Chrome team has been working on a feature to achieve this called “Site Isolation”:

如果我们可以彻底防止敏感数据与攻击者控制的代码所在的进程进行共享,那么我们就可以极大的减轻 Spectre 被成功利用后的影响。Chrome 团队已经在为一项可以实现这种效果的新特性而努力:

“Websites typically cannot access each other's data inside the browser[...]. Occasionally, security bugs are found in this code and malicious websites may try to bypass these rules to attack other websites. [...] Site Isolation offers a second line of defense to make such attacks less likely to succeed. It ensures that pages from different websites are always put into different processes, each running in a sandbox that limits what the process is allowed to do.

Site Isolation has not been enabled by default yet as there are a couple of known issues and the Chrome team would like as much field testing as possible. If you are a web developer, you should enable Site Isolation and check whether your site remains functional. If you’d like to opt-in now, enable chrome://flags#enable-site-per-process. If you find a site that doesn’t work, please help us by filing a bug and mention that you have Site Isolation enabled.

"站点隔离"目前还没有在默认情况下开启,因为现在还有一些已知的问题,而且 Chrome 团队也希望对其进行尽可能多的测试。作为一名 Web 开发者,你应该把它开启并检查下站点是否仍然正常。假如你想现在就开启,请打开 chrome://flags#enable-site-per-process(这个 flag)。如果开启之后你发现某个站点不能正常工作,请填写一个 bug 并提及你已经打开了"站点隔离",以此给予我们帮助。

Cross-site document blocking 跨站文档阻隔

Even when all cross-site pages are put into separate processes, pages can still legitimately request some cross-site subresources, such as images and Javascript. To help prevent sensitive information from leaking this information, Site Isolation includes a “cross-site document blocking” feature that limits which network responses are delivered to the renderer process.

即便是把所有的跨站页面置入分离的进程中,页面仍然可以合法地请求一些跨站的资源,例如,图片和Javascript。为了防止敏感信息从此处暴露,“站点隔离”包含了一个叫做“跨站文档阻隔”的特性,它可以控制网络响应是否可以进入渲染进程。

A website can request two types of data from a server: “documents” and “resources”. Here, documents are HTML, XML, JSON and TXT files. A website is able to receive documents from its own domain or from other domains with permissive CORS headers. Resources include things like images, Javascript, CSS and fonts. Resources can be included from any site.

网站可以从服务器请求两种类型的数据:“文档”和“资源”。在这里所谓的“文档”指的是 HTML,XML,JSON 和 TXT 文件。一个网站可以接收来自同域下的文档,也可以接收来自跨域的 CORS 头部为允许的文档。而所谓的“资源”则包含有图片,Javascript,CSS,字体,他们可以被任何站点所引用。

The cross-site document blocking policy prevents a process from receiving “documents” from other origins if:

  1. They have an HTML, XML, JSON, or text/plain MIME type, and
  2. They have either a "X-Content-Type-Options: nosniff" HTTP response header, or a quick content analysis (“sniffing”) confirms that the type is correct
  3. CORS doesn’t explicitly allow access to the document

跨站文档阻隔政策会在以下情况下阻隔来自其他域下“文档”的接收:

  1. “文档”是 HTML,XML,JSON,或者 text/plain MIME 类型,且
  2.  要么“文档”的响应头部有一个 "X-Content-Type-Options: nosniff",要么在浏览器的快速内容分析中(“sniffing”)确认了类型的正确。
  3.  没有得到 CORS 显式地允许

Documents that are blocked by this policy are presented to the process as empty, although the request still happens in the background.

被这个政策阻隔的这些文档会以空白的形式进入进程,虽然请求实际还在后台进行。

For example: Imagine an attacker creating an tag that includes a JSON file with sensitive data, like . Without Site Isolation, the contents of the JSON file would make it to the renderer process’s memory, at which point the renderer notices that it is not a valid image format and doesn’t render an image. With Spectre, however, there is now a way to potentially read that chunk of memory. Cross-site document blocking would prevent the contents of this file from ever entering the memory of the process the renderer is running in because the MIME type is blocked by cross-site document blocking.

例如:想象一个攻击者,他创建了一个标签,而这个标签指向了一个包含敏感数据的JSON文件,如。如果没有站点隔离,那么这个JSON文件的内容就会进入渲染进程的内存,此时渲染进程会注意到它不是一个正确的图片格式,并放弃把它渲染为一张图片。然而,这对于 Spectre 来说,现在就有了一条可以读取这块内存块的潜在机会了。跨站文档阻隔政策就可以防止这个JSON文件进入渲染器进程的内存,因为仅通过它的 MIME 类型,跨站文档阻隔功能就会将其阻隔。

According to user metrics, there are a lot of Javascript and CSS files that are delivered with text/html or text/plainMIME types. To avoid blocking resources that are accidentally marked as documents, Chrome attempts to sniff the response to ensure the MIME type is correct. This sniffing is imperfect, so if you are sure that you are setting the correct Content-Type headers on your website, the Chrome team recommends adding the X-Content-Type-Options: nosniff header to all your responses.

按照用户数据矩阵的结果,有许多 Javascript 和 CSS 文件是以 text/html 或者 text/plain MIME 类型来传输的。为了防止哪些不经意被标志为了文档类型的资源被阻隔,Chrome 会尝试对响应进行嗅探,以此确保 MIME 类型是正确的。这种尝试存在缺点,所以,如果你肯定你所有的资源都设置了正确的 Content-Type 头的话,Chrome 团队建议再为所有响应添加一个 X-Content-Type-Options: nosniff头。

If you want to try cross-site document blocking, opt-in to Site Isolation as described above.

如果你也想尝试一下跨站文档阻隔,请看上面“站点隔离”一节来开启它。

SameSite COOKIEs 同站 COOKIE

Let’s go back to the example above: . This only works if yourbank.com has stored a COOKIE that automatically logs the user in. COOKIEs typically get sent for all requests to the website that sets the COOKIE — even if the request is made by a third party using an tag. SameSite COOKIEs are a new attribute that specify that a COOKIE should only be attached to a request that originates from the same site, hence the name. Sadly, at the time of writing, only Chrome and Firefox 58+ support this attribute.

回到上面的例子:。其实它只在 yourbank.com 保存了用户登陆后会自动保存的 COOKIE 时才起作用。通常 COOKIE 都会伴随着所有请求一起发送给设置它的网站——即便请求是由第三方发起的,例如上面的 。SameSite 是一个新的 COOKIE 属性,它可以指定一个 COOKIE 只在请求是由同一个站点的页面发起的时候才伴随发送,这也是它名字的由来。不过遗憾的时,在本文编写的时间点,还只有 Chrome 和 Firefox 58+ 支持这个属性。

HTTPOnly and document.COOKIE

If your site's COOKIEs are only used server-side, not by client Javascript, there are ways you can stop the COOKIE's data from entering the renderer process. You can set the HTTPOnly COOKIE attribute, which explicitly prevents the COOKIE from being accessed through client side script on supported browsers, such as Chrome. If setting HTTPOnly isn't possible, you can help limit the exposure of loading COOKIE data to the rendered process by not reading document.COOKIE unless absolutely necessary.

如果你网站的 COOKIE 只在服务端用到,客户端没有用到,那么这有多种方式可以防止 cooike 数据进入渲染进程。你可以给 COOKIE 设置 HTTPOnly 属性,它被所有浏览器所支持(如Chrome),这样可以显式地防止客户端脚本访问 COOKIE。 如果无法设置 HTTPOnly,你也只需要确保不读取 document.COOKIE,除非绝对有必要, 以此来限制对加载 COOKIE 数据的时的暴露。

Open External Links Using rel="noopener"  使用 rel="noopener" 来打开外部链接

When you link to another page using target="_blank", the opened page has access to your window object, can navigate your page to a different URL, and without Site Isolation will be in the same process as your page. To better protect your page, links to external pages that open in a new window should always specify rel="noopener".

如果你使用 target="_blank" 链接其他页面,那么打开后的目标页面是可以访问到你的 window 对象的,然后可以把你的页面导航到另外一个URL,并且如果没有站点隔离的话,这个页面将会和你的页面在同一个进程里面。所以,为了更好地保护你的页面,对于需要在一个新窗口打开的外部页面链接,你应该始终为其指定 rel="noopener"

High-resolution timers  高精度计时器

To exploit Meltdown or Spectre, an attacker needs to measure how long it takes to read a certain value from memory. For this, a reliable and accurate timer is needed.

想要利用 Meltdown 和 Spectre,攻击者必须测量出从内存读取某个值的耗时。而这种测量,必须借助一个高可靠、高精度的计时器。

One API the web platform offers is performance.now() which is accurate to 5 microseconds. As a mitigation, all major browsers have decreased the resolution of performance.now() to make it harder to mount the attacks.

Web 平台提供的其中一个 API 是 performance.now() ,它可以精确到5微妙。为了缓解攻击,所有的浏览器都降低了这个 API 的精度,以使得它很难成为攻击的入口。

Another way to get a high-resolution timer is to use a SharedArrayBuffer. The buffer is used by a dedicated worker to increment a counter. The main thread reads this counter and uses that as a timer. For the time being browsers have decided to disable SharedArrayBuffer until other mitigations are in place.

另外一种获取高精度计时器的方式是使用 SharedArrayBuffer。例如,用一个专门的 worker 来增加一个计数变量,然后主线程读取这个变量,(记录读取耗时),以此当作计时器。目前所有浏览器都已经决定准备禁用 SharedArrayBuffer,直到其他措施到位。

V8

To exploit Spectre, a specifically crafted sequence of CPU instructions is needed. The V8 team has implemented mitigations for known attack proofs of concept, and is working on changes in TurboFan, their optimizing compiler, that make its generated code safe even when these attacks are triggered. However, these code generation changes may come at a performance penalty.

要利用 Spectre,必须要有一个精心准备的 CPU 指令序列。V8 团队对一些已知的理论上可能的攻击采取了缓解措施,也在努力对 TurboFan 做出改变,优化他们的编译器,以此保证代码的生成安全,即便是发生在攻击的时候。不过,这些代码生成的改变会带来性能上的代价。






推荐阅读
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 20211101CleverTap参与度和分析工具功能平台学习/实践
    1.应用场景主要用于学习CleverTap的使用,该平台主要用于客户保留与参与平台.为客户提供价值.这里接触到的原因,是目前公司用到该平台的服务~2.学习操作 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • 本文介绍了响应式页面的概念和实现方式,包括针对不同终端制作特定页面和制作一个页面适应不同终端的显示。分析了两种实现方式的优缺点,提出了选择方案的建议。同时,对于响应式页面的需求和背景进行了讨论,解释了为什么需要响应式页面。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 怀疑是每次都在新建文件,具体代码如下 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 浏览器中的异常检测算法及其在深度学习中的应用
    本文介绍了在浏览器中进行异常检测的算法,包括统计学方法和机器学习方法,并探讨了异常检测在深度学习中的应用。异常检测在金融领域的信用卡欺诈、企业安全领域的非法入侵、IT运维中的设备维护时间点预测等方面具有广泛的应用。通过使用TensorFlow.js进行异常检测,可以实现对单变量和多变量异常的检测。统计学方法通过估计数据的分布概率来计算数据点的异常概率,而机器学习方法则通过训练数据来建立异常检测模型。 ... [详细]
  • 深入理解Kafka服务端请求队列中请求的处理
    本文深入分析了Kafka服务端请求队列中请求的处理过程,详细介绍了请求的封装和放入请求队列的过程,以及处理请求的线程池的创建和容量设置。通过场景分析、图示说明和源码分析,帮助读者更好地理解Kafka服务端的工作原理。 ... [详细]
author-avatar
手机用户2502897401
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有