summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-05 20:35:04 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-05 20:57:52 -0400
commitec110fa1b7299a947ea3eabc0e2c46094408c8ba (patch)
tree93acc29fcb6541e24bdfe6af1f64ef54b272f669
parent1c767711bb553fa828596f95f8ed9e91a3e13b5d (diff)
Add some validation to options loading
-rw-r--r--ext/bg/js/options.js21
1 files changed, 17 insertions, 4 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index d903250e..976f8e55 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -323,10 +323,23 @@ function optionsVersion(options) {
function optionsLoad() {
return new Promise((resolve, reject) => {
- chrome.storage.local.get(null, store => resolve(store.options));
+ chrome.storage.local.get(['options'], store => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(error);
+ } else {
+ resolve(store.options);
+ }
+ });
}).then(optionsStr => {
- return optionsStr ? JSON.parse(optionsStr) : {};
- }).catch(error => {
+ if (typeof optionsStr === 'string') {
+ const options = JSON.parse(optionsStr);
+ if (typeof options === 'object' && options !== null && !Array.isArray(options)) {
+ return options;
+ }
+ }
+ return {};
+ }).catch(() => {
return {};
}).then(options => {
return optionsVersion(options);
@@ -334,7 +347,7 @@ function optionsLoad() {
}
function optionsSave(options) {
- return new Promise((resolve, reject) => {
+ return new Promise((resolve) => {
chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
}).then(() => {
apiOptionsSet(options);