Skip to content

Commit ea03140

Browse files
Merge pull request #92 from contentstack/fix/dx-1852-sre-issue-regex
dx | 1852 | sre issue
2 parents 1b053cd + f759462 commit ea03140

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib/query.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ export class Query extends BaseQuery {
3030

3131
// Validate if input matches any of the safe, pre-approved patterns
3232
private isValidRegexPattern(input: string): boolean {
33+
const validRegex = /^[a-zA-Z0-9|^$.*+?()[\]{}\\-]+$/; // Allow only safe regex characters
34+
if (!validRegex.test(input)) {
35+
return false;
36+
}
3337
try {
34-
new RegExp(input); // Try to create a new RegExp object
35-
return true; // No error means it's a valid regex
38+
new RegExp(input);
39+
return true;
3640
} catch (e) {
37-
return false; // Error means it's not a valid regex
41+
return false;
3842
}
3943
}
4044

0 commit comments

Comments
 (0)