File tree 1 file changed +18
-5
lines changed
packages/insomnia/src/common
1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -293,11 +293,24 @@ export async function render<T>(
293
293
) {
294
294
// Do nothing to these types
295
295
} else if ( typeof x === 'string' ) {
296
- // Detect if the string contains a require statement
297
- if ( / r e q u i r e \s * \( / ig. test ( x ) ) {
298
- console . warn ( 'Short-circuiting `render`; string contains possible "require" invocation:' , x ) ;
299
- Sentry . captureException ( new Error ( `Short-circuiting 'render'; string contains possible "require" invocation: ${ x } ` ) ) ;
300
- return x ;
296
+ // Allowed modules could have valid use cases within templates, and we know for a fact that these modules cannot be
297
+ // used as part of an exploit.
298
+ const allowedModules = [ 'crypto' , 'path' ] ;
299
+ const matches = [ ...x . matchAll ( / r e q u i r e \s * \( \s * [ " ' ` ] ( [ ^ ' " ` ] * ) [ ' " ` ] / gi) ] . map ( match => match [ 1 ] ) ;
300
+
301
+ if ( matches . length ) {
302
+ // Only allow the string to be rendered if required modules are *all* in the allowed modules list. If any modules
303
+ // outside of the allowed list is detected, we short-circuit rendering and return the raw string.
304
+ for ( const match of matches ) {
305
+ if ( allowedModules . includes ( match ) ) {
306
+ continue ;
307
+ } else {
308
+ console . warn ( 'Short-circuiting `render`; string contains at least one disallowed "require" invocation:' , x ) ;
309
+ Sentry . captureException ( new Error ( `Short-circuiting 'render'; string contains at least one disallowed "require" invocation: ${ x } ` ) ) ;
310
+
311
+ return x ;
312
+ }
313
+ }
301
314
}
302
315
303
316
try {
You can’t perform that action at this time.
0 commit comments