Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/panels/violation/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,32 @@ export default (detectionType: ScanType) => `
element.className = element.className.replace(' hidden', '');
}
};

const getCweCveLink = cweCve => {
if (!cweCve || typeof cweCve !== 'string') {
return undefined;
}

if (cweCve.startsWith('GHSA')) {
return 'https://github.com/advisories/' + cweCve;
} else if (cweCve.startsWith('CWE')) {
const cweNumber = parseInt(cweCve.split('-')[1]);
return 'https://cwe.mitre.org/data/definitions/' + cweNumber;
} else if (cweCve.startsWith('CVE')) {
return 'https://cve.mitre.org/cgi-bin/cvename.cgi?name=' + cweCve;
} else {
return undefined;
}
};

const renderCweCveLink = cweCve => {
const link = getCweCveLink(cweCve);
if (link) {
return \`<a href="\${link}" target="_blank" rel="noopener noreferrer">\${cweCve}</a>\`;
} else {
return cweCve;
}
};
</script>
${detectionType === ScanType.Sca ? scaRenderer : ''}
${detectionType === ScanType.Secrets ? secretRenderer : ''}
Expand Down
5 changes: 3 additions & 2 deletions src/panels/violation/renderer/sast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const renderDetection = detection => {

ge('title').innerText = detection.detection_details.policy_display_name;

const cwes = detection.detection_details.cwe.join(', ');
const renderedCwes = detection.detection_details.cwe.map(cwe => renderCweCveLink(cwe));
const cwes = renderedCwes.join(', ');
if (cwes) {
ge('short-details').innerText = [detection.severity, cwes].join(' | ');
ge('short-details').innerHTML = [detection.severity, cwes].join(' | ');
} else {
ge('short-details').innerText = detection.severity;
}
Expand Down
8 changes: 4 additions & 4 deletions src/panels/violation/renderer/sca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const renderDetection = detection => {
// if package vulnerability
ge('title').innerText = detection.detection_details.alert.summary;

const cwe = detection.detection_details.vulnerability_id;
const cwe = renderCweCveLink(detection.detection_details.vulnerability_id);
const severity = detection.severity;
ge('short-details').innerText = severity + ' | ' + cwe;
ge('short-details').innerHTML = severity + ' | ' + cwe;

showElement('first-patched-version');
ge('first-patched-version-value').innerText = detection.detection_details.alert.first_patched_version;

showElement('summary');
ge('summary-text').innerHTML = detection.detection_details.alert.description;
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ export const initContext = (context: vscode.ExtensionContext) => {
};

export const resetState = () => {
updateWorkspaceState(VscodeStates.AuthenticatingInProgress, false);

updateWorkspaceState(VscodeStates.SecretsScanInProgress, false);
updateWorkspaceState(VscodeStates.ScaScanInProgress, false);
updateWorkspaceState(VscodeStates.IacScanInProgress, false);
updateWorkspaceState(VscodeStates.SastScanInProgress, false);

updateWorkspaceState(VscodeStates.NotificationIsOpen, false);
updateWorkspaceState(VscodeStates.NotificationWasShown, false);

updateWorkspaceState(VscodeStates.HasDetections, false);
};

export const getContext = (): vscode.ExtensionContext => {
Expand Down