fix: authentication adapter app ID validation may be circumvented; this fixes a vulnerability that affects configurations which allow users to authenticate using the Parse Server authentication adapter for *Facebook* or *Spotify* and where the server-side authentication adapter configuration appIds is set as a string (e.g. abc) instead of an array of strings (e.g. ["abc"]) ([GHSA-r657-33vp-gp22](https://github.com/parse-community/parse-server/security/advisories/GHSA-r657-33vp-gp22)) [skip release] (#8188)
This commit is contained in:
@@ -441,6 +441,29 @@ describe('AuthenticationProviders', function () {
|
|||||||
expect(httpsRequest.get.calls.first().args[0].includes('appsecret_proof')).toBe(true);
|
expect(httpsRequest.get.calls.first().args[0].includes('appsecret_proof')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw error when Facebook request appId is wrong data type', async () => {
|
||||||
|
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');
|
||||||
|
spyOn(httpsRequest, 'get').and.callFake(() => {
|
||||||
|
return Promise.resolve({ id: 'a' });
|
||||||
|
});
|
||||||
|
const options = {
|
||||||
|
facebook: {
|
||||||
|
appIds: 'abcd',
|
||||||
|
appSecret: 'secret_sauce',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const authData = {
|
||||||
|
access_token: 'badtoken',
|
||||||
|
};
|
||||||
|
const { adapter, appIds, providerOptions } = authenticationLoader.loadAuthAdapter(
|
||||||
|
'facebook',
|
||||||
|
options
|
||||||
|
);
|
||||||
|
await expectAsync(adapter.validateAppId(appIds, authData, providerOptions)).toBeRejectedWith(
|
||||||
|
new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'appIds must be an array.')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle Facebook appSecret for validating auth data', async () => {
|
it('should handle Facebook appSecret for validating auth data', async () => {
|
||||||
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');
|
const httpsRequest = require('../lib/Adapters/Auth/httpsRequest');
|
||||||
spyOn(httpsRequest, 'get').and.callFake(() => {
|
spyOn(httpsRequest, 'get').and.callFake(() => {
|
||||||
|
|||||||
@@ -32,22 +32,23 @@ function validateGraphToken(authData, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateGraphAppId(appIds, authData, options) {
|
async function validateGraphAppId(appIds, authData, options) {
|
||||||
var access_token = authData.access_token;
|
var access_token = authData.access_token;
|
||||||
if (process.env.TESTING && access_token === 'test') {
|
if (process.env.TESTING && access_token === 'test') {
|
||||||
return Promise.resolve();
|
return;
|
||||||
|
}
|
||||||
|
if (!Array.isArray(appIds)) {
|
||||||
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'appIds must be an array.');
|
||||||
}
|
}
|
||||||
if (!appIds.length) {
|
if (!appIds.length) {
|
||||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is not configured.');
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is not configured.');
|
||||||
}
|
}
|
||||||
return graphRequest(
|
const data = await graphRequest(
|
||||||
'app?access_token=' + access_token + getAppSecretPath(authData, options)
|
`app?access_token=${access_token}${getAppSecretPath(authData, options)}`
|
||||||
).then(data => {
|
);
|
||||||
if (data && appIds.indexOf(data.id) != -1) {
|
if (!data || !appIds.includes(data.id)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Facebook auth is invalid for this user.');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFacebookKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
|
const getFacebookKeyByKeyId = async (keyId, cacheMaxEntries, cacheMaxAge) => {
|
||||||
|
|||||||
@@ -13,17 +13,18 @@ function validateAuthData(authData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a promise that fulfills if this app id is valid.
|
// Returns a promise that fulfills if this app id is valid.
|
||||||
function validateAppId(appIds, authData) {
|
async function validateAppId(appIds, authData) {
|
||||||
var access_token = authData.access_token;
|
const access_token = authData.access_token;
|
||||||
|
if (!Array.isArray(appIds)) {
|
||||||
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'appIds must be an array.');
|
||||||
|
}
|
||||||
if (!appIds.length) {
|
if (!appIds.length) {
|
||||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Spotify auth is not configured.');
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Spotify auth is not configured.');
|
||||||
}
|
}
|
||||||
return request('me', access_token).then(data => {
|
const data = await request('me', access_token);
|
||||||
if (data && appIds.indexOf(data.id) != -1) {
|
if (!data || !appIds.includes(data.id)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Spotify auth is invalid for this user.');
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Spotify auth is invalid for this user.');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A promisey wrapper for Spotify API requests.
|
// A promisey wrapper for Spotify API requests.
|
||||||
|
|||||||
Reference in New Issue
Block a user