mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Only allow wildcards for scoped packages (@scope/*)
This commit is contained in:
parent
2d609066c8
commit
20cc62d6e1
3 changed files with 4 additions and 30 deletions
|
|
@ -196,7 +196,7 @@ export function getHasSuppressedVersions() {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
function matchesExclusionPattern(packageName, pattern) {
|
||||
if (pattern.endsWith("*")) {
|
||||
if (pattern.endsWith("/*")) {
|
||||
return packageName.startsWith(pattern.slice(0, -1));
|
||||
}
|
||||
return packageName === pattern;
|
||||
|
|
|
|||
|
|
@ -509,32 +509,6 @@ describe("npmInterceptor minimum package age", async () => {
|
|||
assert.ok(Object.keys(modifiedJson.versions).includes("2.0.0"));
|
||||
});
|
||||
|
||||
it("Should exclude packages matching wildcard pattern prefix-*", async () => {
|
||||
minimumPackageAgeSettings = 5;
|
||||
skipMinimumPackageAgeSetting = false;
|
||||
minimumPackageAgeExclusionsSetting = ["react-*"];
|
||||
|
||||
const packageUrl = "https://registry.npmjs.org/react-dom";
|
||||
|
||||
const originalBody = JSON.stringify({
|
||||
name: "react-dom",
|
||||
["dist-tags"]: { latest: "18.0.0" },
|
||||
versions: { ["17.0.0"]: {}, ["18.0.0"]: {} },
|
||||
time: {
|
||||
created: getDate(-365 * 24),
|
||||
modified: getDate(-1),
|
||||
["17.0.0"]: getDate(-100),
|
||||
["18.0.0"]: getDate(-1), // Would normally be filtered
|
||||
},
|
||||
});
|
||||
|
||||
const modifiedBody = await runModifyNpmInfoRequest(packageUrl, originalBody);
|
||||
const modifiedJson = JSON.parse(modifiedBody);
|
||||
|
||||
// All versions should remain since react-* matches react-dom
|
||||
assert.equal(Object.keys(modifiedJson.versions).length, 2);
|
||||
});
|
||||
|
||||
it("Should NOT exclude packages that don't match wildcard pattern", async () => {
|
||||
minimumPackageAgeSettings = 5;
|
||||
skipMinimumPackageAgeSetting = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue