Skip to content

Commit a710f66

Browse files
committed
fix(grade): Set grades of IPAddr/localhost/not-http-or-https sites to unknown
1 parent 0a3e62f commit a710f66

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

js/cloudopt-core.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,8 @@ cloudopt.grade = (function (cloudopt) {
944944

945945
/**
946946
* Decide the secure level of a website
947-
*
948-
* @param result result of website()
947+
*
948+
* @param result result of website()
949949
*/
950950
function classify(result) {
951951
var level = 0; /* no level */
@@ -955,6 +955,8 @@ cloudopt.grade = (function (cloudopt) {
955955
level = 2; /* normal */
956956
} else if (result.score >= 40) {
957957
level = 3; /* potential threat */
958+
} else if (result.score === 0 && result.safe) {
959+
level = 5; /* unknown */
958960
} else {
959961
level = 4; /* dangerous */
960962
}
@@ -969,9 +971,12 @@ cloudopt.grade = (function (cloudopt) {
969971
safe = true;
970972
}
971973
if (level === 3) {
972-
if (config.safePotential)
973-
safe = false;
974-
else
974+
if (config.safePotential)
975+
safe = false;
976+
else
977+
safe = true;
978+
}
979+
if (level === 5) {
975980
safe = true;
976981
}
977982
if (config.whiteList.indexOf(result.host) > -1 || config.whiteListAds.indexOf(result.host) > -1) {
@@ -984,47 +989,63 @@ cloudopt.grade = (function (cloudopt) {
984989
return safe;
985990
}
986991

992+
function couldGrade(url) {
993+
if (!url.startsWith("http://") && !url.startsWith("https://")) {
994+
return false;
995+
}
996+
var host = cloudopt.utils.getHost(url);
997+
if (/^([0-9]{1,3}\.){3}[0-9]{1,3}$/.test(host)
998+
|| "localhost" === host) {
999+
return false;
1000+
}
1001+
1002+
return true;
1003+
}
1004+
9871005
/**
9881006
* Check the url and get the web data. Such as score ,type, host
9891007
*
9901008
* @param website url
9911009
* @param callback callback function
9921010
*/
9931011
function website(website, callback) {
994-
var cacheSuffix = "_grade_1.0";
995-
website = cloudopt.utils.getHost(website);
996-
website = website + cacheSuffix;
1012+
// safe=true and score=0 represent that this site has no grade
9971013
var result = {
9981014
safe: true,
9991015
type: "",
10001016
date: new Date(),
10011017
score: 0,
10021018
host: ""
10031019
};
1004-
if (website.startsWith("192.") || website.startsWith("localhost") || website.startsWith("127.")) {
1005-
return result;
1020+
if (!couldGrade(website)) {
1021+
callback(result);
1022+
return;
10061023
}
1007-
result.host = website.replace(cacheSuffix, "");
10081024

1009-
cloudopt.store.get(website, function (item) {
1025+
var cacheSuffix = "_grade_1.0";
1026+
website = cloudopt.utils.getHost(website);
1027+
result.host = website;
1028+
cacheKey = website + cacheSuffix;
1029+
1030+
cloudopt.store.get(cacheKey, function (item) {
10101031
if (item != undefined && JSON.stringify(item) != "{}" && cloudopt.utils.comparisonDate(item.date, defaultExpireTime.safeWebsite)) {
10111032
cloudopt.config.refresh(function () {
10121033
item.safe = isSafe(item);
10131034
callback(item);
10141035
});
10151036
return;
10161037
} else {
1017-
cloudopt.store.remove(website);
1018-
cloudopt.http.get(cloudopt.host + 'grade/website/' + website.replace(cacheSuffix, ''),{
1038+
cloudopt.store.remove(cacheKey);
1039+
cloudopt.http.get(cloudopt.host + 'grade/website/' + website, {
10191040
timeout: 30000
10201041
}).carryApiKey().then(data=>{
10211042
result.safe = isSafe(data.result);
10221043
result.type = data.result.type;
10231044
result.score = data.result.score;
1024-
1045+
10251046
if (data.result.host != "") {
10261047
result.date = new Date().getTime();
1027-
cloudopt.store.set(website, result);
1048+
cloudopt.store.set(cacheKey, result);
10281049
}
10291050
callback(result);
10301051
},error=>{
@@ -1161,17 +1182,10 @@ cloudopt.browserIconChange = (function (cloudopt) {
11611182

11621183
function auto(url) {
11631184
cloudopt.grade.website(url, function(result) {
1164-
if (url.indexOf("file://") == 0
1165-
|| url.indexOf("chrome-extension://") == 0
1166-
|| url.indexOf("chrome://") == 0) {
1167-
gray();
1168-
return;
1169-
}
1170-
11711185
var level = cloudopt.grade.classify(result);
11721186
if (result.safe === false) {
11731187
danger();
1174-
} else if (level == 3) {
1188+
} else if (level == 3 || level == 5) {
11751189
gray();
11761190
} else if (level == 2) {
11771191
normal();

js/cloudopt-popup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cloudopt.onFinish(function() {
2-
2+
33
function _checkEvaluateTips(url) {
44
const key = "evaluate_tip_"+url;
55
cloudopt.store.get(key, function(lastShown) {
@@ -33,10 +33,6 @@ cloudopt.onFinish(function() {
3333
active: true,
3434
currentWindow: true
3535
}, function(tabArray) {
36-
if (tabArray[tabArray.length - 1].url.indexOf("file://") == 0 || tabArray[tabArray.length - 1].url.indexOf("chrome-extension://") == 0 || tabArray[tabArray.length - 1].url.indexOf("chrome://") == 0) {
37-
$(".score h1").text("?");
38-
return;
39-
}
4036

4137
url = tabArray[tabArray.length - 1].url;
4238

0 commit comments

Comments
 (0)