Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
reliable-get
Advanced tools
A circuit breaker and cached wrapper for GET requests (enables reliable external service interaction).
Reliable HTTP get wrapper (with cache and serve stale on error), best wrapped around things you dont trust very much.
If reliable-get makes a request that times out or errors, its callback will receive both an error object and a previously cached response, if one is present in cache. You can then decide whether to ignore the error and use the cached response, or not.
var ReliableGet = require('reliable-get');
var config = {
cache:{
engine:'memorycache'
}
};
var rg = new ReliableGet(config);
rg.on('log', function(level, message, data) {
// Wire up to your favourite logger
});
rg.on('stat', function(type, key, value) {
// Wire up to your favourite stats library (e.g. statsd)
});
rg.get({url:'http://www.google.com'}, function(err, response) {
console.log(response.content);
});
When you create an instance of reliable-get you need to specify the cache configuration. This then applies across all requests.
var config = {
cache:{
engine:'redis',
url:'redis://localhost:6379?db=0'
}
};
You can also pass a property requestOpts
to pass options to be used in request. Example:
var config = {
cache: {
engine: 'redis',
url: 'redis://localhost:6379?db=0'
},
requestOpts: {
forever: true,
followRedirect: false
}
}
Property | Description | Example / Default | Required |
---|---|---|---|
cache.engine | Cache to use, redis/memcached/memorycache/nocache | nocache | No |
cache.engine.url | URL to redis | localhost:6379 | No |
cache.compress | Use snappy compression | false | No |
cache.namespace | Prefix for redis keys | '' | No |
cache.hosts | Array of host:port combinations for memcached | [] | No |
cache.autodiscover | Use Elasticache Auto Discovery | false | No |
When making a get request, you need to provide a basic options object:
rg.get({url:'http://www.google.com'}, function(err, response) {
console.log(response.content);
});
Property | Description | Example / Default | Required |
---|---|---|---|
url | Service to get | http://my-service.tes.co.uk | Yes |
timeout | Timeout for service | 5000 | No |
cacheKey | Key to store cached value against | my-service_tes_co_uk | No |
tags | List of tags (surrogate keys) | [] | No |
cacheTTL | TTL of cached value in ms | 1 minute (60000) | No |
explicitNoCache | Do not cache under any circumstances | false | No |
headers | Headers to send with request | No | |
tracer | Unique value to pass with request | No | |
type | Type of request, used for statsd and logging | No | |
statsdKey | Key that statsd events will be posted to | No | |
eventHandler | Object (see below) for logging and stats | No |
Example from a Compoxure backend request:
var options = {
url: targetUrl,
cacheKey: targetCacheKey,
cacheTTL: targetCacheTTL,
timeout: utils.timeToMillis(backend.timeout || DEFAULT_LOW_TIMEOUT),
headers: backendHeaders,
tracer: req.tracer,
statsdKey: 'backend_' + utils.urlToCacheKey(host)
};
From a compoxure fragment request:
var options = {
url: url,
timeout: timeout,
cacheKey: cacheKey,
cacheTTL: cacheTTL,
explicitNoCache: explicitNoCache,
headers: optionsHeaders,
tracer: req.tracer,
statsdKey: statsdKey
};
The options
object is fully passed down to the request.
The library will decorate with response with some useful keys that you may need to use, there are following:
stale
- is added to response when the request to origin failed and a stale cached version is returned insteadcached
- is true
if there was a cache hit, otherwise false
realTiming
- show the time it took for the response to be returnedSome store (memorycache/redis) supports assigning one or more tags to a certain resource. They are used only if the resource is cached, to purge all cache entries with the same tag.
The cache object accept any config value accepted by redis. It also takes:
<host>:<port>
combinartions in an arrayThe "config.requestOpts" contains the default configuration passed to "request".
FAQs
A circuit breaker and cached wrapper for GET requests (enables reliable external service interaction).
The npm package reliable-get receives a total of 20 weekly downloads. As such, reliable-get popularity was classified as not popular.
We found that reliable-get 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.