Skip to content

Commit c0273c8

Browse files
1.4.1b
Fixes a non-critical vulnerability: requests to loopback/private addresses should be ignored. See #21
1 parent d88751c commit c0273c8

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/bg/webRequest.js

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
'use strict';
22

3-
const acao = {name: 'Access-Control-Allow-Origin', value: '*'};
4-
const filter = {urls: ["<all_urls>"]};
5-
const rIDs = {}; // tab objs by request ID
6-
const getRoot = host => {
3+
/** ---------- Functions ---------- **/
4+
5+
function IPinRange(ip, min, max) {
6+
for (const i in ip) {
7+
if (ip[i] < min[i] || ip[i] > max[i]) return;
8+
}
9+
return true;
10+
}
11+
12+
function isReservedAddress(str) {
13+
const addr = str.split('.');
14+
if (addr.length !== 4) return;
15+
for (const part of addr) {
16+
if (Number.isNaN(+part) || part < 0 || part > 255) return;
17+
}
18+
return (
19+
IPinRange(addr, [10,0,0,0], [10,255,255,255]) ||
20+
IPinRange(addr, [100,64,0,0], [100,127,255,255]) ||
21+
IPinRange(addr, [127,0,0,0], [127,255,255,255]) ||
22+
IPinRange(addr, [169,254,0,0], [169,254,255,255]) ||
23+
IPinRange(addr, [172,16,0,0], [172,31,255,255]) ||
24+
IPinRange(addr, [192,0,0,0], [192,0,0,255]) ||
25+
IPinRange(addr, [192,168,0,0], [192,168,255,255]) ||
26+
IPinRange(addr, [198,18,0,0], [198,19,255,255])
27+
);
28+
}
29+
30+
function getRoot(host) {
731
const parts = host.split('.');
832
let root;
933
while (parts.length > 1) {
@@ -17,8 +41,9 @@ const getRoot = host => {
1741
}
1842
}
1943
return root;
20-
};
21-
const isExcluded = (origin, target) => {
44+
}
45+
46+
function isExcluded(origin, target) {
2247
const arr = settings.exclusions;
2348
for (const e of arr) {
2449
if (e.origin.includes('*')) {
@@ -31,7 +56,13 @@ const isExcluded = (origin, target) => {
3156
} else if (e.target !== target) continue;
3257
return true;
3358
}
34-
};
59+
}
60+
61+
/** ------------------------------ **/
62+
63+
const acao = {name: 'Access-Control-Allow-Origin', value: '*'};
64+
const filter = {urls: ["<all_urls>"]};
65+
const rIDs = {}; // tab objs by request ID
3566

3667
browser.webRequest.onBeforeSendHeaders.addListener(d => {
3768
if (d.tabId === -1 || !d.requestHeaders) return;
@@ -57,7 +88,7 @@ browser.webRequest.onBeforeSendHeaders.addListener(d => {
5788
target.hash ||
5889
target.username ||
5990
target.password
60-
)
91+
) || isReservedAddress(target.hostname)
6192
) return;
6293

6394
const newHeaders = [];

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
"webRequestBlocking"
3838
],
3939
"short_name": "POOP",
40-
"version": "1.4.0"
40+
"version": "1.4.1b"
4141
}

0 commit comments

Comments
 (0)