diff --git a/src/core/plugins/json-schema-2020-12-samples/fn/core/random.js b/src/core/plugins/json-schema-2020-12-samples/fn/core/random.js index 6a707639cba..fdc26b41970 100644 --- a/src/core/plugins/json-schema-2020-12-samples/fn/core/random.js +++ b/src/core/plugins/json-schema-2020-12-samples/fn/core/random.js @@ -16,7 +16,18 @@ export const bytes = (length) => randomBytes(length) export const randexp = (pattern) => { try { - const randexpInstance = new RandExp(pattern) + /** + * Applying maximum value (100) to numbers from regex patterns to avoid ReDoS: + * 1. {x} + * 2. {x,} + * 3. {,y} + * 4. {x,y} + */ + const patternSanitizer = + /(?<=(? { try { - const randexp = new RandExp(pattern) - return randexp.gen() + /** + * Applying maximum value (100) to numbers from regex patterns to avoid ReDoS: + * 1. {x} + * 2. {x,} + * 3. {,y} + * 4. {x,y} + */ + const patternSanitizer = + /(?<=(?