Skip to content

Commit 109bc9a

Browse files
flovilmartdrew-gross
authored andcommitted
handling matching api.parse.com when calling upgradeToRevocableSession without a sessionToken (parse-community#2721)
1 parent 90e9994 commit 109bc9a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spec/RevocableSessionsUpgrade.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,24 @@ describe_only_db('mongo')('revocable sessions', () => {
8989
done();
9090
});
9191
});
92+
93+
it('should not crash without session token #2720', done => {
94+
rp.post({
95+
url: Parse.serverURL+'/upgradeToRevocableSession',
96+
headers: {
97+
'X-Parse-Application-Id': Parse.applicationId,
98+
'X-Parse-Rest-API-Key': 'rest'
99+
},
100+
json: true
101+
}).then((res) => {
102+
fail('should not be able to upgrade a bad token');
103+
}, (response) => {
104+
expect(response.statusCode).toBe(404);
105+
expect(response.error).not.toBeUndefined();
106+
expect(response.error.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
107+
expect(response.error.error).toEqual('invalid session');
108+
}).then(() => {
109+
done();
110+
});
111+
});
92112
})

src/Routers/SessionsRouter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export class SessionsRouter extends ClassesRouter {
5454
const config = req.config;
5555
const masterAuth = Auth.master(config)
5656
const user = req.auth.user;
57+
// Issue #2720
58+
// Calling without a session token would result in a not found user
59+
if (!user) {
60+
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'invalid session');
61+
}
5762
const expiresAt = config.generateSessionExpiresAt();
5863
const sessionData = {
5964
sessionToken: 'r:' + newToken(),

0 commit comments

Comments
 (0)