File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ var vm = require('vm');
55var logger = require ( '../logger' ) . default ;
66
77var regexTimeout = 0 ;
8+ // IMPORTANT: vmContext is shared across all calls for performance (vm.createContext() is expensive).
9+ // This is safe because safeRegexTest is synchronous — setting the context properties and calling
10+ // runInContext happen in the same event loop tick with no interruption possible. Do NOT add any
11+ // asynchronous operations (await, callbacks, promises) between setting vmContext properties and
12+ // calling script.runInContext, as this would allow other calls to overwrite the context values
13+ // and cause cross-contamination between regex evaluations.
814var vmContext = vm . createContext ( Object . create ( null ) ) ;
915var scriptCache = new Map ( ) ;
1016var SCRIPT_CACHE_MAX = 1000 ;
@@ -13,6 +19,7 @@ function setRegexTimeout(ms) {
1319 regexTimeout = ms ;
1420}
1521
22+ // IMPORTANT: This function must remain synchronous. See vmContext comment above.
1623function safeRegexTest ( pattern , flags , input ) {
1724 try {
1825 if ( ! regexTimeout ) {
You can’t perform that action at this time.
0 commit comments