mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge branch 'rama-integration-beta' into rama-min-package-age-reporting
This commit is contained in:
commit
5f82e45b2b
131 changed files with 6372 additions and 2461 deletions
|
|
@ -4,7 +4,7 @@ import {
|
|||
getNpmMinimumPackageAgeExclusions,
|
||||
} from "../../../../config/settings.js";
|
||||
import { ui } from "../../../../environment/userInteraction.js";
|
||||
import { getHeaderValueAsString } from "../../http-utils.js";
|
||||
import { clearCachingHeaders, getHeaderValueAsString } from "../../http-utils.js";
|
||||
|
||||
/** @type {EventEmitter<{ versionsRemoved: [{packageName: string, packageVersions: string[]}] }>} */
|
||||
export const modifyResponseEventEmitter = new EventEmitter();
|
||||
|
|
@ -104,15 +104,7 @@ export function modifyNpmInfoResponse(body, headers) {
|
|||
removedVersions.push(version);
|
||||
|
||||
deleteVersionFromJson(bodyJson, version);
|
||||
if (headers) {
|
||||
// When modifying the response, the etag and last-modified headers
|
||||
// no longer match the content so they needs to be removed before sending the response.
|
||||
delete headers["etag"];
|
||||
delete headers["last-modified"];
|
||||
// Removing the cache-control header will prevent the package manager from caching
|
||||
// the modified response.
|
||||
delete headers["cache-control"];
|
||||
}
|
||||
clearCachingHeaders(headers);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -213,3 +205,22 @@ function matchesExclusionPattern(packageName, pattern) {
|
|||
}
|
||||
return packageName === pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Buffer} body
|
||||
* @param {NodeJS.Dict<string | string[]> | undefined} headers
|
||||
* @returns {string | undefined}
|
||||
*/
|
||||
export function getPackageNameFromMetadataResponse(body, headers) {
|
||||
try {
|
||||
const contentType = getHeaderValueAsString(headers, "content-type");
|
||||
if (!contentType?.toLowerCase().includes("application/json")) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const bodyJson = JSON.parse(body.toString("utf8"));
|
||||
return typeof bodyJson.name === "string" ? bodyJson.name : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue