File tree 9 files changed +145
-70
lines changed
node-form/widgets/highlight-input/variable-value-block/components
9 files changed +145
-70
lines changed Original file line number Diff line number Diff line change 90
90
"uuid" : " ^10.0.0" ,
91
91
"zod" : " ^3.23.8" ,
92
92
"zustand" : " ^4.5.4" ,
93
- "zustand-computed-state" : " ^0.1.8"
93
+ "zustand-computed-state" : " ^0.1.8" ,
94
+ "isomorphic-dompurify" : " ^2.14.0"
94
95
},
95
96
"devDependencies" : {
96
97
"@shellagent/eslint-config" : " workspace:*" ,
Original file line number Diff line number Diff line change 3
3
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' ;
4
4
import { $getNodeByKey , COMMAND_PRIORITY_EDITOR } from 'lexical' ;
5
5
import { memo , useRef , useEffect } from 'react' ;
6
+ import { sanitize } from 'isomorphic-dompurify' ;
6
7
7
8
import { cn } from '@/utils/cn' ;
8
9
@@ -125,21 +126,23 @@ const VariableValueBlockComponent = ({
125
126
} ;
126
127
127
128
const renderParts = ( ) => {
128
- return parts
129
- . map ( part => {
130
- if ( part . type === PartType . TEXT ) {
131
- return part . content ;
132
- } else if ( part . type === PartType . VARIABLE ) {
133
- return `<span
129
+ return sanitize (
130
+ parts
131
+ . map ( part => {
132
+ if ( part . type === PartType . TEXT ) {
133
+ return part . content ;
134
+ } else if ( part . type === PartType . VARIABLE ) {
135
+ return `<span
134
136
data-origin-value="${ part . content } "
135
137
data-display="${ part . display } "
136
138
contenteditable="false"
137
139
class="inline-block text-blue-700 cursor-text px-0.5"
138
140
>${ part . display } </span>` ;
139
- }
140
- return '' ;
141
- } )
142
- . join ( '' ) ;
141
+ }
142
+ return '' ;
143
+ } )
144
+ . join ( '' ) ,
145
+ ) ;
143
146
} ;
144
147
145
148
return (
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
21
21
import { observer } from 'mobx-react-lite' ;
22
22
import React , { useEffect , useRef } from 'react' ;
23
23
import { Box , Flex } from 'react-system' ;
24
+ import { sanitize } from 'isomorphic-dompurify' ;
24
25
25
26
import {
26
27
DEFAULT_MODAL_STYLES ,
@@ -226,7 +227,9 @@ export const ComfyUIEditorModal = observer(() => {
226
227
] } >
227
228
< div
228
229
dangerouslySetInnerHTML = { {
229
- __html : model . messageDetail ?. replaceAll ( '\n' , '<br />' ) || '' ,
230
+ __html : sanitize (
231
+ model . messageDetail ?. replaceAll ( '\n' , '<br />' ) || '' ,
232
+ ) ,
230
233
} }
231
234
/>
232
235
</ Modal >
Original file line number Diff line number Diff line change @@ -128,11 +128,27 @@ export const customFetch = async <T>(
128
128
{ toastId : 'login-error' } ,
129
129
) ;
130
130
setTimeout ( ( ) => {
131
+ const currentUrl = window . location . href ;
132
+ const isValidRedirectUrl = ( ( ) => {
133
+ try {
134
+ const url = new URL ( currentUrl ) ;
135
+ return (
136
+ url . hostname . endsWith ( 'myshell.fun' ) ||
137
+ url . hostname . endsWith ( 'myshell.ai' ) ||
138
+ url . hostname . endsWith ( 'myshell.life' )
139
+ ) ;
140
+ } catch ( e ) {
141
+ return false ;
142
+ }
143
+ } ) ( ) ;
144
+
145
+ const redirectUrl = isValidRedirectUrl
146
+ ? currentUrl
147
+ : 'https://myshell.ai' ;
148
+
131
149
window . location . href = `${
132
150
process . env . NEXT_PUBLIC_LOGIN_URL
133
- } ?login=true&redirect=${ decodeURIComponent (
134
- window . location . href ,
135
- ) } `;
151
+ } ?login=true&redirect=${ encodeURIComponent ( redirectUrl ) } `;
136
152
} , 3000 ) ;
137
153
}
138
154
Original file line number Diff line number Diff line change 30
30
"react-dnd" : " ^16.0.1" ,
31
31
"react-dnd-html5-backend" : " ^16.0.1" ,
32
32
"react-error-boundary" : " ^4.0.13" ,
33
+ "sval" : " ^0.6.1" ,
33
34
"tailwind-merge" : " ^2.5.2" ,
34
35
"zod" : " ^3.23.8" ,
35
36
"zustand" : " ^4.5.5"
Original file line number Diff line number Diff line change
1
+ import { exec } from './exec' ;
2
+ import Sval from 'sval' ;
3
+
4
+ describe ( 'exec' , ( ) => {
5
+ it ( 'should return the result of the code' , ( ) => {
6
+ const result = exec ( `$this.value === "image"` , {
7
+ $this : {
8
+ value : 'text' ,
9
+ } ,
10
+ } ) ;
11
+ expect ( result ) . toBe ( false ) ;
12
+ } ) ;
13
+
14
+ it ( 'exec sval ver' , ( ) => {
15
+ const result = exec ( `$this.value === "image"` , {
16
+ $this : {
17
+ value : 'image' ,
18
+ } ,
19
+ } ) ;
20
+ expect ( result ) . toBe ( true ) ;
21
+
22
+ const result2 = exec ( `$this.value === "image"` , {
23
+ $this : {
24
+ value : 'text' ,
25
+ } ,
26
+ } ) ;
27
+ expect ( result2 ) . toBe ( false ) ;
28
+ } ) ;
29
+
30
+ it ( 'sval' , ( ) => {
31
+ const interpreter = new Sval ( {
32
+ ecmaVer : 'latest' ,
33
+ sourceType : 'script' ,
34
+ sandBox : true ,
35
+ } ) ;
36
+ const code = `
37
+ globalThis.$this = {
38
+ value: "text"
39
+ }
40
+ exports.a = $this.value === "image"
41
+ ` ;
42
+ interpreter . run ( code ) ;
43
+ expect ( interpreter . exports . a ) . toBe ( false ) ;
44
+ } ) ;
45
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import { TContext } from '../types' ;
2
+ import Sval from 'sval' ;
2
3
3
- function exec ( code : string , scope : TContext ) {
4
- try {
5
- const str = `
6
- var ${ '____data' } = arguments[0];
7
- with(${ '____data' } ) {
8
- return ${ code }
9
- }
10
- ` ;
4
+ function safeExec ( expression : string , scope : TContext ) {
5
+ const interpreter = new Sval ( {
6
+ ecmaVer : 'latest' ,
7
+ sourceType : 'script' ,
8
+ sandBox : true ,
9
+ } ) ;
11
10
12
- return new Function ( str ) ( scope ) ;
13
- } catch ( e ) {
14
- console . log ( e ) ;
15
- }
11
+ let globalThisAssignments = '' ;
12
+
13
+ Object . keys ( scope ) . forEach ( key => {
14
+ const value = scope [ key ] ;
15
+ globalThisAssignments += `globalThis[${ JSON . stringify (
16
+ key ,
17
+ ) } ] = ${ JSON . stringify ( value ) } ;\n`;
18
+ } ) ;
19
+
20
+ const code = `
21
+ ${ globalThisAssignments }
22
+ exports.a = ${ expression } ;` ;
23
+
24
+ interpreter . run ( code ) ;
25
+
26
+ return interpreter . exports . a ;
16
27
}
17
28
18
- export { exec } ;
29
+ export { safeExec as exec } ;
Original file line number Diff line number Diff line change
1
+ module . exports = function ( wallaby ) {
2
+ return {
3
+ autoDetect : [ 'jest' ] ,
4
+ } ;
5
+ } ;
You can’t perform that action at this time.
0 commit comments