
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
persistore
Advanced tools
The Persistore
is primary designed to use a very easy API (get
, set
, remove
)
to store any string with fallback strategies that apply automatically to each
client browser. So if localStorage
is not accessible it falls back internally to cookies
.
And if this would be neither possible, it will just use local variables, which is as
persistent as possible in this situation without any backend support.
TypeScript
support includednpm i --save persistore
import { Persistore } from 'persistore';
Persistore.set('my-key', '{"here": "comes your data"}');
console.log(Persistore.get('my-key')); // prints: '{"here": "comes your data"}'
Persistore.remove('my-key');
console.log(Persistore.get('my-key')); // prints: undefined
Same is possible for persistence restricted to session lifetime:
import { Persistore } from 'persistore';
Persistore.session.set('my-key', '{"here": "comes your data"}');
console.log(Persistore.session.get('my-key')); // prints: '{"here": "comes your data"}'
Persistore.session.remove('my-key');
console.log(Persistore.session.get('my-key')); // prints: undefined
And additional features to handle cookies is also included:
import { CookieUtil } from 'persistore';
CookieUtil.set('my-key', '{"here": "comes your data"}');
console.log(CookieUtil.get('my-key')); // prints: '{"here": "comes your data"}'
CookieUtil.remove('my-key');
console.log(CookieUtil.get('my-key')); // prints: undefined
// access all cookies
CookieUtil.getAll().forEach(([name, value]) => console.log(name, value)); // prints all cookies
HINT: Since most browsers have a strict cookie size limitation, the Persistore will throw an error if it would try to insert a cookie which exceeds the maximum size of 4093 bytes (iOS Safari reserves 3 additional bytes). The actual browser behaviour in that case would be to silently do nothing, what can lead to strange behaviour of your application. Therefore you should catch the possibly thrown error if you want to store large strings to handle this special case. Another useful information for you might be: localStorage and sessionStorage are not available on some browsers. The most common cases are iOS-Safari-Private-Mode users, where the Persistore will always fallback to cookies.
It is also possible to make some configuration. For now it is only the key prefixing and an opt-out for secure cookies (useful for localhost development).
import { Persistore } from 'persistore';
Persistore.config({ prefix: 'myApp.', insecure: IS_LOCALHOST });
FAQs
Automatically applying persistent storage with fallback strategies
We found that persistore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.