Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit e8f4696

Browse files
authored
Merge pull request #375 from mozilla/is-local-check
Improve isLocal check. Fixes #366
2 parents 0e33780 + 0a279ce commit e8f4696

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/background.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,17 +536,18 @@ class Background {
536536
}
537537

538538
function isLocal(url) {
539-
if (url.hostname === "localhost" ||
540-
url.hostname === "localhost.localdomain" ||
541-
url.hostname === "localhost6" ||
542-
url.hostname === "localhost6.localdomain6") {
543-
return true;
544-
}
545-
const localports = /(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/;
546-
if (localports.test(url.hostname)) {
547-
return true;
548-
}
549-
return false;
539+
let hostname = url.hostname;
540+
return (/(.+\.)?localhost$/.test(hostname) ||
541+
/(.+\.)?localhost6$/.test(hostname) ||
542+
/(.+\.)?localhost.localdomain$/.test(hostname) ||
543+
/(.+\.)?localhost6.localdomain6$/.test(hostname) ||
544+
/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
545+
/^192\.168\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
546+
/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
547+
/^172\.1[6-9]\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
548+
/^172\.2[0-9]\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
549+
/^172\.3[0-1]\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
550+
/\[[0:]+1\]/.test(hostname));
550551
}
551552

552553
// We want to continue the sending of requests to the proxy even if we

0 commit comments

Comments
 (0)