Skip to content

Commit 7ca9ed0

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)) (#8183)
1 parent e29f7c0 commit 7ca9ed0

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spec/ParseSession.spec.js

Lines changed: 28 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,20 @@ RestWrite.prototype.handleSession = function () {
985985
} else if (this.data.sessionToken) {
986986
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME);
987987
}
988+
if (!this.auth.isMaster) {
989+
this.query = {
990+
$and: [
991+
this.query,
992+
{
993+
user: {
994+
__type: 'Pointer',
995+
className: '_User',
996+
objectId: this.auth.user.id,
997+
},
998+
},
999+
],
1000+
};
1001+
}
9881002
}
9891003

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

0 commit comments

Comments
 (0)