summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorhackademix2019-10-05 15:42:29 +0200
committerhackademix2019-10-05 15:45:56 +0200
commit5ee30535c41678209e52346fc69067753aa310b0 (patch)
treef75d3a39c2292b395b894030ab225300515314d9 /src/common
parent9e951a378c1bb86b5fd4c658966d148578aa6462 (diff)
downloadnoscript-5ee30535c41678209e52346fc69067753aa310b0.tar.gz
noscript-5ee30535c41678209e52346fc69067753aa310b0.tar.xz
noscript-5ee30535c41678209e52346fc69067753aa310b0.zip
IPv4 subnet shortcut matching.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Policy.js27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/common/Policy.js b/src/common/Policy.js
index 674263a..71e6ff9 100644
--- a/src/common/Policy.js
+++ b/src/common/Policy.js
@@ -3,6 +3,7 @@ var {Permissions, Policy, Sites} = (() => {
const SECURE_DOMAIN_PREFIX = "ยง:";
const SECURE_DOMAIN_RX = new RegExp(`^${SECURE_DOMAIN_PREFIX}`);
const DOMAIN_RX = new RegExp(`(?:^\\w+://|${SECURE_DOMAIN_PREFIX})?([^/]*)`, "i");
+ const IPV4_RX = /^(?:\d+\.){1,3}\d+/;
const INTERNAL_SITE_RX = /^(?:(?:about|chrome|resource|(?:moz|chrome)-.*):|\[System)/;
const VALID_SITE_RX = /^(?:(?:(?:(?:http|ftp|ws)s?|file):)(?:(?:\/\/)[\w\u0100-\uf000][\w\u0100-\uf000.-]*[\w\u0100-\uf000.](?:$|\/))?|[\w\u0100-\uf000][\w\u0100-\uf000.-]*[\w\u0100-\uf000]$)/;
@@ -158,6 +159,7 @@ var {Permissions, Policy, Sites} = (() => {
if (!hostname) return null;
if (!tld.preserveFQDNs) hostname = tld.normalize(hostname);
let secure = protocol === "https:";
+ let isIPv4 = IPV4_RX.test(hostname);
for (let domain = hostname;;) {
if (this.has(domain)) {
return domain;
@@ -168,13 +170,24 @@ var {Permissions, Policy, Sites} = (() => {
return ssDomain;
}
}
- let dotPos = domain.indexOf(".");
- if (dotPos === -1) {
- break;
- }
- domain = domain.substring(dotPos + 1); // sub
- if (!domain) {
- break;
+
+ if (isIPv4) {
+ // subnet shortcuts
+ let dotPos = domain.lastIndexOf(".");
+ if (!(dotPos > 3 || domain.indexOf(".") < dotPos)) {
+ break; // we want at least the 2 most significant bytes
+ }
+ domain = domain.substring(0, dotPos);
+ } else {
+ // (sub)domain matching
+ let dotPos = domain.indexOf(".");
+ if (dotPos === -1) {
+ break;
+ }
+ domain = domain.substring(dotPos + 1); // upper level
+ if (!domain) {
+ break;
+ }
}
}
return null;