Skip to content

Commit 7acf7e8

Browse files
Fix XSS, Encoding, and Error Handling Issues (AST-129962, AST-129966, AST-129969) (#1353)
1 parent 0314e5b commit 7acf7e8

File tree

5 files changed

+141
-55
lines changed

5 files changed

+141
-55
lines changed

README.md

Lines changed: 87 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<a href="https://github.com/Checkmarx/ast-vscode-extension">
1717
<img src="https://raw.githubusercontent.com/Checkmarx/ci-cd-integrations/main/.images/cx_x_icon.png" alt="Logo" width="80" height="80" />
1818
</a>
19-
<h3 align="center">VS Code Extension</h3>
19+
<h3 align="center">Checkmarx VS Code Extension</h3>
20+
<h3 align="center">Also supported for: Cursor, Windsurf and Kiro</h3>
2021
<p align="center">
2122
<a href="https://checkmarx.com/resource/documents/en/34965-68742-checkmarx-one-vs-code-extension--plugin-.html"><strong>Explore the docs »</strong></a>
2223
<br />
@@ -28,10 +29,10 @@
2829
<summary>Table of Contents</summary>
2930
<ol>
3031
<li><a href="#overview">Overview</a></li>
31-
<li><a href="#checkmarx-one-results">Checkmarx One Results</a></li>
32+
<li><a href="#checkmarx-one-platform">Checkmarx One Platform</a></li>
33+
<li><a href="#checkmarx-developer-assist">Checkmarx Developer Assist</a></li>
3234
<li><a href="#kics-realtime-scanner">KICS Realtime Scanner</a></li>
3335
<li><a href="#checkmarx-sca-realtime-scanner">Checkmarx SCA Realtime Scanner</a></li>
34-
<li><a href="#initial-setup">Initial Setup</a></li>
3536
<li><a href="#contributing">Contributing</a></li>
3637
<li><a href="#license">License</a></li>
3738
<li><a href="#feedback">Feedback</a></li>
@@ -40,24 +41,34 @@
4041
</details>
4142

4243
## Overview
44+
> ⭐ Although this plugin was developed for VS Code, the plugin has been tested and found to be effective for use in Cursor, Windsurf and Kiro. This document was written for the VS Code plugin, and applies equally to the other supported IDEs. Any information that applies **only** to VS Code, and not to the other supported IDEs, is noted explicitly.
4345
4446
Checkmarx continues to spearhead the shift-left approach to AppSec by bringing our powerful AppSec tools into your IDE. This empowers developers to identify vulnerabilities and remediate them **as they code**. The Checkmarx Visual Studio Code plugin integrates seamlessly into your IDE, identifying vulnerabilities in your proprietary code, open source dependencies, and IaC files. The plugin offers actionable remediation insights in real-time.
4547

46-
The Checkmarx Visual Studio Code extension contains three separate tools:
48+
The Checkmarx Visual Studio Code extension contains four separate capabilities:
4749

48-
- Checkmarx One Results
50+
- Checkmarx One Platform
51+
52+
- Checkmarx Developer Assist
4953

5054
- KICS Realtime Scanner
5155

5256
- Checkmarx SCA Realtime Scanner
5357

5458
> The plugin is available on [marketplace](https://marketplace.visualstudio.com/items?itemName=checkmarx.ast-results). In addition, the code can be accessed [here](https://github.com/Checkmarx/ast-vscode-extension).
5559
56-
## Checkmarx One Results
60+
### Support for VS Code-compatible IDEs
61+
Although this plugin was developed for VS Code, the plugin has been tested and found to be effective for use in the following VS Code-compatible IDEs:
62+
- **Cursor**
63+
- **Windsurf**
64+
- **Kiro** (compatible with version 2.44.0 and above of this extension)
65+
66+
67+
## Checkmarx One Platform
5768

58-
This tool enables Checkmarx One users to access the full functionality of your Checkmarx One account directly from your IDE. You can run new scans or import results from scans run in your Checkmarx One account. Checkmarx provides detailed info about each vulnerability, including remediation recommendations and examples of effective remediation.
69+
This tool enables Checkmarx One users to access the full functionality of your Checkmarx One account (SAST, SCA, IaC, and Secret Detection) directly from your IDE. You can run new scans or import results from scans run in your Checkmarx One account. Checkmarx provides detailed info about each vulnerability, including remediation recommendations and examples of effective remediation. The plugin enables you to navigate from a vulnerability to the relevant source code, so that you can easily zero-in on the problematic code and start working on remediation. <br>
5970

60-
The extension enables you to navigate from a vulnerability to the relevant source code, so that you can easily zero-in on the problematic code and start working on remediation. This tool requires authentication, using credentials from your Checkmarx One account.
71+
These features require authentication, using an API Key or login credentials for your Checkmarx One account.
6172

6273

6374
**GIF - Running a Scan from the IDE**
@@ -68,37 +79,74 @@ The extension enables you to navigate from a vulnerability to the relevant sourc
6879

6980
### Key Features
7081

71-
- Access the full power of Checkmarx One (SAST, SCA, IaC Security and Secret Detection) directly from your IDE.
82+
- Access the Checkmarx One platform directly from your IDE.
83+
- Run a new scan from your IDE even before committing the code, or import scan results from your Checkmarx One account.
84+
- Rescan an existing branch from your IDE or create a new branch in Checkmarx One for the local branch in your workspace.
85+
- Provides actionable results including remediation recommendations. Navigate from the results panel directly to the highlighted vulnerable code in the editor and get right down to work on the remediation.
86+
- Connect to Checkmarx via **API Key** or **OAuth user login** flow.
87+
- View information about how to remediate **SAST vulnerabilities**, including code samples.
88+
- Group and filter results.
89+
- Triage results — edit the result predicate (severity, state, and comments) directly from the Visual Studio Code console (currently supported for **SAST**, **SCA** and **IaC Security**).
90+
- Links to Codebashing lessons.
91+
- Apply Auto Remediation to automatically remediate open source vulnerabilities by updating to a non-vulnerable package version.
92+
- **“AI Security Champion”** harnesses the power of AI to help you understand the vulnerabilities in your code and resolve them quickly and easily (currently supported for **SAST** and **IaC Security** vulnerabilities).
93+
- Shows [Application Security Posture Management (ASPM)](https://docs.checkmarx.com/en/34965-281716-application-security-posture-management.html) results in the IDE.
94+
95+
---
7296

73-
- Run a new scan from your IDE even before committing the code, or import scan results from your Checkmarx One account.
97+
### Prerequisites
7498

75-
- Rescan an existing branch from your IDE or create a new branch in Checkmarx One for the local branch in your workspace.
99+
- An installation of a supported IDE. (**For VS Code**: VS Code version 1.63.0 or above)
100+
101+
- You have access to Checkmarx One via:
102+
- an **API Key** (see [*Generating an API Key*](https://docs.checkmarx.com/en/34965-68618-generating-an-api-key.html#UUID-f3b6481c-47f4-6cd8-9f0d-990896e36cd6_UUID-39ccc262-c7cb-5884-52ed-e1692a635e08)), OR
103+
- login credentials (**Base URL**, **Tenant name**, **Username**, and **Password**)
76104

77-
- Provides actionable results including remediation recommendations. Navigate from results panel directly to the highlighted vulnerable code in the editor and get right down to work on the remediation.
105+
> In order to use this integration for running an end-to-end flow of scanning a project and viewing results, the API Key or user account must have at a minimum the out-of-the-box composite role `ast-scanner` as well as the IAM role `default-roles`.
78106
79-
- View info about how to remediate SAST vulnerabilities, including code samples
107+
- **git** is installed on your local machine. For installation instructions, see [here](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
80108

81-
- Group and filter results
109+
- To use **AI Generated Remediation**, you must have an **API Key for your GPT account**
110+
(unless your account is configured to use Azure AI; see [*Configuring Plugin Settings*](https://docs.checkmarx.com/en/34965-324314-plugins-settings.html#UUID-ea5638d0-3673-520c-79e0-085f92d4a2dc_id_ConfiguringScannerDefaultSettings-OpenScannerDefaultSettings)).
82111

83-
- Triage results - edit the result predicate (severity, state and comments) directly from the Visual Studio Code console
112+
### Installation
84113

85-
- Links to Codebashing lessons
114+
1. Install the **Checkmarx** extension from the Marketplace.
115+
2. In the IDE, open Checkmarx One Settings, click on **Authentication**, and enter your API Key or login credentials to enable all Checkmarx One features.
116+
3. Configure additional Checkmarx One settings as described in Checkmarx [documentation](https://docs.checkmarx.com/en/34965-123549-installing-and-setting-up-the-checkmarx-vs-code-extension.html).
86117

87-
- Apply Auto Remediation to automatically remediate open source vulnerabilities, by updating to a non-vulnerable package version.
118+
**GIF – Installing and Setting Up the Extension**
119+
![Installing and Setting up the Extension](https://raw.githubusercontent.com/Checkmarx/ci-cd-integrations/main/.images/vscode_installation_and_initial_setup.gif)
88120

89-
- "AI Guided Remediation" harnesses the power of AI to help you to understand the vulnerabilities in your code, and resolve them quickly and easily.
121+
### Usage
122+
* Learn about using Checkmarx One features [here](https://docs.checkmarx.com/en/34965-68743-using-the-checkmarx-vs-code-extension---checkmarx-one-results.html)
90123

91-
- AI Secure Coding Assistant (ASCA) - A lightweight scan engine that runs in the background while you work, enabling developers to identify and remediate secure coding best practice violations as they code.
124+
---
92125

126+
## Checkmarx Developer Assist
127+
Developer Assist is an agentic AI tool that delivers real-time context-aware prevention, remediation, and guidance to developers inside the IDE.
128+
<br>
129+
### Key Features
130+
- An advanced security agent that delivers real-time context-aware prevention, remediation, and guidance to developers from the IDE.
131+
- Realtime scanners identify risks as you code.
132+
- AI Secure Coding Assistant (ASCA), a lightweight source code scanner, enables developers to identify secure coding best practice violations in the file that they are working on as they code.
133+
- Specialized realtime scanners identify vulnerable open source packages and container images, as well as exposed secrets and IaC risks.
134+
- MCP-based agentic AI remediation.
135+
- AI powered explanation of risk details.
93136
### Prerequisites
94-
- An installation of VS Code version 1.63.0 or above
137+
- Either a **Developer Assist Access Key** OR
138+
- Credentials for a Checkmarx One account with a **Checkmarx One Assist** license, and with the **Checkmarx MCP** activated for your tenant account in the Checkmarx One UI under **Settings → Plugins**. This must be done by an account admin.
139+
- **For VS Code**: Supported for VS Code version **1.100.0** or above
140+
(supports both `settings.json` (v1.100–1.101) and `mcp.json` (v1.102+))
141+
- **For VS Code**: You must have **GitHub Copilot** installed
142+
### Installation
143+
1. Install the **Checkmarx** extension from the Marketplace.
144+
2. In the IDE, open Checkmarx Settings, click on **Authentication**, and enter your Access Key or login credentials.
95145

96-
- You have an **API Key** for your Checkmarx One account. To create an API key, see [Generating an API Key](https://checkmarx.com/resource/documents/en/34965-68618-generating-an-api-key.html).
97-
> In order to use this integration for running an end-to-end flow of scanning a project and viewing results, the API Key must have at a minimum the out-of-the-box composite role `ast-scanner` as well as the IAM role `default-roles`.
146+
### Usage
147+
* Learn about using Checkmarx Developer Assist [here](https://docs.checkmarx.com/en/34965-474001-using-the-checkmarx-vs-code-extension---dev-assist.html)
98148

99-
- "git" is installed on your local machine. For installation instructions, see [here](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
100-
101-
- In order to use **AI Generated Remediation**, you need to have an API Key for your GPT account.
149+
**GIF - AI Remediation with Developer Assist**
102150

103151
## KICS Realtime Scanner
104152

@@ -117,14 +165,20 @@ This tool initiates KICS scans directly from their VS Code console. The scan run
117165

118166
- Apply Auto Remediation to automatically fix IaC vulnerabilities
119167

120-
- AI Guided Remediation”harnesses the power of AI to help you to understand the vulnerabilities in your code, and resolve them quickly and easily.
168+
- "AI Guided Remediation” harnesses the power of AI to help you to understand the vulnerabilities in your code, and resolve them quickly and easily.
121169

122170
### Prerequisites
123171

124172
- You must have a supported container engine (e.g., Docker, Podman etc.) installed and running in your environment.
125173

126174
- In order to use **AI Generated Remediation**, you need to have an API Key for your GPT account.
127175

176+
### Installation
177+
178+
1. Install the **Checkmarx** extension from the Marketplace.
179+
> No additional setup is required — KICS Realtime Scanner works automatically once the extension is installed.
180+
2. If you would like to customize the scan parameters, enter the desired flags in the Additional Parameters field. For a list of available options, see [Scan Command Options](https://docs.checkmarx.com/en/34965-123549-installing-and-setting-up-the-checkmarx-vs-code-extension.html).
181+
128182
## Checkmarx SCA Realtime Scanner
129183

130184
This tool enables VS Code users to initiate SCA scans directly from their VS Code console, and shows detailed results as soon as the scan is completed. The scan identifies the open-source dependencies used in your code and indicates the security risks associated with those packages. The identified packages are shown in a tree structure with an indication of the risk level for each package. You can drill down to show the specific vulnerabilities associated with a package. This is a **free tool** provided by Checkmarx for all VS Code users, and does not require the user to submit credentials for a Checkmarx One account.
@@ -143,35 +197,22 @@ This tool enables VS Code users to initiate SCA scans directly from their VS Cod
143197

144198
- In order to get comprehensive results, you need to install all relevant package managers on your local environment, see [Installing Supported Package Managers](https://checkmarx.com/resource/documents/en/34965-19198-installing-supported-package-managers-for-resolver.html).
145199

146-
## Initial Setup
147-
1. Verify that all prerequisites are in place.
148-
149-
2. Install the extension from Marketplace.
150-
151-
3. Configure the extension settings as follows:
152-
- For **KICS Realtime Scanner** and **SCA Realtime Scanner** - no
153-
configuration needed.
154-
- For SCA Realtime Scanning, if your environment doesn't have access to the internet, then you will need to configure a proxy server in the Settings, under **Checkmarx One: Additional Params**.
155-
156-
- For **Checkmarx One Results** - use your Checkmarx One API Key to integrate with your Checkmarx One account, as described [here](https://checkmarx.com/resource/documents/en/34965-123549-installing-and-setting-up-the-checkmarx-vs-code-extension.html#UUID-b74024dd-5f0e-cac7-668c-94049b9d8566_id_VisualStudioCode-ASTResults-SettinguptheExtension).
157-
158-
- If you would like to use **AI Guided Remediation**, use your GPT API Key to integrate with your GPT account, as described [here](https://checkmarx.com/resource/documents/en/34965-123549-installing-and-setting-up-the-checkmarx-vs-code-extension.html#UUID-b74024dd-5f0e-cac7-668c-94049b9d8566_section-idm4543400890995233753488463936).
159-
200+
### Installation
160201

161-
**GIF - Installing and Setting up the Extension**
162-
![Installing and Setting up the Extension](https://raw.githubusercontent.com/Checkmarx/ci-cd-integrations/main/.images/vscode_installation_and_initial_setup.gif "Installing and Setting up the Extension")
202+
1. Install the **Checkmarx** extension from the Marketplace.
203+
> No configuration is required for SCA Realtime Scanning in most environments.
163204
164205
## Contributing
165206

166207
We appreciate feedback and contribution to the VsCode extension! Before you get started, please see the following:
167208

168-
- [Checkmarx contribution guidelines](docs/contributing.md)
169-
- [Checkmarx Code of Conduct](docs/code_of_conduct.md)
209+
- [Checkmarx contribution guidelines](https://github.com/Checkmarx/ast-vscode-extension/blob/HEAD/docs/contributing.md)
210+
- [Checkmarx Code of Conduct](https://github.com/Checkmarx/ast-vscode-extension/blob/HEAD/docs/code_of_conduct.md)
170211

171212
<!-- LICENSE -->
172213
## License
173214

174-
Distributed under the [Apache 2.0](LICENSE). See `LICENSE` for more information.
215+
Distributed under the [Apache 2.0](https://github.com/Checkmarx/ast-vscode-extension/blob/HEAD/LICENSE). See `LICENSE` for more information.
175216

176217
<!-- FEEDBACK -->
177218
## Feedback
@@ -186,7 +227,7 @@ Project Link: [https://github.com/Checkmarx/ast-vscode-extension](https://github
186227

187228
Find more integrations from our team [here](https://github.com/Checkmarx/ci-cd-integrations#checkmarx-ast-integrations)
188229

189-
© 2024 Checkmarx Ltd. All Rights Reserved.
230+
© 2025 Checkmarx Ltd. All Rights Reserved.
190231

191232
[contributors-shield]: https://img.shields.io/github/contributors/Checkmarx/ast-vscode-extension.svg
192233
[contributors-url]: https://github.com/Checkmarx/ast-vscode-extension/graphs/contributors

media/gpt.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@
66
var currentMessage;
77
var currentID;
88

9+
/**
10+
* Sanitize HTML content to prevent XSS attacks while preserving safe formatting
11+
* @param {string} html - The HTML content to sanitize
12+
* @returns {string} - Sanitized HTML content
13+
*/
14+
function sanitizeHtml(html) {
15+
// Parse with DOMParser to work with actual DOM elements
16+
const parser = new DOMParser();
17+
const doc = parser.parseFromString(html, 'text/html');
18+
19+
// Remove any script tags
20+
const scripts = doc.querySelectorAll('script');
21+
scripts.forEach(script => script.remove());
22+
23+
// Remove all event handler attributes and dangerous protocols
24+
const allElements = doc.querySelectorAll('*');
25+
allElements.forEach(element => {
26+
// Remove all on* event attributes
27+
Array.from(element.attributes).forEach(attr => {
28+
if (attr.name.startsWith('on')) {
29+
element.removeAttribute(attr.name);
30+
}
31+
});
32+
33+
// Remove javascript: protocol from href and src
34+
if (element.hasAttribute('href')) {
35+
const href = element.getAttribute('href');
36+
if (href && href.toLowerCase().startsWith('javascript:')) {
37+
element.removeAttribute('href');
38+
}
39+
}
40+
if (element.hasAttribute('src')) {
41+
const src = element.getAttribute('src');
42+
if (src && src.toLowerCase().startsWith('javascript:')) {
43+
element.removeAttribute('src');
44+
}
45+
}
46+
});
47+
48+
return doc.body.innerHTML;
49+
}
50+
951
marked.setOptions({
1052
renderer: new marked.Renderer(),
1153
highlight: function (code, _lang) {
@@ -69,7 +111,7 @@
69111
async function typeWriter() {
70112
const inCodeBlock = currentMessage.includes('```') && currentMessage.split('```').length % 2 === 0;
71113
const markedContent = new DOMParser().parseFromString(marked.parse(currentMessage + (inCodeBlock ? '\n```' : '')), 'text/html');
72-
const textMarkdown = markedContent.documentElement.innerHTML;
114+
const textMarkdown = sanitizeHtml(markedContent.body.innerHTML);
73115
document.getElementById("gpt-" + currentID).innerHTML += textMarkdown;
74116
const chatContainer = document.getElementById('chat-container');
75117
const pres = chatContainer.querySelectorAll('pre');

media/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
let preCode = document.createElement('pre');
367367
preCode.setAttribute('class', 'pre-code');
368368
let codeElement = document.createElement('code');
369-
codeElement.textContent = code.code.replaceAll("<", "&lt;").replaceAll(">", "&gt");
369+
codeElement.textContent = code.code;
370370
preCode.appendChild(codeElement);
371371
learnSectionDiv.appendChild(codeTitlePara);
372372
learnSectionDiv.appendChild(preCode);

0 commit comments

Comments
 (0)