Skip to content

Commit 0bb4761

Browse files
Allow 127.0.0.1 as valid URL for scraping (#2560)
* allow 127.0.0.1 as valid url for scraping * update comments and lint --------- Co-authored-by: timothycarambat <[email protected]>
1 parent e719d05 commit 0bb4761

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

collector/extensions/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ function extensions(app) {
118118
try {
119119
const websiteDepth = require("../utils/extensions/WebsiteDepth");
120120
const { url, depth = 1, maxLinks = 20 } = reqBody(request);
121-
if (!validURL(url)) return { success: false, reason: "Not a valid URL." };
122-
121+
if (!validURL(url)) throw new Error("Not a valid URL.");
123122
const scrapedData = await websiteDepth(url, depth, maxLinks);
124123
response.status(200).json({ success: true, data: scrapedData });
125124
} catch (e) {

collector/utils/url/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** ATTN: SECURITY RESEARCHERS
22
* To Security researchers about to submit an SSRF report CVE - please don't.
33
* We are aware that the code below is does not defend against any of the thousands of ways
4-
* you can map a hostname to another IP. The code below does not have intention of blocking this
4+
* you can map a hostname to another IP via tunneling, hosts editing, etc. The code below does not have intention of blocking this
55
* and is simply to prevent the user from accidentally putting in non-valid websites, which is all this protects
66
* since _all urls must be submitted by the user anyway_ and cannot be done with authentication and manager or admin roles.
77
* If an attacker has those roles then the system is already vulnerable and this is not a primary concern.
@@ -14,15 +14,29 @@
1414
const VALID_PROTOCOLS = ["https:", "http:"];
1515
const INVALID_OCTETS = [192, 172, 10, 127];
1616

17+
/**
18+
* If an ip address is passed in the user is attempting to collector some internal service running on internal/private IP.
19+
* This is not a security feature and simply just prevents the user from accidentally entering invalid IP addresses.
20+
* @param {URL} param0
21+
* @param {URL['hostname']} param0.hostname
22+
* @returns {boolean}
23+
*/
1724
function isInvalidIp({ hostname }) {
1825
const IPRegex = new RegExp(
1926
/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/gi
2027
);
28+
29+
// Not an IP address at all - passthrough
2130
if (!IPRegex.test(hostname)) return false;
2231
const [octetOne, ..._rest] = hostname.split(".");
2332

2433
// If fails to validate to number - abort and return as invalid.
2534
if (isNaN(Number(octetOne))) return true;
35+
36+
// Allow localhost loopback and 0.0.0.0 for scraping convenience
37+
// for locally hosted services or websites
38+
if (["127.0.0.1", "0.0.0.0"].includes(hostname)) return false;
39+
2640
return INVALID_OCTETS.includes(Number(octetOne));
2741
}
2842

0 commit comments

Comments
 (0)