mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Move safe-chain package to packages/safe-chain
This commit is contained in:
parent
fc9a9ca129
commit
7673d32912
68 changed files with 85 additions and 52 deletions
56
packages/safe-chain/src/scanning/audit/index.js
Normal file
56
packages/safe-chain/src/scanning/audit/index.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import {
|
||||
MALWARE_STATUS_MALWARE,
|
||||
openMalwareDatabase,
|
||||
} from "../malwareDatabase.js";
|
||||
|
||||
export async function auditChanges(changes) {
|
||||
const allowedChanges = [];
|
||||
const disallowedChanges = [];
|
||||
|
||||
var malwarePackages = await getPackagesWithMalware(
|
||||
changes.filter(
|
||||
(change) => change.type === "add" || change.type === "change"
|
||||
)
|
||||
);
|
||||
|
||||
for (const change of changes) {
|
||||
const malwarePackage = malwarePackages.find(
|
||||
(pkg) => pkg.name === change.name && pkg.version === change.version
|
||||
);
|
||||
|
||||
if (malwarePackage) {
|
||||
disallowedChanges.push({ ...change, reason: malwarePackage.status });
|
||||
} else {
|
||||
allowedChanges.push(change);
|
||||
}
|
||||
}
|
||||
|
||||
const auditResults = {
|
||||
allowedChanges,
|
||||
disallowedChanges,
|
||||
isAllowed: disallowedChanges.length === 0,
|
||||
};
|
||||
|
||||
return auditResults;
|
||||
}
|
||||
|
||||
async function getPackagesWithMalware(changes) {
|
||||
if (changes.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const malwareDb = await openMalwareDatabase();
|
||||
let allVulnerablePackages = [];
|
||||
|
||||
for (const change of changes) {
|
||||
if (malwareDb.isMalware(change.name, change.version)) {
|
||||
allVulnerablePackages.push({
|
||||
name: change.name,
|
||||
version: change.version,
|
||||
status: MALWARE_STATUS_MALWARE,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return allVulnerablePackages;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue