Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[web] Don't block page load on malformed feature flags

Manav Rathic120cfc74b81
diff --git a/web/packages/new/photos/services/settings.ts b/web/packages/new/photos/services/settings.ts
index 06aa63c3d2..76e24d66f2 100644
--- a/web/packages/new/photos/services/settings.ts
+++ b/web/packages/new/photos/services/settings.ts
@@ -128,6 +128,8 @@ export const logoutSettings = () => {
*/
export const syncSettings = async () => {
const jsonString = await fetchFeatureFlags().then((res) => res.text());
+ // Do a parse as a sanity check before saving the string contents.
+ FeatureFlags.parse(JSON.parse(jsonString));
saveRemoteFeatureFlagsJSONString(jsonString);
syncSettingsSnapshotWithLocalStorage();
};
@@ -138,7 +140,12 @@ const saveRemoteFeatureFlagsJSONString = (s: string) =>
const savedRemoteFeatureFlags = () => {
const s = localStorage.getItem("remoteFeatureFlags");
if (!s) return undefined;
- return FeatureFlags.parse(JSON.parse(s));
+ try {
+ return FeatureFlags.parse(JSON.parse(s));
+ } catch (e) {
+ log.warn("Ignoring unparseable saved remoteFeatureFlags", e);
+ return undefined;
+ }
};
const FeatureFlags = z.object({