Security/Safe Browsing: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(→‎QA: link to meta bug)
(→‎Links: Add another form that's working according to Google engineers.)
 
(71 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Note: The Safe Browsing feature in Firefox has been renamed to Phishing Protection, but it's still known as Safe Browsing internally.
Note: The Safe Browsing feature in Firefox has been renamed to Phishing Protection, but it's still known as Safe Browsing internally.


Download protection has its [[Security/Application Reputation|own separate page]].
[[Security/Application Reputation|Download Protection]] and [[Security/Tracking protection|Tracking protection]] have their own separate pages.


= History =
= History =


[http://www.google.com/tools/firefox/safebrowsing/ Google Safe Browsing] was an anti-phishing extension released by Google on [http://labs.google.com/ labs.google.com] in December 2005. Google has released this extension to the Mozilla Foundation under MPL 1.1/GPL 2.0/LGPL 2.1 in order that it might be used as part of Firefox if desired. We've landed this change on the trunk as a global extension as of 7 March 2006.
[http://www.google.com/tools/firefox/safebrowsing/ Google Safe Browsing] was an anti-phishing extension released by Google on [http://labs.google.com/ labs.google.com] in December 2005. Google has released this extension to the Mozilla Foundation under MPL 1.1/GPL 2.0/LGPL 2.1 in order that it might be used as part of Firefox if desired. We've landed this change on the trunk as a global extension as of 7 March 2006. You can read the discussion that lead up to to its integration in https://bugzilla.mozilla.org/show_bug.cgi?id=329292


You can read the discussion that lead up to to its integration in https://bugzilla.mozilla.org/show_bug.cgi?id=329292
Google started migrating their Safe Browsing to [https://developers.google.com/safe-browsing/v4/index version 4 of the protocol] in 2015. We completed our [[Security/Safe_Browsing/V4_Implementation|V4 implementation]] in late 2017 and shipped it in Firefox 56 via a [https://github.com/mozilla/sbv4-gradual-rollout Shield gradual roll-out].


= Prefs =
= Prefs =


* <tt>browser.safebrowsing.debug</tt>: show debugging info from the JavaScript list update code on the command line
* <tt>browser.safebrowsing.blockedURIs.enabled</tt>: enable the plugin stability blocking (no override or UI)
* <tt>browser.safebrowsing.enabled</tt>: enable '''phishing''' protection
* <tt>browser.safebrowsing.debug</tt>: show debugging info from the JavaScript list update code on the command line as long as <tt>browser.dom.window.dump.enabled</tt> is also enabled
* <tt>browser.safebrowsing.id</tt>: what SAFEBROWSING_ID in <tt>gethashURL</tt> and <tt>updateURL</tt> maps to
* <tt>browser.safebrowsing.id</tt>: what SAFEBROWSING_ID in <tt>gethashURL</tt> and <tt>updateURL</tt> maps to
* <tt>browser.safebrowsing.forbiddenURIs</tt>: enable support for '''forbidden''' sites blocking (no override possible)
* <tt>browser.safebrowsing.malware.enabled</tt>: enable '''malware''' protection (includes '''unwanted''' as well)
* <tt>browser.safebrowsing.malware.enabled</tt>: enable '''malware''' protection
* <tt>browser.safebrowsing.phishing.enabled</tt>: enable '''phishing''' protection
* <tt>browser.safebrowsing.provider.google.gethashURL</tt>: server endpoint for completions of malware and phishing lists
* <tt>browser.safebrowsing.provider.google.lists</tt>: list of tables coming from the Google Safe Browsing service
* <tt>browser.safebrowsing.provider.google.reportURL</tt>: probably unused
* <tt>browser.safebrowsing.provider.google.updateURL</tt>: server endpoint for malware and phishing list updates
* <tt>browser.safebrowsing.provider.google.lastupdatetime</tt>: timestamp (in ms) of when the last list update happened.
* <tt>browser.safebrowsing.provider.google.nextupdatetime</tt>: timestamp (in ms) of when the list should next be downloaded.
* <tt>browser.safebrowsing.reportMalwareMistakeURL</tt>: destination for the "This isn't an attack site" button (after ignoring the interstitial warning)
* <tt>browser.safebrowsing.reportMalwareMistakeURL</tt>: destination for the "This isn't an attack site" button (after ignoring the interstitial warning)
* <tt>browser.safebrowsing.reportPhishMistakeURL</tt>: destination for the "This isn't a web forgery" button (after ignoring the interstitial warning)
* <tt>browser.safebrowsing.reportPhishMistakeURL</tt>: destination for the "This isn't a web forgery" button (after ignoring the interstitial warning)
* <tt>browser.safebrowsing.reportPhishURL</tt>: destination for the "Help | Report Web Forgery" menu item
* <tt>browser.safebrowsing.reportPhishURL</tt>: destination for the "Help | Report Web Forgery" menu item
* <tt>urlclassifier.blockedTable</tt>: list of tables to use for the plugin stability blocking
* <tt>urlclassifier.disallow_completions</tt>: list of tables for which we never call <tt>gethash</tt>
* <tt>urlclassifier.disallow_completions</tt>: list of tables for which we never call <tt>gethash</tt>
* <tt>urlclassifier.forbiddenTable</tt>: list of tables to use when looking for sites to block without an override
* <tt>urlclassifier.gethashnoise</tt>: the number of fake entries to add to any <tt>gethash</tt> calls. Defaul value: 4. Maximum value: 999 (beyond, the Google request fails with HTTP 400).
* <tt>urlclassifier.gethashnoise</tt>: the number of fake entries to add to any <tt>gethash</tt> calls
* <tt>urlclassifier.gethash.timeout_ms</tt>: the timeout after which gethash requests should be aborted
* <tt>urlclassifier.malwareTable</tt>: list of tables to use when looking for malware (they need to be named <tt>*-malware-*</tt> or <tt>*-unwanted-*</tt>)
* <tt>urlclassifier.malwareTable</tt>: list of tables to use when looking for malware (they need to be named <tt>*-malware-*</tt> or <tt>*-unwanted-*</tt>)
* <tt>urlclassifier.max-complete-age</tt>
* <tt>urlclassifier.max-complete-age</tt>: the maximum amount of time in seconds that a complete hash will be considered fresh and allowed to match
* <tt>urlclassifier.phishTable</tt>: list of tables to use when looking for phishing (they need to be named <tt>*-phish-*</tt>)
* <tt>urlclassifier.phishTable</tt>: list of tables to use when looking for phishing (they need to be named <tt>*-phish-*</tt>)
 
* <tt>urlclassifier.skipHostnames</tt>: comma-separated list of hostnames to exempt from Safe Browsing checks (hidden, only for temporary hotfix purposes)
Firefox 42 and earlier:
 
* <tt>browser.safebrowsing.gethashURL</tt>: server endpoint for completions of malware and phishing lists
* <tt>browser.safebrowsing.malware.reportURL</tt>: probably unused
* <tt>browser.safebrowsing.updateURL</tt>: server endpoint for malware and phishing list updates
 
Firefox 43 and later:
 
* <tt>browser.safebrowsing.provider.google.gethashURL</tt>: server endpoint for completions of malware and phishing lists
* <tt>browser.safebrowsing.provider.google.lists</tt>: list of tables coming from the Google Safe Browsing service
* <tt>browser.safebrowsing.provider.google.reportURL</tt>: probably unused
* <tt>browser.safebrowsing.provider.google.updateURL</tt>: server endpoint for malware and phishing list updates


= Documentation =
= Documentation =
* [https://developers.google.com/safe-browsing/developers_guide_v2 Safe Browsing protocol v2.2]  
* Official Google documentation:
** Safe Browsing protocol: [https://web.archive.org/web/20160422212049/https://developers.google.com/safe-browsing/developers_guide_v2 v2.2] and [https://developers.google.com/safe-browsing/v4/ v4]
** [https://developers.google.com/safe-browsing/v4/usage-limits#UserWarnings User warning requirements]
** [https://mana.mozilla.org/wiki/display/FIREFOX/Safe+Browsing Internal documentation available under NDA]
** [https://developer.android.com/training/safetynet/safebrowsing.html Android API] (requires Google Play Services 9.4)
** [https://developer.android.com/preview/features/managing-webview.html#safe-browsing Built-in support in WebView] (public in Android O, private in Android N)
** [https://groups.google.com/forum/#!forum/google-safe-browsing-api Public API mailing list]
* [[Phishing Protection: Design Documentation|Design Documentation]]
* [[Phishing Protection: Design Documentation|Design Documentation]]
* [[Phishing Protection: Server Spec|Server Spec]]
** [[Phishing Protection: Server Spec|Server Spec]]
* [[Phishing Protection: Client Spec|Client Spec]]
** [[Phishing Protection: Client Spec|Client Spec]]
* [https://support.mozilla.org/en-US/kb/how-does-phishing-and-malware-protection-work SUMO]
* [https://support.mozilla.org/en-US/kb/how-does-phishing-and-malware-protection-work SUMO]
* [https://feeding.cloud.geek.nz/posts/how-safe-browsing-works-in-firefox/ Overview of how Safe Browsing works in Firefox]
* Chromium
** [https://www.chromium.org/developers/design-documents/safebrowsing Design documentation]
** [[Security/Safe_Browsing/Chromium_Implementation_Overview|Implementation overview]]
* Google's advice to site owners:
** [https://developers.google.com/webmasters/hacked/ Malware]
** [https://support.google.com/webmasters/answer/6350487 Deceptive content]
** [https://support.google.com/webmasters/answer/3258249 Potentially unwanted or uncommon software]


= Engineering =
= Engineering =
Product/Component: '''Toolkit/Safe Browsing'''
Product/Component: '''Toolkit/Safe Browsing'''


* [https://bugzilla.mozilla.org/show_bug.cgi?id=1149867 Tracking bug]
* <s>[https://bugzilla.mozilla.org/show_bug.cgi?id=1149867 Tracking bug]</s> ('''deprecated, do not use''')
* The Firefox implementation is split into a few parts:
* The Firefox implementation is split into a few parts:
** <tt>browser/components/safebrowsing/</tt> (front-end tests)
** <tt>browser/components/safebrowsing/</tt> (front-end tests)
Line 57: Line 66:
** <tt>~/.cache/mozilla/firefox/XXXX/safebrowsing/</tt> on Linux
** <tt>~/.cache/mozilla/firefox/XXXX/safebrowsing/</tt> on Linux
** <tt>~/Library/Caches/Firefox/Profiles/XXXX/safebrowsing/</tt> on Mac
** <tt>~/Library/Caches/Firefox/Profiles/XXXX/safebrowsing/</tt> on Mac
** <tt>C:\Users\XXXX\AppData\Local\mozilla\firefox\profiles\XXXX\safebrowsing\</tt> on Windows
* [https://github.com/mozilla/itisatrap itisatrap.org] test pages
* [https://github.com/mozilla/itisatrap itisatrap.org] test pages
* [https://people.mozilla.org/~fmarier/safebrowsing-dashboard/ Telemetry dashboard]
* [https://people.mozilla.org/~fmarier/safebrowsing-dashboard/ Telemetry dashboard]
Line 63: Line 73:


Both [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#611 nsBaseChannel::Open()] and [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#672 nsBaseChannel::AsyncOpen()] ask for the channel to be [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#306 "classified"] by
Both [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#611 nsBaseChannel::Open()] and [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#672 nsBaseChannel::AsyncOpen()] ask for the channel to be [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsBaseChannel.cpp#306 "classified"] by
[https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsChannelClassifier.cpp#354 nsChannelClassifier]. There is also a [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/protocol/http/nsHttpChannel.cpp#5185 local-only classification] that is requested by [[Security/Tracking protection|tracking protection]].
[https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsChannelClassifier.cpp#354 nsChannelClassifier]. There is also a [[Security/Tracking_protection#Code_walkthrough|local-only classification]] that is requested by [[Security/Tracking protection|tracking protection]].


The classifier [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#173 determines the type of URL that it is] and then [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#988 returns the appropriate NS_ERROR code]. That causes the channel to be [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/netwerk/base/nsChannelClassifier.cpp?offset=200#646 cancelled with that error code].
While we collect information about each of the list matches in [https://searchfox.org/mozilla-central/rev/da499aac682d0bbda5829327b60a865cbc491611/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#1454-1484 <tt>nsUrlClassifierClassifyCallback::HandleResult()</tt>], which is called for each matched list from
[https://searchfox.org/mozilla-central/rev/da499aac682d0bbda5829327b60a865cbc491611/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#1296-1326 <tt>nsUrlClassifierLookupCallback::HandleResults()</tt>], we pick only the highest priority list match and call <tt>OnClassifyComplete()</tt> in
[https://searchfox.org/mozilla-central/rev/da499aac682d0bbda5829327b60a865cbc491611/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#1433-1442 <tt>nsUrlClassifierClassifyCallback::HandleEvent()</tt>] according to:
 
* [https://searchfox.org/mozilla-central/rev/da499aac682d0bbda5829327b60a865cbc491611/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#1383-1389 priority of providers]
* [https://searchfox.org/mozilla-central/rev/da499aac682d0bbda5829327b60a865cbc491611/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#66-93 priority of warning types]
 
Then we [https://searchfox.org/mozilla-central/rev/8affe6e83188787eb61fe0528eeb6eef6081ba06/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp#1449 return information about the list match]. That causes the channel to be [https://searchfox.org/mozilla-central/rev/8affe6e83188787eb61fe0528eeb6eef6081ba06/netwerk/base/nsChannelClassifier.cpp#1174 cancelled with that error code].


When the [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/docshell/base/nsDocShell.cpp#7613 classification state of the page  changes], the appropriate UI [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/docshell/base/nsDocShell.cpp#4854  is shown].
When the [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/docshell/base/nsDocShell.cpp#7613 classification state of the page  changes], the appropriate UI [https://dxr.mozilla.org/mozilla-central/rev/f8086bd3c84fc1a42c3625cf3cc2253f0a5e8cfd/docshell/base/nsDocShell.cpp#4854  is shown].
== Tests ==
Here are all of the tests which are relevant to Safe Browsing:
./mach gtest UrlClassifier*
./mach test toolkit/components/url-classifier/tests/browser/
./mach test toolkit/components/url-classifier/tests/unit/
./mach test toolkit/components/url-classifier/tests/mochitest/
as well as the ones in <tt>testing/firefox-ui/tests/functional/safebrowsing/</tt>.
Also relevant are the [[Security/Tracking_protection#Tests|Tracking Protection tests]].


= QA =
= QA =


* <tt>about:url-classifier</tt> provides lots of useful state information
* Test pages
* Test pages
** [http://itisatrap.org/firefox/its-an-attack.html Malware], [http://itisatrap.org/firefox/its-a-trap.html phishing], [http://itisatrap.org/firefox/unwanted.html unwanted software] and [http://itisatrap.org/firefox/forbidden.html forbidden] hard-coded test URLs
** [http://itisatrap.org/firefox/its-an-attack.html Malware], [http://itisatrap.org/firefox/its-a-trap.html phishing], and [http://itisatrap.org/firefox/unwanted.html unwanted software] hard-coded test URLs
** [http://phishtank.com/ Phishtank] (real phishing sites)
** [http://phishtank.com/ Phishtank] (real phishing sites)
** [http://testsafebrowsing.appspot.com Google test pages]
** [http://testsafebrowsing.appspot.com Google test pages] (we don't implement: Clank Warnings, Client-side phishing detection, Bad IP Warnings)
** [https://github.com/mozilla/safebrowsing-test Static test pages for specific bugs]
* [https://bugzilla.mozilla.org/show_bug.cgi?id=1250329 Meta QA bug]
* [https://bugzilla.mozilla.org/show_bug.cgi?id=1250329 Meta QA bug]
* [https://www.google.com/transparencyreport/safebrowsing/diagnostic/index.html Info on why certain URLs are blocked]
* [https://www.google.com/transparencyreport/safebrowsing/diagnostic/index.html Info on why certain URLs are blocked]
* [https://github.com/fmarier/sbdbdump/blob/master/dump.py Script to dump the contents of the local store]
* [https://github.com/fmarier/sbdbdump/blob/master/dump.py Script to dump the contents of the local store]
* [https://github.com/mozilla/firefox-ui-tests/blob/mozilla-central/firefox_ui_tests/functional/security/ UI tests (Marionette)]
* [https://dxr.mozilla.org/mozilla-central/source/testing/firefox-ui/tests/functional/security UI tests (Marionette)]
* [https://hg.mozilla.org/qa/mozmill-tests/file/default/firefox/tests/remote/restartTests/testSafeBrowsing_initialDownload/test2.js Mozmill test for initial list download] (needs to be [https://bugzilla.mozilla.org/show_bug.cgi?id=1237396 ported to Marionette])
 
To turn on debugging output, export the following environment variables:
 
MOZ_LOG_FILE=/tmp/safebrowsing.log
MOZ_LOG="UrlClassifierDbService:5,nsChannelClassifier:5,UrlClassifierProtocolParser:5,UrlClassifierStreamUpdater:5,UrlClassifierPrefixSet:5"
 
and also see these prefs to see debugging output from the JS pieces of Safe Browsing:
 
  browser.dom.window.dump.enabled = true
  browser.safebrowsing.debug = true
 
= Telemetry =
 
'''Alerts are sent to [https://mail.mozilla.org/listinfo/safebrowsing-telemetry safebrowsing-telemetry@mozilla.org].'''


To turn on debugging output, export the following environment variable:
* Performance
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_ASYNC_CLASSIFYLOCAL_TIME&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-08&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_ASYNC_CLASSIFYLOCAL_TIME]: time spent inside AsyncClassifyLocalWithTables()
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_CLASSIFYLOCAL_TIME&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-08&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_CLASSIFYLOCAL_TIME]: time spent inside ClassifyLocalWithTables()
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_CL_CHECK_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_CL_CHECK_TIME]: how long a Safe Browsing lookup took
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=google!google4!other!mozilla&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_CL_KEYED_UPDATE_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_CL_KEYED_UPDATE_TIME]: how long table updates takes
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_LOOKUP_TIME_2&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-08&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_LOOKUP_TIME_2]: time spent in the dbservice while doing a lookup
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_PS_CONSTRUCT_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_PS_CONSTRUCT_TIME]: time spent constructing a PrefixSet
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_PS_FALLOCATE_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_PS_FALLOCATE_TIME]: time spent allocating a PrefixSet
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_PS_FILELOAD_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_PS_FILELOAD_TIME]: time spent loading PrefixSet from disk
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_SHUTDOWN_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_SHUTDOWN_TIME]: time spent in the URL Classifier shutdown code
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_VLPS_CONSTRUCT_TIME&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-08&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_VLPS_CONSTRUCT_TIME]: time spent constructing a variable-length PrefixSet
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_VLPS_FALLOCATE_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_VLPS_FALLOCATE_TIME]: time spent allocating a variable-length PrefixSet
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_VLPS_FILELOAD_TIME&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_VLPS_FILELOAD_TIME]: time spent loading a variable-length PrefixSet from disk
* Server-related
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=google!__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_COMPLETE_REMOTE_STATUS2&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_COMPLETE_REMOTE_STATUS2]: HTTP status code returned by the gethash server
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-18&keys=google4!google!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_COMPLETE_SERVER_RESPONSE_TIME&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-30&table=0&trim=1&use_submission_date=0 URLCLASSIFIER_COMPLETE_SERVER_RESPONSE_TIME]: response time from the completion server
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=google!__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_COMPLETE_TIMEOUT2&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_COMPLETE_TIMEOUT2]: whether or not a client timed out while contacting the gethash server
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=__none__!__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_COMPLETION_ERROR&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_COMPLETION_ERROR]: whether a V4 completion result couldn't be parsed or contained an unknown threat type
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=google!other!mozilla!other&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_UPDATE_ERROR&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UPDATE_ERROR]: whether or not an error was encountered while processing an update
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=google4!google!mozilla!other&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_UPDATE_REMOTE_NETWORK_ERROR&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-08&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UPDATE_REMOTE_NETWORK_ERROR]: update errors while downloading updates
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=google!other!mozilla!other&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_UPDATE_REMOTE_STATUS2&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UPDATE_REMOTE_STATUS2]: HTTP status code returned by the update server
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-18&keys=google4!google!mozilla&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_UPDATE_SERVER_RESPONSE_TIME&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-30&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UPDATE_SERVER_RESPONSE_TIME]: response time from the update server
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-05-18&keys=google4!google!mozilla&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_UPDATE_TIMEOUT&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-05-03&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UPDATE_TIMEOUT]: whether or not a client timed out while contacting the update server
* Database size
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_LC_COMPLETIONS&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_LC_COMPLETIONS]: number of entries in the completion cache
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2016-06-06&keys=__none__!__none__!__none__&max_channel_version=nightly%252F49&measure=URLCLASSIFIER_LC_PREFIXES&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2016-04-25&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_LC_PREFIXES]: number of entries in the prefix cache
* User interface
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-08-21&keys=__none__!__none__!__none__&max_channel_version=nightly%252F57&measure=URLCLASSIFIER_UI_EVENTS&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-08-08&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_UI_EVENTS]: number of interstitial pages shown ([https://searchfox.org/mozilla-central/source/toolkit/components/url-classifier/IUrlClassifierUITelemetry.idl malware, phishing, unwanted, harmful]) either in a top-level page or in a frame and the number of times users click on "Ignore this warning", "Get me out of here" or "Why is this blocked?"
* V4 quality assurance
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-19&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_NEGATIVE_CACHE_DURATION&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_NEGATIVE_CACHE_DURATION]: negative cache duration received in fullhash response
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-04-18&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_POSITIVE_CACHE_DURATION&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-03-22&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_POSITIVE_CACHE_DURATION]: positive cache duration received in fullhash response
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-01-30&keys=__none__!__none__!__none__&max_channel_version=nightly%252F54&measure=URLCLASSIFIER_VLPS_LOAD_CORRUPT&min_channel_version=null&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-01-23&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_VLPS_LOAD_CORRUPT]: whether or not a variable-length PrefixSet loaded from disk is corrupt
** [https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&end_date=2017-05-18&keys=__none__!__none__!__none__&max_channel_version=nightly%252F55&measure=URLCLASSIFIER_VLPS_LONG_PREFIXES&min_channel_version=null&processType=*&product=Firefox&sanitize=1&sort_keys=submissions&start_date=2017-05-16&table=1&trim=1&use_submission_date=0 URLCLASSIFIER_VLPS_LONG_PREFIXES]  ('''Nightly-only'''): length of the variable-length prefixes that are sent by Google


NSPR_LOG_MODULES="UrlClassifierDbService:5,nsChannelClassifier:5,UrlClassifierProtocolParser:5,UrlClassifierStreamUpdater:5,UrlClassifierPrefixSet:5"
= Links =


and also see the <tt>browser.safebrowsing.debug</tt> pref to see debugging output from the JS pieces of Safe Browsing.
* Google reporting forms:
** [https://safebrowsing.google.com/safebrowsing/report_badware/ Malware]
** [https://safebrowsing.google.com/safebrowsing/report_phish/ Phishing] -- [https://safebrowsing.google.com/safebrowsing/report_phish/?tpl=mozilla Firefox-specific]
** [https://safebrowsing.google.com/safebrowsing/report_error/ Phishing error] (false positive) -- [https://safebrowsing.google.com/safebrowsing/report_error/?tpl=mozilla Firefox-specific]
** [https://safebrowsing.google.com/safebrowsing/report_general/ General] (false negatives and false positives)
* StopBadware.org form:
** [https://www.stopbadware.org/firefox Malware error]
* [https://intranet.mozilla.org/SafeBrowsing API key and account details] (internal access only)

Latest revision as of 01:24, 19 May 2021

Note: The Safe Browsing feature in Firefox has been renamed to Phishing Protection, but it's still known as Safe Browsing internally.

Download Protection and Tracking protection have their own separate pages.

History

Google Safe Browsing was an anti-phishing extension released by Google on labs.google.com in December 2005. Google has released this extension to the Mozilla Foundation under MPL 1.1/GPL 2.0/LGPL 2.1 in order that it might be used as part of Firefox if desired. We've landed this change on the trunk as a global extension as of 7 March 2006. You can read the discussion that lead up to to its integration in https://bugzilla.mozilla.org/show_bug.cgi?id=329292

Google started migrating their Safe Browsing to version 4 of the protocol in 2015. We completed our V4 implementation in late 2017 and shipped it in Firefox 56 via a Shield gradual roll-out.

Prefs

  • browser.safebrowsing.blockedURIs.enabled: enable the plugin stability blocking (no override or UI)
  • browser.safebrowsing.debug: show debugging info from the JavaScript list update code on the command line as long as browser.dom.window.dump.enabled is also enabled
  • browser.safebrowsing.id: what SAFEBROWSING_ID in gethashURL and updateURL maps to
  • browser.safebrowsing.malware.enabled: enable malware protection (includes unwanted as well)
  • browser.safebrowsing.phishing.enabled: enable phishing protection
  • browser.safebrowsing.provider.google.gethashURL: server endpoint for completions of malware and phishing lists
  • browser.safebrowsing.provider.google.lists: list of tables coming from the Google Safe Browsing service
  • browser.safebrowsing.provider.google.reportURL: probably unused
  • browser.safebrowsing.provider.google.updateURL: server endpoint for malware and phishing list updates
  • browser.safebrowsing.provider.google.lastupdatetime: timestamp (in ms) of when the last list update happened.
  • browser.safebrowsing.provider.google.nextupdatetime: timestamp (in ms) of when the list should next be downloaded.
  • browser.safebrowsing.reportMalwareMistakeURL: destination for the "This isn't an attack site" button (after ignoring the interstitial warning)
  • browser.safebrowsing.reportPhishMistakeURL: destination for the "This isn't a web forgery" button (after ignoring the interstitial warning)
  • browser.safebrowsing.reportPhishURL: destination for the "Help | Report Web Forgery" menu item
  • urlclassifier.blockedTable: list of tables to use for the plugin stability blocking
  • urlclassifier.disallow_completions: list of tables for which we never call gethash
  • urlclassifier.gethashnoise: the number of fake entries to add to any gethash calls. Defaul value: 4. Maximum value: 999 (beyond, the Google request fails with HTTP 400).
  • urlclassifier.gethash.timeout_ms: the timeout after which gethash requests should be aborted
  • urlclassifier.malwareTable: list of tables to use when looking for malware (they need to be named *-malware-* or *-unwanted-*)
  • urlclassifier.max-complete-age: the maximum amount of time in seconds that a complete hash will be considered fresh and allowed to match
  • urlclassifier.phishTable: list of tables to use when looking for phishing (they need to be named *-phish-*)
  • urlclassifier.skipHostnames: comma-separated list of hostnames to exempt from Safe Browsing checks (hidden, only for temporary hotfix purposes)

Documentation

Engineering

Product/Component: Toolkit/Safe Browsing

  • Tracking bug (deprecated, do not use)
  • The Firefox implementation is split into a few parts:
    • browser/components/safebrowsing/ (front-end tests)
    • netwerk/base/nsChannelClassifier
    • toolkit/components/url-classifier/ (includes the list manager)
  • Local store is in:
    • ~/.cache/mozilla/firefox/XXXX/safebrowsing/ on Linux
    • ~/Library/Caches/Firefox/Profiles/XXXX/safebrowsing/ on Mac
    • C:\Users\XXXX\AppData\Local\mozilla\firefox\profiles\XXXX\safebrowsing\ on Windows
  • itisatrap.org test pages
  • Telemetry dashboard

Code walkthrough

Both nsBaseChannel::Open() and nsBaseChannel::AsyncOpen() ask for the channel to be "classified" by nsChannelClassifier. There is also a local-only classification that is requested by tracking protection.

While we collect information about each of the list matches in nsUrlClassifierClassifyCallback::HandleResult(), which is called for each matched list from nsUrlClassifierLookupCallback::HandleResults(), we pick only the highest priority list match and call OnClassifyComplete() in nsUrlClassifierClassifyCallback::HandleEvent() according to:

Then we return information about the list match. That causes the channel to be cancelled with that error code.

When the classification state of the page changes, the appropriate UI is shown.

Tests

Here are all of the tests which are relevant to Safe Browsing:

./mach gtest UrlClassifier*
./mach test toolkit/components/url-classifier/tests/browser/
./mach test toolkit/components/url-classifier/tests/unit/
./mach test toolkit/components/url-classifier/tests/mochitest/

as well as the ones in testing/firefox-ui/tests/functional/safebrowsing/.

Also relevant are the Tracking Protection tests.

QA

To turn on debugging output, export the following environment variables:

MOZ_LOG_FILE=/tmp/safebrowsing.log
MOZ_LOG="UrlClassifierDbService:5,nsChannelClassifier:5,UrlClassifierProtocolParser:5,UrlClassifierStreamUpdater:5,UrlClassifierPrefixSet:5"

and also see these prefs to see debugging output from the JS pieces of Safe Browsing:

 browser.dom.window.dump.enabled = true
 browser.safebrowsing.debug = true

Telemetry

Alerts are sent to safebrowsing-telemetry@mozilla.org.

Links