Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vsm-dictionary-cacher
Advanced tools
Wrapper around a VSM-dictionary, that manages a cache of string-match results
vsm-dictionary-cacher
is a wrapper around VSM-dictionaries,
to speed up requests for string-matches in three ways:
It stores results from requests to getMatchesForString()
in a cache.
These results are returned for subsequent requests
that use same search-string & options, instead of re-running the query.
This helps e.g.
vsm-autocomplete
avoid making duplicate requests to an online dictionary server.
It creates a more responsive autocomplete when the user types, and then backspaces.
It also prevents launching a second query to a server, that has the same
search-string & options as an ongoing query.
Instead, it makes the second query wait, and when the first one's result
comes in, it shares that result immediately with the second one.
This helps e.g.
vsm-autocomplete
avoid making duplicate requests
when a user types, and backspaces or re-types quickly.
And it can remember for which strings there were no matches.
Then for subsequently queried strings, that start with such a 'no matches'
string, it can immediately return 'no matches' too.
This helps e.g.
vsm-autocomplete
avoid making unnecessary requests
for search-strings for which a substring already returned no matches.
This package provides a factory function that accepts any VsmDictionary class,
and returns a subclass of it,
which simply adds an extra layer of caching functionality
to getMatchesForString()
.
Install like:
npm install vsm-dictionary-cacher --save-prod
Then use like:
const Dictionary = require('vsm-dictionary-local'); // ...or any other VsmDictionary implementation.
const cacher = require('vsm-dictionary-cacher');
const CachedDictionary = cacher(Dictionary); // This makes a new subclass.
var dict = new CachedDictionary(); // This makes an instance.
// This will query the Dictionary as normal, bypassing the cache.
dict.getMatchesForString('abc', {filter: {dictID: 'Foo'}}, (err, res) => {
// This will get the result from the cache (instead of re-running the query).
dict.getMatchesForString('abc', {filter: {dictID: 'Foo'}}, (err, res) => {
});
// These will *not* get their result from the cache.
dict.getMatchesForString('abc', {filter: {dictID: 'BAR'}}, (err, res) => {});
dict.getMatchesForString('QQQ', {filter: {dictID: 'Foo'}}, (err, res) => {});
});
You can give an options object as second argument to the factory function, with these optional properties:
maxItems
: {Number}:maxAge
: {Number}:predictEmpties
: {Boolean}:true
, then it keeps a list of strings (per options-object) for which
getMatchesForString()
returned no results (i.e.: { items: [] }
).{ items: [] }
for 'abc'.
Default is true
.
maxItems
and maxAge
do not apply.Specify options like:
const CachedDictionary = cacher(Dictionary, { maxItems: 100, maxAge: 180000 });
The wrapper adds an extra function to the VsmDictionary subclass:
clearCache()
:predictEmpties
.When maxAge
is not 0 (i.e. when cache items can expire), then:
maxAge
ms has passed
since any last cache-access; i.e. all items' memory gets released then.It can happen that getMatchesForString()
gets called a second time with the
same arguments, but that results from the first call haven't arrived yet
(i.e. the first query hasn't called its callback with a result yet).
When a query on the original storage fails, then no item will be added
to the cache, and no attempt to re-query will be made by vsm-dictionary-cacher
.
This means that for concurrent requests (as described above),
the same error will be returned almost-immediately by all those requests.
FAQs
Wrapper around a VSM-dictionary, that manages a cache of string-match results
The npm package vsm-dictionary-cacher receives a total of 0 weekly downloads. As such, vsm-dictionary-cacher popularity was classified as not popular.
We found that vsm-dictionary-cacher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.