From cd5ee4837c53ecf42e6868c324934f21955d0bc7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 1 Sep 2020 00:02:01 -0500 Subject: [PATCH] Check that soapbox.json is really an object before importing, fixes #376 --- app/soapbox/actions/soapbox.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index eedd1787f..c072a0bbc 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -40,8 +40,9 @@ export function fetchSoapboxConfig() { export function fetchSoapboxJson() { return (dispatch, getState) => { - api(getState).get('/instance/soapbox.json').then(response => { - dispatch(importSoapboxConfig(response.data)); + api(getState).get('/instance/soapbox.json').then(({ data }) => { + if (!isObject(data)) throw 'soapbox.json failed'; + dispatch(importSoapboxConfig(data)); }).catch(error => { dispatch(soapboxConfigFail(error)); }); @@ -56,12 +57,14 @@ export function importSoapboxConfig(soapboxConfig) { } export function soapboxConfigFail(error) { - if (!error.response) { - console.error('Unable to obtain soapbox configuration: ' + error); - } return { type: SOAPBOX_CONFIG_REQUEST_FAIL, error, skipAlert: true, }; } + +// https://stackoverflow.com/a/46663081 +function isObject(o) { + return o instanceof Object && o.constructor === Object; +}