Skip to content

Commit 83cdc89

Browse files
authored
fix: session object properties can be updated by foreign user; this fixes a security vulnerability in which a foreign user can write to the session object of another user if the session object ID is known; the fix prevents writing to foreign session objects ([GHSA-6w4q-23cf-j9jp](GHSA-6w4q-23cf-j9jp)) [skip release] (#8181)
1 parent f0db4ca commit 83cdc89

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spec/ParseSession.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,32 @@ describe('Parse.Session', () => {
135135
fail(err);
136136
});
137137
});
138+
139+
it('cannot edit session with known ID', async () => {
140+
const request = require('../lib/request');
141+
await setupTestUsers();
142+
const [first, second] = await new Parse.Query(Parse.Session).find({ useMasterKey: true });
143+
const headers = {
144+
'X-Parse-Application-Id': 'test',
145+
'X-Parse-Rest-API-Key': 'rest',
146+
'X-Parse-Session-Token': second.get('sessionToken'),
147+
'Content-Type': 'application/json',
148+
};
149+
const firstUser = first.get('user').id;
150+
const secondUser = second.get('user').id;
151+
const e = await request({
152+
method: 'PUT',
153+
headers,
154+
url: `http://localhost:8378/1/sessions/${first.id}`,
155+
body: JSON.stringify({
156+
foo: 'bar',
157+
user: { __type: 'Pointer', className: '_User', objectId: secondUser },
158+
}),
159+
}).catch(e => e.data);
160+
expect(e.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
161+
expect(e.error).toBe('Object not found.');
162+
await Parse.Object.fetchAll([first, second], { useMasterKey: true });
163+
expect(first.get('user').id).toBe(firstUser);
164+
expect(second.get('user').id).toBe(secondUser);
165+
});
138166
});

src/RestWrite.js

+14
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,20 @@ RestWrite.prototype.handleSession = function () {
10181018
} else if (this.data.sessionToken) {
10191019
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME);
10201020
}
1021+
if (!this.auth.isMaster) {
1022+
this.query = {
1023+
$and: [
1024+
this.query,
1025+
{
1026+
user: {
1027+
__type: 'Pointer',
1028+
className: '_User',
1029+
objectId: this.auth.user.id,
1030+
},
1031+
},
1032+
],
1033+
};
1034+
}
10211035
}
10221036

10231037
if (!this.query && !this.auth.isMaster) {

0 commit comments

Comments
 (0)