Skip to content

Commit 0849c06

Browse files
committed
santize
1 parent 09af779 commit 0849c06

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libs/remix-ui/remix-ai/src/lib/components/Default.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import './color.css'
99
import '@nlux/themes/unstyled.css';
1010
import copy from 'copy-to-clipboard'
1111

12+
// Using DOMPurify for sanitization
13+
import DOMPurify from 'dompurify';
14+
15+
// Function to sanitize user input
16+
const sanitizeInput = (input: string) => DOMPurify.sanitize(input);
17+
1218
export let ChatApi = null
1319

1420
export const Default = (props) => {
@@ -39,6 +45,8 @@ export const Default = (props) => {
3945
prompt: string,
4046
observer: StreamingAdapterObserver,
4147
) => {
48+
49+
const cleanPrompt = sanitizeInput(prompt);
4250
GenerationParams.stream_result = true
4351
setIS_streaming(true)
4452
GenerationParams.return_stream_response = GenerationParams.stream_result
@@ -47,14 +55,14 @@ export const Default = (props) => {
4755
if (await props.plugin.call('remixAI', 'isChatRequestPending')){
4856
response = await props.plugin.call('remixAI', 'ProcessChatRequestBuffer', GenerationParams);
4957
} else {
50-
response = await props.plugin.call('remixAI', 'solidity_answer', prompt, GenerationParams);
58+
response = await props.plugin.call('remixAI', 'solidity_answer', cleanPrompt, GenerationParams);
5159
}
5260

5361
if (GenerationParams.return_stream_response) HandleStreamResponse(response,
5462
(text) => {observer.next(text)},
5563
(result) => {
5664
observer.next(' ') // Add a space to flush the last message
57-
ChatHistory.pushHistory(prompt, result)
65+
ChatHistory.pushHistory(cleanPrompt, result)
5866
observer.complete()
5967
setTimeout(() => { setIS_streaming(false) }, 1000)
6068
}

0 commit comments

Comments
 (0)