@@ -9,6 +9,12 @@ import './color.css'
9
9
import '@nlux/themes/unstyled.css' ;
10
10
import copy from 'copy-to-clipboard'
11
11
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
+
12
18
export let ChatApi = null
13
19
14
20
export const Default = ( props ) => {
@@ -39,6 +45,8 @@ export const Default = (props) => {
39
45
prompt : string ,
40
46
observer : StreamingAdapterObserver ,
41
47
) => {
48
+
49
+ const cleanPrompt = sanitizeInput ( prompt ) ;
42
50
GenerationParams . stream_result = true
43
51
setIS_streaming ( true )
44
52
GenerationParams . return_stream_response = GenerationParams . stream_result
@@ -47,14 +55,14 @@ export const Default = (props) => {
47
55
if ( await props . plugin . call ( 'remixAI' , 'isChatRequestPending' ) ) {
48
56
response = await props . plugin . call ( 'remixAI' , 'ProcessChatRequestBuffer' , GenerationParams ) ;
49
57
} else {
50
- response = await props . plugin . call ( 'remixAI' , 'solidity_answer' , prompt , GenerationParams ) ;
58
+ response = await props . plugin . call ( 'remixAI' , 'solidity_answer' , cleanPrompt , GenerationParams ) ;
51
59
}
52
60
53
61
if ( GenerationParams . return_stream_response ) HandleStreamResponse ( response ,
54
62
( text ) => { observer . next ( text ) } ,
55
63
( result ) => {
56
64
observer . next ( ' ' ) // Add a space to flush the last message
57
- ChatHistory . pushHistory ( prompt , result )
65
+ ChatHistory . pushHistory ( cleanPrompt , result )
58
66
observer . complete ( )
59
67
setTimeout ( ( ) => { setIS_streaming ( false ) } , 1000 )
60
68
}
0 commit comments