Headline
CVE-2018-25079: security: Fix REDOS vulnerability · segmentio/is-url@1495509
A vulnerability was found in Segmentio is-url up to 1.2.2. It has been rated as problematic. Affected by this issue is some unknown functionality of the file index.js. The manipulation leads to inefficient regular expression complexity. The attack may be launched remotely. Upgrading to version 1.2.3 is able to address this issue. The name of the patch is 149550935c63a98c11f27f694a7c4a9479e53794. It is recommended to upgrade the affected component. VDB-220058 is the identifier assigned to this vulnerability.
@@ -6,10 +6,15 @@ module.exports = isUrl;
/** * Matcher. * RegExps. * A URL must match #1 and then at least one of #2/#3. * Use two levels of REs to avoid REDOS. */
var matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/; var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/ var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
/** * Loosely validate a URL `string`. @@ -19,5 +24,20 @@ var matcher = /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/; */
function isUrl(string){ return matcher.test(string); var match = string.match(protocolAndDomainRE); if (!match) { return false; }
var everythingAfterProtocol = match[1]; if (!everythingAfterProtocol) { return false; }
if (localhostDomainRE.test(everythingAfterProtocol) || nonLocalhostDomainRE.test(everythingAfterProtocol)) { return true; }
return false; }