-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ft-domain_blacklist_dom_start'
* ft-domain_blacklist_dom_start: Added logic to perform the blacklisting on document_start - this makes the redirect faster, and doesn't wait for page load, which caused sometimes the phishing alert to not happen.
- Loading branch information
Showing
3 changed files
with
98 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
(function() { | ||
let objBrowser = chrome ? chrome : browser; | ||
//Get the blacklist domains option for the user | ||
objBrowser.runtime.sendMessage({func: "blacklist_domains"}, function(objResponse) { | ||
if(objResponse && objResponse.hasOwnProperty("resp")) { | ||
if(objResponse.resp == 1) { | ||
blacklistedDomainCheck(); | ||
} | ||
} | ||
}); | ||
|
||
//Detects if the current tab is in the blacklisted domains file | ||
function blacklistedDomainCheck() | ||
{ | ||
let objBrowser = chrome ? chrome : browser; | ||
var arrBlacklistedDomains = []; | ||
var arrWhitelistedDomains = ["www.myetherwallet.com", "myetherwallet.com"]; | ||
objBrowser.runtime.sendMessage({func: "blacklist_domain_list"}, function(objResponse) { | ||
if(objResponse && objResponse.hasOwnProperty("resp")) { | ||
arrBlacklistedDomains = objResponse.resp; | ||
objBrowser.runtime.sendMessage({func: "whitelist_domain_list"}, function(objResponse) { | ||
if(objResponse && objResponse.hasOwnProperty("resp")) { | ||
arrWhitelistedDomains = objResponse.resp; | ||
return doBlacklistCheck(); | ||
} | ||
}.bind(arrWhitelistedDomains)); | ||
} | ||
}.bind(arrBlacklistedDomains)); | ||
|
||
function doBlacklistCheck() { | ||
if(arrBlacklistedDomains.length > 0) { | ||
var strCurrentTab = window.location.hostname; | ||
|
||
//Domain is whitelisted, don't check the blacklist. | ||
if(arrWhitelistedDomains.includes(strCurrentTab)) { | ||
console.log("Domain "+ strCurrentTab +" is whitelisted on EAL!"); | ||
return; | ||
} | ||
|
||
//Levenshtien - @sogoiii | ||
var isBlacklisted = arrBlacklistedDomains.includes(strCurrentTab); | ||
var source = strCurrentTab.replace(/\./g,''); | ||
var intHolisticMetric = levenshtein(source, 'myetherwallet'); | ||
var intHolisticLimit = 7 // How different can the word be? | ||
var blHolisticStatus = (intHolisticMetric > 0 && intHolisticMetric < intHolisticLimit) ? true : false; | ||
|
||
if (isBlacklisted || blHolisticStatus ) { | ||
window.location.href = "https://harrydenley.com/EtherAddressLookup/phishing.html"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
function levenshtein(a, b) { | ||
if(a.length == 0) return b.length; | ||
if(b.length == 0) return a.length; | ||
|
||
// swap to save some memory O(min(a,b)) instead of O(a) | ||
if(a.length > b.length) { | ||
var tmp = a; | ||
a = b; | ||
b = tmp; | ||
} | ||
|
||
var row = []; | ||
// init the row | ||
for(var i = 0; i <= a.length; i++){ | ||
row[i] = i; | ||
} | ||
|
||
// fill in the rest | ||
for(var i = 1; i <= b.length; i++){ | ||
var prev = i; | ||
for(var j = 1; j <= a.length; j++){ | ||
var val; | ||
if(b.charAt(i-1) == a.charAt(j-1)){ | ||
val = row[j-1]; // match | ||
} else { | ||
val = Math.min(row[j-1] + 1, // substitution | ||
prev + 1, // insertion | ||
row[j] + 1); // deletion | ||
} | ||
row[j - 1] = prev; | ||
prev = val; | ||
} | ||
row[a.length] = prev; | ||
} | ||
|
||
return row[a.length]; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters