mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Parse npm registry's timestamps.
This commit is contained in:
parent
ea75179143
commit
900bf8e6ea
1 changed files with 3 additions and 9 deletions
|
|
@ -67,7 +67,7 @@ export function modifyNpmInfoResponse(body, headers) {
|
||||||
|
|
||||||
const cutOff = new Date(
|
const cutOff = new Date(
|
||||||
new Date().getTime() - getMinimumPackageAgeHours() * 3600 * 1000
|
new Date().getTime() - getMinimumPackageAgeHours() * 3600 * 1000
|
||||||
).toISOString();
|
);
|
||||||
|
|
||||||
const hasLatestTag = !!bodyJson["dist-tags"]["latest"];
|
const hasLatestTag = !!bodyJson["dist-tags"]["latest"];
|
||||||
|
|
||||||
|
|
@ -79,13 +79,8 @@ export function modifyNpmInfoResponse(body, headers) {
|
||||||
.filter((x) => x.version !== "created" && x.version !== "modified");
|
.filter((x) => x.version !== "created" && x.version !== "modified");
|
||||||
|
|
||||||
for (const { version, timestamp } of versions) {
|
for (const { version, timestamp } of versions) {
|
||||||
if (version === "created" || version === "modified") {
|
const timestampValue = new Date(timestamp);
|
||||||
continue;
|
if (timestampValue > cutOff) {
|
||||||
}
|
|
||||||
|
|
||||||
// Timestamps are compared as strings.
|
|
||||||
// This can be done because they are formatted in ISO8601, which is sortable.
|
|
||||||
if (timestamp > cutOff) {
|
|
||||||
deleteVersionFromJson(bodyJson, version);
|
deleteVersionFromJson(bodyJson, version);
|
||||||
if (headers) {
|
if (headers) {
|
||||||
// When modifying the response, the etag and last-modified headers
|
// When modifying the response, the etag and last-modified headers
|
||||||
|
|
@ -93,7 +88,6 @@ export function modifyNpmInfoResponse(body, headers) {
|
||||||
delete headers["etag"];
|
delete headers["etag"];
|
||||||
delete headers["last-modified"];
|
delete headers["last-modified"];
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue