pinia-plugin-persistedstate icon indicating copy to clipboard operation
pinia-plugin-persistedstate copied to clipboard

🔥 hydrate store using paths

Open conor-odro opened this issue 1 year ago • 3 comments

Description

Currently the plugin will restore the entire contents of localStorage or sessionStorage back into the Vue store, regardless of which paths are whitelisted by the paths array. This can result in stale data from a user being put back into the store which should no longer be persisted (i.e in the past the field was included in the paths array but has since been removed) or potentially allows a bad actor to inject their own data into the Vue store (granted this is slightly contrived but could be an issue for some applications).

Linked Issues

#268

Additional context

This has been tested (via Jest) and also locally in my own app. Unsure if we want this to be turned on/off via a config option?

conor-odro avatar Jan 15 '24 16:01 conor-odro

I would see this as a breaking change because it changes the rehydration behaviour, but i totally see it as a feature/something needed. Maybe keep it being a flag as opt-in to not break the current behaviour, it could eventually become thedefault behaviour on upcoming major version

prazdevs avatar Jan 18 '24 14:01 prazdevs

I would see this as a breaking change because it changes the rehydration behaviour, but i totally see it as a feature/something needed. Maybe keep it being a flag as opt-in to not break the current behaviour, it could eventually become thedefault behaviour on upcoming major version

That's completely fair, appreciate the feedback @prazdevs - I'll update the PR to include an opt-in flag

conor-odro avatar Jan 22 '24 12:01 conor-odro

Hey @prazdevs apologies for the delay in getting around to this - I've updated the PR with a new pathHydration opt-in flag

conor-odro avatar Jan 31 '24 10:01 conor-odro