From c38f1acc3878025148540820642612cec3b0bcf9 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 22 Jan 2022 02:25:58 +0530 Subject: [PATCH] Fix potential exponential backtracking in regex in utils.parseExtensionSource --- dist/index.js | 2 +- src/utils.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 664c9404..234c64a2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1177,7 +1177,7 @@ async function customPackage(pkg, type, version, os_version) { } exports.customPackage = customPackage; async function parseExtensionSource(extension, prefix) { - const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/; + const regex = /(\w+)-(\w+:\/\/.{1,253}(?:[.:][^:/\s]{2,63})+\/)?([\w.-]+)\/([\w.-]+)@(.+)/; const matches = regex.exec(extension); matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com'; return await joins('\nadd_extension_from_source', ...matches.splice(1, matches.length), prefix); diff --git a/src/utils.ts b/src/utils.ts index ab9579f7..1692fbc2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -492,7 +492,8 @@ export async function parseExtensionSource( prefix: string ): Promise { // Groups: extension, domain url, org, repo, release - const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/; + const regex = + /(\w+)-(\w+:\/\/.{1,253}(?:[.:][^:/\s]{2,63})+\/)?([\w.-]+)\/([\w.-]+)@(.+)/; const matches = regex.exec(extension) as RegExpExecArray; matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com'; return await joins(