Skip to content

Commit ead12bd

Browse files
authored
fix: Session field guard bypass via falsy values for ACL and user fields (#10382)
1 parent b587767 commit ead12bd

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

spec/ParseSession.spec.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,91 @@ describe('Parse.Session', () => {
546546
expect(updateRes.data.code).toBe(Parse.Error.INVALID_KEY_NAME);
547547
});
548548

549+
it('should reject null ACL when updating a session via PUT', async () => {
550+
const user = await Parse.User.signUp('sessionupdatenull5', 'password');
551+
const sessionToken = user.getSessionToken();
552+
553+
const sessionRes = await request({
554+
method: 'GET',
555+
url: 'http://localhost:8378/1/sessions/me',
556+
headers: {
557+
'X-Parse-Application-Id': 'test',
558+
'X-Parse-REST-API-Key': 'rest',
559+
'X-Parse-Session-Token': sessionToken,
560+
},
561+
});
562+
const sessionId = sessionRes.data.objectId;
563+
564+
const updateRes = await request({
565+
method: 'PUT',
566+
url: `http://localhost:8378/1/sessions/${sessionId}`,
567+
headers: {
568+
'X-Parse-Application-Id': 'test',
569+
'X-Parse-REST-API-Key': 'rest',
570+
'X-Parse-Session-Token': sessionToken,
571+
'Content-Type': 'application/json',
572+
},
573+
body: {
574+
ACL: null,
575+
},
576+
}).catch(e => e);
577+
578+
expect(updateRes.data.code).toBe(Parse.Error.INVALID_KEY_NAME);
579+
});
580+
581+
it('should reject null ACL when creating a session via POST', async () => {
582+
const user = await Parse.User.signUp('sessioncreatenull1', 'password');
583+
const sessionToken = user.getSessionToken();
584+
585+
const createRes = await request({
586+
method: 'POST',
587+
url: 'http://localhost:8378/1/sessions',
588+
headers: {
589+
'X-Parse-Application-Id': 'test',
590+
'X-Parse-REST-API-Key': 'rest',
591+
'X-Parse-Session-Token': sessionToken,
592+
'Content-Type': 'application/json',
593+
},
594+
body: {
595+
ACL: null,
596+
},
597+
}).catch(e => e);
598+
599+
expect(createRes.data.code).toBe(Parse.Error.INVALID_KEY_NAME);
600+
});
601+
602+
it('should reject null user when updating a session via PUT', async () => {
603+
const user = await Parse.User.signUp('sessionupdatenull6', 'password');
604+
const sessionToken = user.getSessionToken();
605+
606+
const sessionRes = await request({
607+
method: 'GET',
608+
url: 'http://localhost:8378/1/sessions/me',
609+
headers: {
610+
'X-Parse-Application-Id': 'test',
611+
'X-Parse-REST-API-Key': 'rest',
612+
'X-Parse-Session-Token': sessionToken,
613+
},
614+
});
615+
const sessionId = sessionRes.data.objectId;
616+
617+
const updateRes = await request({
618+
method: 'PUT',
619+
url: `http://localhost:8378/1/sessions/${sessionId}`,
620+
headers: {
621+
'X-Parse-Application-Id': 'test',
622+
'X-Parse-REST-API-Key': 'rest',
623+
'X-Parse-Session-Token': sessionToken,
624+
'Content-Type': 'application/json',
625+
},
626+
body: {
627+
user: null,
628+
},
629+
}).catch(e => e);
630+
631+
expect(updateRes.data.code).toBe(Parse.Error.INVALID_KEY_NAME);
632+
});
633+
549634
describe('PUT /sessions/me', () => {
550635
it('should return error with invalid session token', async () => {
551636
const response = await request({

src/RestWrite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,12 @@ RestWrite.prototype.handleSession = function () {
12281228
}
12291229

12301230
// TODO: Verify proper error to throw
1231-
if (this.data.ACL) {
1231+
if ('ACL' in this.data) {
12321232
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Cannot set ' + 'ACL on a Session.');
12331233
}
12341234

12351235
if (this.query) {
1236-
if (this.data.user && !this.auth.isMaster && this.data.user.objectId != this.auth.user.id) {
1236+
if ('user' in this.data && !this.auth.isMaster && this.data.user?.objectId !== this.auth.user.id) {
12371237
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: user');
12381238
} else if ('installationId' in this.data) {
12391239
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'Invalid key name: installationId');

0 commit comments

Comments
 (0)