Skip to content

Commit cf585cd

Browse files
authored
fix: potential xss issue reported in mynah-ui (aws#2209)
* fix: potential xss issue * fix: addressing comments * fix: unescaping the history message while opening history tab
1 parent da4c3db commit cf585cd

File tree

9 files changed

+23
-7
lines changed

9 files changed

+23
-7
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/aws-lsp-codewhisperer/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@
6767
"vscode-uri": "^3.1.0",
6868
"ws": "^8.18.0",
6969
"xml2js": "^0.6.2",
70-
"xmlbuilder2": "^3.1.1"
70+
"xmlbuilder2": "^3.1.1",
71+
"unescape-html": "^1.1.0"
7172
},
7273
"devDependencies": {
7374
"@types/adm-zip": "^0.5.5",
7475
"@types/archiver": "^6.0.2",
7576
"@types/diff": "^7.0.2",
7677
"@types/encoding-japanese": "^2.2.1",
78+
"@types/escape-html": "^1.0.4",
7779
"@types/ignore-walk": "^4.0.3",
7880
"@types/local-indexing": "file:./types/types-local-indexing-1.1.0.tgz",
7981
"@types/lokijs": "^1.5.14",

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import { LocalProjectContextController } from '../../shared/localProjectContextC
5757
import { CancellationError } from '@aws/lsp-core'
5858
import { ToolApprovalException } from './tools/toolShared'
5959
import * as constants from './constants/constants'
60-
import { DEFAULT_MODEL_ID, GENERATE_ASSISTANT_RESPONSE_INPUT_LIMIT, GENERIC_ERROR_MS } from './constants/constants'
60+
import { GENERATE_ASSISTANT_RESPONSE_INPUT_LIMIT, GENERIC_ERROR_MS } from './constants/constants'
6161
import { MISSING_BEARER_TOKEN_ERROR } from '../../shared/constants'
6262
import {
6363
AmazonQError,

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ import {
179179
OUTPUT_LIMIT_EXCEEDS_PARTIAL_MSG,
180180
RESPONSE_TIMEOUT_MS,
181181
RESPONSE_TIMEOUT_PARTIAL_MSG,
182-
DEFAULT_MODEL_ID,
183182
COMPACTION_BODY,
184183
COMPACTION_HEADER_BODY,
185184
DEFAULT_MACOS_RUN_SHORTCUT,
@@ -230,6 +229,7 @@ import { CodeWhispererServiceToken } from '../../shared/codeWhispererService'
230229
import { DisplayFindings } from './tools/qCodeAnalysis/displayFindings'
231230
import { IDE } from '../../shared/constants'
232231
import { IdleWorkspaceManager } from '../workspaceContext/IdleWorkspaceManager'
232+
import escapeHTML = require('escape-html')
233233

234234
type ChatHandlers = Omit<
235235
LspHandlers<Chat>,
@@ -1363,7 +1363,7 @@ export class AgenticChatController implements ChatHandlers {
13631363
this.#debug('Skipping adding user message to history - cancelled by user')
13641364
} else {
13651365
this.#chatHistoryDb.addMessage(tabId, 'cwc', conversationIdentifier, {
1366-
body: currentMessage.userInputMessage?.content ?? '',
1366+
body: escapeHTML(currentMessage.userInputMessage?.content ?? ''),
13671367
type: 'prompt' as any,
13681368
userIntent: currentMessage.userInputMessage?.userIntent,
13691369
origin: currentMessage.userInputMessage?.origin,

server/aws-lsp-codewhisperer/src/language-server/agenticChat/constants/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const SERVICE_MANAGER_POLL_INTERVAL_MS = 100
1414

1515
// LLM Constants
1616
export const GENERATE_ASSISTANT_RESPONSE_INPUT_LIMIT = 500_000
17-
export const DEFAULT_MODEL_ID = BedrockModel.CLAUDE_SONNET_4_20250514_V1_0
1817

1918
// Compaction
2019
export const COMPACTION_BODY = (threshold: number) =>

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { ChatItemType } from '@aws/mynah-ui'
3535
import { getUserHomeDir } from '@aws/lsp-core/out/util/path'
3636
import { ChatHistoryMaintainer } from './chatHistoryMaintainer'
3737
import { existsSync, renameSync } from 'fs'
38+
import escapeHTML = require('escape-html')
3839

3940
export class ToolResultValidationError extends Error {
4041
constructor(message?: string) {
@@ -693,6 +694,7 @@ export class ChatDatabase {
693694
}
694695
return {
695696
...message,
697+
body: escapeHTML(message.body),
696698
userInputMessageContext: {
697699
// keep falcon context when inputMessage is not a toolResult message
698700
editorState: hasToolResults ? undefined : message.userInputMessageContext?.editorState,

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { activeFileCmd } from '../../context/additionalContextProvider'
2828
import { PriorityQueue } from 'typescript-collections'
2929
import { Features } from '@aws/language-server-runtimes/server-interface/server'
3030
import * as crypto from 'crypto'
31+
import unescapeHTML = require('unescape-html')
3132

3233
// Ported from https://github.com/aws/aws-toolkit-vscode/blob/master/packages/core/src/shared/db/chatDb/util.ts
3334

@@ -172,7 +173,7 @@ export function messageToStreamingMessage(msg: Message): StreamingMessage {
172173
export function messageToChatMessage(msg: Message): ChatMessage[] {
173174
const chatMessages: ChatMessage[] = [
174175
{
175-
body: msg.body,
176+
body: unescapeHTML(msg.body),
176177
type: msg.type,
177178
codeReference: msg.codeReference,
178179
relatedContent:

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { MCPServerConfig, PersonaConfig, MCPServerPermission, McpPermissionType,
99
import path = require('path')
1010
import { QClientCapabilities } from '../../../configuration/qConfigurationServer'
1111
import crypto = require('crypto')
12-
import { Features } from '@aws/language-server-runtimes/server-interface/server'
1312

1413
/**
1514
* Load, validate, and parse MCP server configurations from JSON files.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'unescape-html' {
2+
function unescapeHTML(str: string): string
3+
export = unescapeHTML
4+
}

0 commit comments

Comments
 (0)