Skip to content

Commit

Permalink
fix(api): create regexp alias to fix snyk redos false positive
Browse files Browse the repository at this point in the history
This change fixes the false positive snyk warning about a possible Redos regex attack. Synk does not correctly detect the settings reference, because the related regexes themselves are safe (checked via devina.io/redos-checker)
  • Loading branch information
lubber-de authored Aug 30, 2023
1 parent f2aad7e commit bc1849c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
: $.extend({}, $.fn.api.settings),

// internal aliases
regExp = settings.regExp,
namespace = settings.namespace,
metadata = settings.metadata,
selector = settings.selector,
Expand Down Expand Up @@ -360,8 +361,8 @@
optionalVariables
;
if (url) {
requiredVariables = url.match(settings.regExp.required);
optionalVariables = url.match(settings.regExp.optional);
requiredVariables = url.match(regExp.required);
optionalVariables = url.match(regExp.optional);
urlData = urlData || settings.urlData;
if (requiredVariables) {
module.debug('Looking for required URL variables', requiredVariables);
Expand Down Expand Up @@ -458,7 +459,7 @@
});
});
$.each(formArray, function (i, el) {
if (!settings.regExp.validate.test(el.name)) {
if (!regExp.validate.test(el.name)) {
return;
}
var
Expand All @@ -469,7 +470,7 @@
|| (String(floatValue) === el.value
? floatValue
: (el.value === 'false' ? false : el.value)),
nameKeys = el.name.match(settings.regExp.key) || [],
nameKeys = el.name.match(regExp.key) || [],
pushKey = el.name.replace(/\[]$/, '')
;
if (!(pushKey in pushes)) {
Expand All @@ -489,9 +490,9 @@

if (k === '' && !Array.isArray(value)) { // foo[]
value = build([], pushes[pushKey]++, value);
} else if (settings.regExp.fixed.test(k)) { // foo[n]
} else if (regExp.fixed.test(k)) { // foo[n]
value = build([], k, value);
} else if (settings.regExp.named.test(k)) { // foo; foo[bar]
} else if (regExp.named.test(k)) { // foo; foo[bar]
value = build({}, k, value);
}
}
Expand Down

0 comments on commit bc1849c

Please sign in to comment.