@@ -13129,4 +13129,146 @@ describe('Vulnerabilities', () => {
1312913129 expect(object.get('settings')).toEqual({ ...stored().settings, a: true });
1313013130 });
1313113131 });
13132+
13133+ describe('(GHSA-r66f-3q22-grc4) Google Play Games auth adapter accepts a player id that the access token does not belong to', () => {
13134+ const tokenUrl = 'https://oauth2.googleapis.com/token';
13135+ const playersUrl = 'https://www.googleapis.com/games/v1/players';
13136+ const victimPlayerId = 'victim-player';
13137+ const attackerPlayerId = 'attacker-player';
13138+ const unlinkedPlayerId = 'unlinked-player';
13139+ const headers = {
13140+ 'Content-Type': 'application/json',
13141+ 'X-Parse-Application-Id': 'test',
13142+ 'X-Parse-REST-API-Key': 'rest',
13143+ };
13144+
13145+ // Stands in for Google: the credential belongs to `owner`; `players/me` returns the token
13146+ // owner and `players/<id>` returns the requested player, as Google documents.
13147+ const mockGoogle = owner =>
13148+ mockFetch([
13149+ {
13150+ url: tokenUrl,
13151+ method: 'POST',
13152+ response: { ok: true, json: () => Promise.resolve({ access_token: 'google-token' }) },
13153+ },
13154+ ...['me', victimPlayerId, attackerPlayerId, unlinkedPlayerId].map(id => ({
13155+ url: `${playersUrl}/${id}`,
13156+ method: 'GET',
13157+ response: {
13158+ ok: true,
13159+ json: () => Promise.resolve({ playerId: id === 'me' ? owner : id }),
13160+ },
13161+ })),
13162+ ]);
13163+
13164+ const logInWith = authData =>
13165+ request({
13166+ method: 'POST',
13167+ url: 'http://localhost:8378/1/users',
13168+ headers,
13169+ body: JSON.stringify({ authData: { gpgames: authData } }),
13170+ }).catch(e => e);
13171+
13172+ const linkWith = (user, authData) =>
13173+ request({
13174+ method: 'PUT',
13175+ url: `http://localhost:8378/1/users/${user.id}`,
13176+ headers: { ...headers, 'X-Parse-Session-Token': user.getSessionToken() },
13177+ body: JSON.stringify({ authData: { gpgames: authData } }),
13178+ }).catch(e => e);
13179+
13180+ // Reads the row directly so the adapter's afterFind cannot mask what was persisted.
13181+ const storedProviderData = async objectId => {
13182+ const [row] = await Config.get('test').database.find('_User', { objectId });
13183+ return row.authData?.gpgames;
13184+ };
13185+
13186+ let victim;
13187+
13188+ beforeEach(async () => {
13189+ await reconfigureServer({
13190+ auth: { gpgames: { clientId: 'clientId', clientSecret: 'clientSecret' } },
13191+ });
13192+ mockGoogle(victimPlayerId);
13193+ victim = await Parse.User.logInWith('gpgames', {
13194+ authData: { code: 'victim-code', id: victimPlayerId },
13195+ });
13196+ });
13197+
13198+ it('rejects an authorization code with the id of another player', async () => {
13199+ mockGoogle(attackerPlayerId);
13200+
13201+ const response = await logInWith({ code: 'attacker-code', id: victimPlayerId });
13202+
13203+ const body = JSON.parse(response.text);
13204+ expect(body.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
13205+ expect(body.sessionToken).toBeUndefined();
13206+ });
13207+
13208+ it('rejects an access token with the id of another player when insecure auth is enabled', async () => {
13209+ await reconfigureServer({ auth: { gpgames: { enableInsecureAuth: true } } });
13210+ mockGoogle(attackerPlayerId);
13211+
13212+ const response = await logInWith({ access_token: 'attacker-token', id: victimPlayerId });
13213+
13214+ const body = JSON.parse(response.text);
13215+ expect(body.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
13216+ expect(body.sessionToken).toBeUndefined();
13217+ });
13218+
13219+ it('logs in the player who owns the access token when insecure auth is enabled', async () => {
13220+ await reconfigureServer({ auth: { gpgames: { enableInsecureAuth: true } } });
13221+ mockGoogle(victimPlayerId);
13222+
13223+ const response = await logInWith({ access_token: 'victim-token', id: victimPlayerId });
13224+
13225+ expect(response.status).toBe(200);
13226+ expect(response.data.objectId).toBe(victim.id);
13227+ });
13228+
13229+ it('rejects linking the id of another player to an account', async () => {
13230+ const attacker = new Parse.User();
13231+ await attacker.signUp({ username: 'attacker', password: 'attacker-password' });
13232+ mockGoogle(attackerPlayerId);
13233+
13234+ const response = await linkWith(attacker, { code: 'attacker-code', id: unlinkedPlayerId });
13235+
13236+ const body = JSON.parse(response.text);
13237+ expect(body.code).toBe(Parse.Error.SESSION_MISSING);
13238+ expect(global.fetch.calls.allArgs().map(([url]) => url)).toEqual([
13239+ tokenUrl,
13240+ `${playersUrl}/me`,
13241+ ]);
13242+ expect(await storedProviderData(attacker.id)).toBeUndefined();
13243+ });
13244+
13245+ it('links the player who owns the authorization code to an account', async () => {
13246+ const user = new Parse.User();
13247+ await user.signUp({ username: 'player', password: 'player-password' });
13248+ mockGoogle(unlinkedPlayerId);
13249+
13250+ const response = await linkWith(user, { code: 'player-code', id: unlinkedPlayerId });
13251+
13252+ expect(response.status).toBe(200);
13253+ expect((await storedProviderData(user.id)).id).toBe(unlinkedPlayerId);
13254+ });
13255+
13256+ it('logs in the player who owns the authorization code', async () => {
13257+ mockGoogle(victimPlayerId);
13258+
13259+ const response = await logInWith({ code: 'victim-code', id: victimPlayerId });
13260+
13261+ expect(response.status).toBe(200);
13262+ expect(response.data.objectId).toBe(victim.id);
13263+ });
13264+
13265+ it('resolves the player from the authorization code when no id is supplied', async () => {
13266+ mockGoogle(victimPlayerId);
13267+
13268+ const response = await logInWith({ code: 'victim-code' });
13269+
13270+ expect(response.status).toBe(200);
13271+ expect(response.data.objectId).toBe(victim.id);
13272+ });
13273+ });
1313213274});
0 commit comments