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.
Calculate when HTTP responses expire from the cache headers
expired
accepts HTTP headers as an argument and will return information on when the resource will expire. Cache-Control
and Expires
headers are supported, if both exist Cache-Control
takes priority (Why?).
npm install --save expired
const expired = require('expired');
const headers = `
Age: 0
Cache-Control: public, max-age=300
Content-Encoding: gzip
Content-Type: application/json;charset=utf-8
Date: Fri, 23 Dec 2016 05:50:31 GMT
Last-Modified: Fri, 23 Dec 2016 05:23:23 GMT`;
expired(headers);
// false
expired.in(headers);
// 500000
expired.on(headers);
// Date('2016-12-23T05:55:31.000Z')
delay(600000).then(() => {
expired(headers);
// true
expired.in(headers);
// -100000
expired.on(headers);
// Date('2016-12-23T05:55:31.000Z')
});
Many HTTP modules will parse response headers into an object for you. expired
will also accept headers in this format:
const expired = require('expired');
const headers = {
'age': '0',
'cache-control': 'public, max-age=300',
'content-encoding': 'gzip',
'content-type': 'application/json;charset=utf-8',
'date': 'Fri, 23 Dec 2016 05:50:31 GMT',
'last-modified': 'Fri, 23 Dec 2016 05:23:23 GMT'
};
expired(headers);
// false
You can make the functions pure by passing in a JavaScript Date
object to compare to instead of depending on new Date()
. This isn't necessary for expired.on
as it doesn't compare dates and is already pure.
The following are all pure functions:
const headers = `...`;
const date = new Date();
expired(headers, date);
expired.in(headers, date);
expired.on(headers);
Returns a boolean relating to whether the resource has expired or not. true
means it's expired, false
means it's fresh.
Returns the amount of milliseconds from the current date until the resource will expire. If the resource has already expired it will return a negative integer.
Returns a JavaScript Date
object for the date the resource will expire.
MIT © Luke Childs
FAQs
Calculate when HTTP responses expire from the cache headers
The npm package expired receives a total of 10 weekly downloads. As such, expired popularity was classified as not popular.
We found that expired 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
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.