Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

other/Refactor results.ts not done #1019

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1,019 changes: 523 additions & 496 deletions media/view.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/commands/webViewCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path = require("path");
import * as vscode from "vscode";
import { getCodebashingLink } from "../codebashing/codebashing";
import { Logs } from "../models/logs";
import { AstResult } from "../models/results";
import { AstResult } from "../models/astResults/AstResult";
import { getLearnMore } from "../sast/learnMore";
import { getChanges, triageSubmit } from "../utils/triage";
import { applyScaFix } from "../sca/scaFix";
Expand Down
216 changes: 216 additions & 0 deletions src/models/astResults/AstResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import * as vscode from "vscode";
import * as path from "path";
import {
StateLevel,
SeverityLevel,
constants,
} from "../../utils/common/constants";

// import { KicsAstResult } from "./KicsAstResult";
// import { SastAstResult } from "./SastAstResult";
// import { ScaAstResult } from "./ScaAstResult";
// import { ScsAstResult } from "./ScsAstResult";
// import { ScaRealtimeAstResult } from "./ScaRealtimeAstResult";

export abstract class AstResult {
queryId: string;
queryName: string;
language: string;
cweId: string;
fileName: string;
typeLabel: string;
type: string;
label: string;
id: string;
similarityId: string;
status: string;
state: string;
severity: string;
created: string;
firstFoundAt: string;
foundAt: string;
firstScanId: string;
description: string;
descriptionHTML: string;
comments: any;
declare data: any;
declare vulnerabilityDetails: any;

constructor(result: any) {
this.type = result.type; // common
this.label = result.data.queryName // vi // common
? result.data.queryName
: result.id
? result.id
: result.vulnerabilityDetails.cveName;
this.id = result.id; // vi // common
this.similarityId = result.similarityId; // vi // common
this.status = result.status; // vi // common
this.state = result.state || "";
this.severity = result.severity; // common
this.created = result.created; // common
this.firstFoundAt = result.firstFoundAt; // common
this.foundAt = result.foundAt; // common
this.firstScanId = result.firstScanId; // common
this.description = result.description; // common
this.descriptionHTML = result.descriptionHTML; // common
this.comments = result.comments; // common;
this.data = result.data; // common
this.vulnerabilityDetails = result.vulnerabilityDetails; // common
this.queryId = result.data?.queryId;
this.typeLabel = this.determineTypeLabel(result);
}

getKicsValues(): string {
return ""; // Default implementation for non-Kics types
}

public getqueryId(): string {
return this.queryId;
}
static checkType(result: any): string {
return result.type;
}

setSeverity(severity: string): void {
this.severity = severity;
}

// Common setter for state
setState(state: string): void {
this.state = state;
}

// Abstract methods to be implemented by subclasses
abstract getResultHash(): string;
determineTypeLabel(result: any): string | undefined {
if (result.label) {
return result.label;
}
if (result.type === "scs-secret-detection") {
return "Secret Detection";
}
return undefined;
}
abstract getHtmlDetails(cxPath: vscode.Uri): string;
abstract getTitle(): string;

// handleFileNameAndLine(result: any): void; // Abstract method

// Common utility to shorten filenames
getShortFilename(filename: string): string {
return filename.length > 50 ? "..." + filename.slice(-50) : filename;
}

getIcon() {
switch (this.severity) {
case constants.criticalSeverity:
return path.join("media", "icons", "critical_untoggle.svg");
case constants.highSeverity:
return path.join("media", "icons", "high_untoggle.svg");
case constants.mediumSeverity:
return path.join("media", "icons", "medium_untoggle.svg");
case constants.infoSeverity:
return path.join("media", "icons", "info_untoggle.svg");
case constants.lowSeverity:
return path.join("media", "icons", "low_untoggle.svg");
}
return "";
}

getGptIcon() {
return path.join("media", "icons", "gpt.png");
}

getCxIcon() {
return path.join("media", "icon.png");
}

getCxScaAtackVector() {
return path.join("media", "icons", "attackVector.png");
}

getCxScaComplexity() {
return path.join("media", "icons", "complexity.png");
}

getCxAuthentication() {
return path.join("media", "icons", "authentication.png");
}

getCxConfidentiality() {
return path.join("media", "icons", "confidentiality.png");
}

getCxIntegrity() {
return path.join("media", "icons", "integrity.png");
}

getCxAvailability() {
return path.join("media", "icons", "availability.png");
}

getCxUpgrade() {
return path.join("media", "icons", "upgrade.png");
}

getCxUrl() {
return path.join("media", "icons", "url.png");
}

getTreeIcon() {
return {
light: path.join(__filename, "..", "..", this.getIcon()),
dark: path.join(__filename, "..", "..", this.getIcon()),
};
}

getSeverityCode() {
switch (this.severity) {
case constants.criticalSeverity:
return vscode.DiagnosticSeverity.Error;
case constants.highSeverity:
return vscode.DiagnosticSeverity.Error;
case constants.mediumSeverity:
return vscode.DiagnosticSeverity.Warning;
case constants.infoSeverity:
return vscode.DiagnosticSeverity.Information;
}
return vscode.DiagnosticSeverity.Information;
}

getSeverity() {
switch (this.severity) {
case constants.criticalSeverity:
return SeverityLevel.critical;
case constants.highSeverity:
return SeverityLevel.high;
case constants.mediumSeverity:
return SeverityLevel.medium;
case constants.infoSeverity:
return SeverityLevel.info;
case constants.lowSeverity:
return SeverityLevel.low;
}
return SeverityLevel.empty;
}

getState() {
switch (this.state) {
case "NOT_EXPLOITABLE":
return StateLevel.notExploitable;
case "PROPOSED_NOT_EXPLOITABLE":
return StateLevel.proposed;
case "CONFIRMED":
return StateLevel.confirmed;
case "TO_VERIFY":
return StateLevel.toVerify;
case "URGENT":
return StateLevel.urgent;
case "NOT_IGNORED":
return StateLevel.notIgnored;
case "IGNORED":
return StateLevel.ignored;
}
}
}
22 changes: 22 additions & 0 deletions src/models/astResults/AstResultFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AstResult } from "./AstResult";
import { SastAstResult } from "./SastAstResult";
import { KicsAstResult } from "./KicsAstResult";
import { ScaAstResult } from "./ScaAstResult";
import { ScsAstResult } from "./ScsAstResult";
import { constants } from "../../utils/common/constants";

export class AstResultFactory {
static createInstance(input: any): AstResult {
switch (input.type) {
case constants.sast:
return new SastAstResult(input);
case constants.kics:
return new KicsAstResult(input);
case constants.sca:
return new ScaAstResult(input);
case constants.scsSecretDetection:
return new ScsAstResult(input);
default:
}
}
}
105 changes: 105 additions & 0 deletions src/models/astResults/KicsAstResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { AstResult } from "./AstResult";
import { KicsNode, KicsSummary } from "../nodes/KicsNode";
import * as vscode from "vscode";

export class KicsAstResult extends AstResult {
kicsNode: KicsNode;
typeLabel = "";
cweId = "";
queryId = "";

constructor(result: any) {
super(result);
this.kicsNode = new KicsNode(
result.id,
result.description,
result.severity,
result.data.queryId,
result.data.queryName,
result.data.group,
result.data
);
this.typeLabel = result.label;
this.handleFileNameAndLine(result);
this.queryId = result.data.queryId;
}

handleFileNameAndLine(result: any): void {
this.cweId = result.vulnerabilityDetails?.cweId;
}
setSeverity(severity: string) {
if (this.kicsNode) {
this.kicsNode.severity = severity;
}
}

getResultHash(): string {
if (this.kicsNode) {
return this.kicsNode.id;
}
}

getHtmlDetails(cxPath: vscode.Uri): string {
if (this.kicsNode) {
return this.kicsDetails();
}
}

private kicsDetails() {
let html = "";
html += `
<tr>
<td>
<div class="tooltip">
1.
<span class="tooltiptext">
${this.kicsNode?.data.filename}
</span>
</div>
<a href="#"
class="ast-node"
data-filename="${this.kicsNode?.data.filename}"
data-line="${this.kicsNode?.data.line}"
data-column="${0}"
data-fullName="${this.kicsNode?.data.filename}"
data-length="${1}"
>
${this.getShortFilename(this.kicsNode?.data.filename)} [${
this.kicsNode?.data.line
}:${0}]
</a>
</td>
</tr>
`;
return html;
}

getKicsValues() {
let r = "";
if (this.kicsNode?.data) {
this.kicsNode.data.value
? (r += `
<p>
<b>Value:</b> ${this.kicsNode?.data.value}
</p>
`)
: (r += "");
this.kicsNode.data.expectedValue
? (r += `
<p>
<b>Expected Value:</b> ${this.kicsNode?.data.expectedValue}
</p>
`)
: (r += "");
}
return r;
}

getTitle(): string {
let r = "";
if (this.kicsNode) {
r = `<h3 class="subtitle">Location</h3><hr class="division"/>`;
}
return r;
}
}
Loading