Skip to content

Commit 040e334

Browse files
committed
Fixed SARIF format to allow display in Code Scanning
1 parent a229b4d commit 040e334

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/malwareMatcher.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export interface SarifResult {
172172
properties?: Record<string, unknown>;
173173
locations: SarifResultLocation[];
174174
}
175-
export interface SarifRun { tool: { driver: { name: string; informationUri?: string; rules: SarifRule[] } }; results: SarifResult[]; }
175+
export interface SarifRun { tool: { driver: { name: string; version: string; informationUri?: string; rules: SarifRule[] } }; results: SarifResult[]; }
176176
export interface SarifLog { version: string; $schema: string; runs: SarifRun[]; }
177177

178178
export function buildSarifPerRepo(matches: MalwareMatch[], advisories: MalwareAdvisoryNode[]): Map<string, SarifLog> {
@@ -212,18 +212,30 @@ export function buildSarifPerRepo(matches: MalwareMatch[], advisories: MalwareAd
212212
ruleIndex: ruleIds.indexOf(m.advisoryGhsaId),
213213
level: "error",
214214
message: { text: `Malware advisory ${m.advisoryGhsaId} matched package ${m.purl}${m.vulnerableVersionRange ? ` in range ${m.vulnerableVersionRange}` : ""}` },
215-
properties: {
216-
purl: m.purl,
217-
ecosystem: m.ecosystem,
218-
version: m.version,
219-
vulnerableVersionRange: m.vulnerableVersionRange,
220-
},
221-
locations: [{ physicalLocation: { artifactLocation: { uri: m.purl } } }]
215+
// properties: {
216+
// purl: m.purl,
217+
// ecosystem: m.ecosystem,
218+
// version: m.version,
219+
// vulnerableVersionRange: m.vulnerableVersionRange,
220+
// },
221+
locations: [{ physicalLocation: { artifactLocation: { uri: `file:///${m.purl}` } } }]
222222
}));
223223
const sarif: SarifLog = {
224224
version: "2.1.0",
225225
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
226-
runs: [{ tool: { driver: { name: our_tool_name, informationUri: our_tool_url, rules } }, results }]
226+
runs: [
227+
{
228+
tool: {
229+
driver: {
230+
name: our_tool_name,
231+
version: "0.1.0",
232+
informationUri: our_tool_url,
233+
rules: rules
234+
}
235+
},
236+
results: results
237+
}
238+
]
227239
};
228240
sarifMap.set(repo, sarif);
229241
}

0 commit comments

Comments
 (0)