mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 03:20:23 +01:00
Add additional validation for persisted state metadata (#20462)
Additional validation has been added for persisted state metadata. Beforehand we just checked that the state itself wasn't falsy. Now we ensure that the metadata is an object with a valid version as well.
This commit is contained in:
parent
915bf2ae88
commit
dc7ebe979e
@ -13,6 +13,7 @@ import debounce from 'debounce-stream';
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
import { storeAsStream } from '@metamask/obs-store';
|
import { storeAsStream } from '@metamask/obs-store';
|
||||||
|
import { isObject } from '@metamask/utils';
|
||||||
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
||||||
import { ApprovalType } from '@metamask/controller-utils';
|
import { ApprovalType } from '@metamask/controller-utils';
|
||||||
///: END:ONLY_INCLUDE_IN
|
///: END:ONLY_INCLUDE_IN
|
||||||
@ -411,6 +412,19 @@ export async function loadStateFromPersistence() {
|
|||||||
versionedData = await migrator.migrateData(versionedData);
|
versionedData = await migrator.migrateData(versionedData);
|
||||||
if (!versionedData) {
|
if (!versionedData) {
|
||||||
throw new Error('MetaMask - migrator returned undefined');
|
throw new Error('MetaMask - migrator returned undefined');
|
||||||
|
} else if (!isObject(versionedData.meta)) {
|
||||||
|
throw new Error(
|
||||||
|
`MetaMask - migrator metadata has invalid type '${typeof versionedData.meta}'`,
|
||||||
|
);
|
||||||
|
} else if (typeof versionedData.meta.version !== 'number') {
|
||||||
|
throw new Error(
|
||||||
|
`MetaMask - migrator metadata version has invalid type '${typeof versionedData
|
||||||
|
.meta.version}'`,
|
||||||
|
);
|
||||||
|
} else if (!isObject(versionedData.data)) {
|
||||||
|
throw new Error(
|
||||||
|
`MetaMask - migrator data has invalid type '${typeof versionedData.data}'`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// this initializes the meta/version data as a class variable to be used for future writes
|
// this initializes the meta/version data as a class variable to be used for future writes
|
||||||
localStore.setMetadata(versionedData.meta);
|
localStore.setMetadata(versionedData.meta);
|
||||||
|
Loading…
Reference in New Issue
Block a user