Skip to content

Commit a6e6549

Browse files
authoredMar 1, 2024
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 (#8960)
1 parent 244e343 commit a6e6549

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎spec/vulnerabilities.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,28 @@ describe('Vulnerabilities', () => {
459459
});
460460
});
461461
});
462+
463+
describe('Postgres regex sanitizater', () => {
464+
it('sanitizes the regex correctly to prevent Injection', async () => {
465+
const user = new Parse.User();
466+
user.set('username', 'username');
467+
user.set('password', 'password');
468+
user.set('email', 'email@example.com');
469+
await user.signUp();
470+
471+
const response = await request({
472+
method: 'GET',
473+
url:
474+
"http://localhost:8378/1/classes/_User?where[username][$regex]=A'B'%3BSELECT+PG_SLEEP(3)%3B--",
475+
headers: {
476+
'Content-Type': 'application/json',
477+
'X-Parse-Application-Id': 'test',
478+
'X-Parse-REST-API-Key': 'rest',
479+
},
480+
});
481+
482+
expect(response.status).toBe(200);
483+
expect(response.data.results).toEqual(jasmine.any(Array));
484+
expect(response.data.results.length).toBe(0);
485+
});
486+
});

‎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)