From 4dd6c8168f3dbec5a0e910069a4a29a640e39942 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Mon, 1 Oct 2018 20:28:46 -0230 Subject: Add ability to whitelist a blacklisted domain at runtime --- app/scripts/controllers/blacklist.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js index 1d2191433..89c7cc888 100644 --- a/app/scripts/controllers/blacklist.js +++ b/app/scripts/controllers/blacklist.js @@ -29,6 +29,7 @@ class BlacklistController { constructor (opts = {}) { const initState = extend({ phishing: PHISHING_DETECTION_CONFIG, + whitelist: [], }, opts.initState) this.store = new ObservableStore(initState) // phishing detector @@ -38,6 +39,21 @@ class BlacklistController { this._phishingUpdateIntervalRef = null } + /** + * Adds the given hostname to the runtime whitelist + * @param {string} hostname the hostname to whitelist + */ + whitelistDomain (hostname) { + if (!hostname) { + return + } + + const { whitelist } = this.store.getState() + this.store.updateState({ + whitelist: [...new Set([hostname, ...whitelist])], + }) + } + /** * Given a url, returns the result of checking if that url is in the store.phishing blacklist * @@ -48,6 +64,12 @@ class BlacklistController { */ checkForPhishing (hostname) { if (!hostname) return false + + const { whitelist } = this.store.getState() + if (whitelist.some((e) => e === hostname)) { + return false + } + const { result } = this._phishingDetector.check(hostname) return result } -- cgit v1.2.3