Skip to content

Commit

Permalink
CM-35360 - Use policy display name as title of SAST detections (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX authored May 15, 2024
1 parent 3743e2f commit efee551
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const getScanTypeDisplayName = (scanType: string): string => {

export const DIAGNOSTIC_CODE_SEPARATOR = '::';

export const REQUIRED_CLI_VERSION = '1.9.4';
export const REQUIRED_CLI_VERSION = '1.9.5';

export const CLI_GITHUB = {
OWNER: 'cycodehq',
Expand Down
2 changes: 1 addition & 1 deletion src/panels/violation/renderer/sast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const renderDetection = detection => {
const severityFirstLetter = detection.severity[0].toUpperCase();
ge('severity-icon').src = severityIcons[severityFirstLetter];
ge('title').innerText = detection.message;
ge('title').innerText = detection.detection_details.policy_display_name;
const cwes = detection.detection_details.cwe.join(', ');
if (cwes) {
Expand Down
2 changes: 1 addition & 1 deletion src/panels/violation/violation-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const _enrichIacDetectionForRender = (detection: IacDetection): IacDetection =>
};

const _enrichSastDetectionForRender = (detection: SastDetection): SastDetection => {
if (detection.message) {
if (detection.detection_details.description) {
detection.detection_details.description =
_MARKDOWN_CONVERTER.makeHtml(detection.detection_details.description);
}
Expand Down
4 changes: 4 additions & 0 deletions src/providers/code-actions/commonActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export const createOpenViolationCardAction = (
const detection = scanResultsService.getDetectionById(diagnosticCode.uniqueDetectionId);

let message = detection?.message;
if (detection?.type === 'SAST') {
message = detection?.detection_details.policy_display_name;
}

if (message && message.length > 50) {
message = message.slice(0, 50) + '...';
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/tree-view/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ const _getIacValueItem = (detection: IacDetection): ValueItem => {
};

const _getSastValueItem = (detection: SastDetection): ValueItem => {
const {message, detection_details, severity} = detection;
const {detection_details, severity} = detection;
const {line_in_file, file_path} = detection_details;

const valueItem: TreeViewDisplayedData = {
title: `line ${line_in_file}: ${message}`,
title: `line ${line_in_file}: ${detection_details.policy_display_name}`,
severityFirstLetter: mapSeverityToFirstLetter(severity),
lineNumber: line_in_file,
detection: detection,
Expand Down
2 changes: 1 addition & 1 deletion src/services/scanners/IacScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const detectionsToDiagnostics = async (
const document = await vscode.workspace.openTextDocument(documentUri);

let message = `Severity: ${detection.severity}\n`;
message += `Description: ${detection.message}\n`;
message += `Rule: ${detection.message}\n`;

message += `IaC Provider: ${detection.detection_details.infra_provider}\n`;

Expand Down
5 changes: 1 addition & 4 deletions src/services/scanners/SastScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ const normalizeSastDetections = (result: { detections?: SastDetection[] }): Sast
if (!detection_details.file_path.startsWith('/')) {
detection_details.file_path = '/' + detection_details.file_path;
}

detection_details.description = detection.message;
detection.message = detection.message.slice(0, 50) + '...';
}

return result.detections;
Expand Down Expand Up @@ -158,7 +155,7 @@ const detectionsToDiagnostics = async (
const document = await vscode.workspace.openTextDocument(documentUri);

let message = `Severity: ${detection.severity}\n`;
message += `Description: ${detection.message}\n`;
message += `Rule: ${detection.detection_details.policy_display_name}\n`;
message += `In file: ${detection.detection_details.file_name}\n`;

const diagnostic = new vscode.Diagnostic(
Expand Down
11 changes: 10 additions & 1 deletion src/types/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SecretDetection = {
description?: string;
remediation_guidelines?: string;
custom_remediation_guidelines?: string;
policy_display_name: string;
};
};

Expand Down Expand Up @@ -45,6 +46,10 @@ export type ScaDetection = {
vulnerable_requirements: string;
first_patched_version: string;
};
description?: string;
remediation_guidelines?: string;
custom_remediation_guidelines?: string;
policy_display_name: string;
};
};

Expand All @@ -66,6 +71,7 @@ export type IacDetection = {
description?: string;
remediation_guidelines?: string;
custom_remediation_guidelines?: string;
policy_display_name: string;
};
};

Expand All @@ -77,7 +83,6 @@ export type SastDetection = {
severity: string;
detection_details: {
external_scanner_id: string;
description: string; // doesn't come from CLI yet
line_in_file: number;
start_position: number;
end_position: number;
Expand All @@ -87,6 +92,10 @@ export type SastDetection = {
owasp: string[];
category: string;
languages: string[];
description?: string;
remediation_guidelines?: string;
custom_remediation_guidelines?: string;
policy_display_name: string;
};
};

Expand Down

0 comments on commit efee551

Please sign in to comment.