Skip to content

Commit 5d1f3b0

Browse files
committed
fix: Use $regex key presence check instead of truthiness to handle empty-string patterns
1 parent 6938fb4 commit 5d1f3b0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/RequestComplexity.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,17 @@ describe('request complexity', () => {
657657
).toBeResolved();
658658
});
659659

660+
it('should reject empty-string $regex when allowRegex is false', async () => {
661+
const where = { username: { $regex: '' } };
662+
await expectAsync(
663+
rest.find(config, auth.nobody(config), '_User', where)
664+
).toBeRejectedWith(
665+
jasmine.objectContaining({
666+
message: '$regex operator is not allowed',
667+
})
668+
);
669+
});
670+
660671
it('should allow $regex with maintenance key when allowRegex is false', async () => {
661672
const where = { username: { $regex: 'test' } };
662673
await expectAsync(

src/Controllers/DatabaseController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const validateQuery = (
159159
}
160160

161161
Object.keys(query).forEach(key => {
162-
if (query && query[key] && query[key].$regex) {
162+
if (query && query[key] && query[key].$regex !== undefined) {
163163
if (!isMaster && rc && rc.allowRegex === false) {
164164
throw new Parse.Error(Parse.Error.INVALID_QUERY, '$regex operator is not allowed');
165165
}

0 commit comments

Comments
 (0)