Skip to content

Commit cbefe77

Browse files
authored
fix: Improve PostgreSQL injection detection; fixes security vulnerability [GHSA-6927-3vr9-fxf2](GHSA-6927-3vr9-fxf2) which affects Parse Server deployments using a Postgres database (#8961)
1 parent 9c85e63 commit cbefe77

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Diff for: spec/vulnerabilities.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,28 @@ describe('Vulnerabilities', () => {
433433
});
434434
});
435435
});
436+
437+
describe('Postgres regex sanitizater', () => {
438+
it('sanitizes the regex correctly to prevent Injection', async () => {
439+
const user = new Parse.User();
440+
user.set('username', 'username');
441+
user.set('password', 'password');
442+
user.set('email', '[email protected]');
443+
await user.signUp();
444+
445+
const response = await request({
446+
method: 'GET',
447+
url:
448+
"http://localhost:8378/1/classes/_User?where[username][$regex]=A'B'%3BSELECT+PG_SLEEP(3)%3B--",
449+
headers: {
450+
'Content-Type': 'application/json',
451+
'X-Parse-Application-Id': 'test',
452+
'X-Parse-REST-API-Key': 'rest',
453+
},
454+
});
455+
456+
expect(response.status).toBe(200);
457+
expect(response.data.results).toEqual(jasmine.any(Array));
458+
expect(response.data.results.length).toBe(0);
459+
});
460+
});

Diff for: src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ function literalizeRegexPart(s: string) {
26562656
.replace(/([^\\])(\\Q)/, '$1')
26572657
.replace(/^\\E/, '')
26582658
.replace(/^\\Q/, '')
2659-
.replace(/([^'])'/, `$1''`)
2659+
.replace(/([^'])'/g, `$1''`)
26602660
.replace(/^'([^'])/, `''$1`);
26612661
}
26622662

0 commit comments

Comments
 (0)