Skip to content

Commit 79ae79f

Browse files
glowcloudchar0n
andauthored
fix(security): remedy polynomial regular expression without limiting length to 29 chars (#3507)
Refs #3501 --------- Co-authored-by: Vladimir Gorej <vladimir.gorej@gmail.com>
1 parent fd5d27c commit 79ae79f

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/execute/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function oas3BaseUrl({ spec, pathName, method, server, contextUrl, serverVariabl
347347

348348
if (selectedServerUrl.includes('{')) {
349349
// do variable substitution
350-
const varNames = getVariableTemplateNames(selectedServerUrl);
350+
const varNames = extractServerVariableNames(selectedServerUrl);
351351
varNames.forEach((variable) => {
352352
if (selectedServerObj.variables && selectedServerObj.variables[variable]) {
353353
// variable is defined in server
@@ -388,16 +388,9 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
388388
return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
389389
}
390390

391-
function getVariableTemplateNames(str) {
392-
const results = [];
393-
const re = /{([^}]{1,29})}/g;
394-
let text;
395-
396-
// eslint-disable-next-line no-cond-assign
397-
while ((text = re.exec(str))) {
398-
results.push(text[1]);
399-
}
400-
return results;
391+
function extractServerVariableNames(serverURL) {
392+
const match = serverURL.matchAll(/\{([^{}]+)}|([^{}]+)/g);
393+
return Array.from(match, ([, variable]) => variable).filter(Boolean);
401394
}
402395

403396
// Compose the baseUrl ( scheme + host + basePath )

0 commit comments

Comments
 (0)