Skip to content

Commit bd67f56

Browse files
authored
Change fix with copilot prompt for the case of applicable CVEs (#540)
* better prompt for cves
1 parent d8508cd commit bd67f56

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/commands/commandManager.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,28 @@ export class CommandManager implements ExtensionComponent {
153153
private doVscodeAutofix(node: vscode.TreeItem) {
154154
if (node instanceof CodeIssueTreeNode) {
155155
try {
156-
const prompt: string = `Here is a vulnerability details page. Please suggest a fix for the vulnerability: ${JSON.stringify(
157-
node.getDetailsPage()
158-
)}`;
156+
let issue_details: any = node.getDetailsPage();
157+
let prompt: string = '';
158+
if (issue_details['cve'] && issue_details['component'] && issue_details['version'] && issue_details['infectedVersion']) {
159+
// cve
160+
const base_propmpt: string = `The code contains ${issue_details['component']} (version: ${issue_details['version']}) as dependency with a known vulnerability ${issue_details['cve']['id']}.\nThe provided package name is in lower case, please use after correcting the upper/lower case letters. Propose the following fixes:`;
161+
const upgrade_fix: string = `1) Upgrade the version of the dependency by consulting get_curation_package_status tool to check whether an alternative version will be acceptable The tool MUST return Approved status in order to proceed. Recommended to start from these versions: ${issue_details['infectedVersion']} . Make sure to use the correct format of the package name according to package manager naming convention`;
162+
prompt = `${base_propmpt}\n${upgrade_fix}`;
163+
if (
164+
issue_details['cve']['applicableData'] &&
165+
issue_details['extendedInformation'] &&
166+
issue_details['extendedInformation']['remediation']
167+
) {
168+
const remediation: string = `2) Remediate the use of the dependency in the source code according to the following instructions: \`${
169+
issue_details['extendedInformation']['remediation']
170+
}\`. Use the following vulnerable API use location evidence in the source code (only fix the source code related to the following location!): \`${JSON.stringify(
171+
issue_details['cve']['applicableData']['evidence']
172+
)}\``;
173+
prompt = `${prompt}\n${remediation}`;
174+
}
175+
} else {
176+
prompt = `Here is a vulnerability details page. Please suggest a fix for the vulnerability: ${JSON.stringify(issue_details)}`;
177+
}
159178
vscode.commands.executeCommand('workbench.action.chat.open', prompt);
160179
} catch (error) {
161180
this._logManager.logMessage(`Error calling copilot: ${error}`, 'ERR');

src/main/utils/scanUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export class ScanUtils {
287287
* @returns hashed data in Hex
288288
*/
289289
static Hash(algorithm: string, data: crypto.BinaryLike): string {
290+
// jfrog-ignore
290291
return crypto
291292
.createHash(algorithm)
292293
.update(data)

0 commit comments

Comments
 (0)