Compare commits
6 Commits
main
...
chore/Allo
| Author | SHA1 | Date |
|---|---|---|
|
|
9402ed324d | |
|
|
db4eb056e4 | |
|
|
8972cf8c14 | |
|
|
7f93ab9a91 | |
|
|
6a2816798e | |
|
|
10aa58e53b |
|
|
@ -18,7 +18,7 @@ import { TextSplitter } from 'langchain/text_splitter'
|
||||||
import { DocumentLoader } from 'langchain/document_loaders/base'
|
import { DocumentLoader } from 'langchain/document_loaders/base'
|
||||||
import { NodeVM } from '@flowiseai/nodevm'
|
import { NodeVM } from '@flowiseai/nodevm'
|
||||||
import { Sandbox } from '@e2b/code-interpreter'
|
import { Sandbox } from '@e2b/code-interpreter'
|
||||||
import { secureFetch, checkDenyList } from './httpSecurity'
|
import { secureFetch, checkDenyList, secureAxiosRequest } from './httpSecurity'
|
||||||
import JSON5 from 'json5'
|
import JSON5 from 'json5'
|
||||||
|
|
||||||
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
|
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
|
||||||
|
|
@ -85,7 +85,6 @@ export const availableDependencies = [
|
||||||
'@upstash/redis',
|
'@upstash/redis',
|
||||||
'@zilliz/milvus2-sdk-node',
|
'@zilliz/milvus2-sdk-node',
|
||||||
'apify-client',
|
'apify-client',
|
||||||
'axios',
|
|
||||||
'cheerio',
|
'cheerio',
|
||||||
'chromadb',
|
'chromadb',
|
||||||
'cohere-ai',
|
'cohere-ai',
|
||||||
|
|
@ -103,10 +102,8 @@ export const availableDependencies = [
|
||||||
'linkifyjs',
|
'linkifyjs',
|
||||||
'lunary',
|
'lunary',
|
||||||
'mammoth',
|
'mammoth',
|
||||||
'moment',
|
|
||||||
'mongodb',
|
'mongodb',
|
||||||
'mysql2',
|
'mysql2',
|
||||||
'node-fetch',
|
|
||||||
'node-html-markdown',
|
'node-html-markdown',
|
||||||
'notion-to-md',
|
'notion-to-md',
|
||||||
'openai',
|
'openai',
|
||||||
|
|
@ -122,6 +119,8 @@ export const availableDependencies = [
|
||||||
'weaviate-ts-client'
|
'weaviate-ts-client'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const defaultAllowExternalDependencies = ['axios', 'moment', 'node-fetch']
|
||||||
|
|
||||||
export const defaultAllowBuiltInDep = [
|
export const defaultAllowBuiltInDep = [
|
||||||
'assert',
|
'assert',
|
||||||
'buffer',
|
'buffer',
|
||||||
|
|
@ -1547,14 +1546,44 @@ export const executeJavaScriptCode = async (
|
||||||
? defaultAllowBuiltInDep.concat(process.env.TOOL_FUNCTION_BUILTIN_DEP.split(','))
|
? defaultAllowBuiltInDep.concat(process.env.TOOL_FUNCTION_BUILTIN_DEP.split(','))
|
||||||
: defaultAllowBuiltInDep
|
: defaultAllowBuiltInDep
|
||||||
const externalDeps = process.env.TOOL_FUNCTION_EXTERNAL_DEP ? process.env.TOOL_FUNCTION_EXTERNAL_DEP.split(',') : []
|
const externalDeps = process.env.TOOL_FUNCTION_EXTERNAL_DEP ? process.env.TOOL_FUNCTION_EXTERNAL_DEP.split(',') : []
|
||||||
const deps = process.env.ALLOW_BUILTIN_DEP === 'true' ? availableDependencies.concat(externalDeps) : externalDeps
|
let deps = process.env.ALLOW_BUILTIN_DEP === 'true' ? availableDependencies.concat(externalDeps) : externalDeps
|
||||||
|
deps.push(...defaultAllowExternalDependencies)
|
||||||
|
deps = [...new Set(deps)]
|
||||||
|
|
||||||
|
// Create secure wrappers for HTTP libraries
|
||||||
|
const secureWrappers: ICommonObject = {}
|
||||||
|
|
||||||
|
// Axios
|
||||||
|
const secureAxiosWrapper = async (config: any) => {
|
||||||
|
return await secureAxiosRequest(config)
|
||||||
|
}
|
||||||
|
secureAxiosWrapper.get = async (url: string, config: any = {}) => secureAxiosWrapper({ ...config, method: 'GET', url })
|
||||||
|
secureAxiosWrapper.post = async (url: string, data: any, config: any = {}) =>
|
||||||
|
secureAxiosWrapper({ ...config, method: 'POST', url, data })
|
||||||
|
secureAxiosWrapper.put = async (url: string, data: any, config: any = {}) =>
|
||||||
|
secureAxiosWrapper({ ...config, method: 'PUT', url, data })
|
||||||
|
secureAxiosWrapper.delete = async (url: string, config: any = {}) => secureAxiosWrapper({ ...config, method: 'DELETE', url })
|
||||||
|
secureAxiosWrapper.patch = async (url: string, data: any, config: any = {}) =>
|
||||||
|
secureAxiosWrapper({ ...config, method: 'PATCH', url, data })
|
||||||
|
|
||||||
|
secureWrappers['axios'] = secureAxiosWrapper
|
||||||
|
|
||||||
|
// Node Fetch
|
||||||
|
const secureNodeFetch = async (url: string, options: any = {}) => {
|
||||||
|
return await secureFetch(url, options)
|
||||||
|
}
|
||||||
|
secureWrappers['node-fetch'] = secureNodeFetch
|
||||||
|
|
||||||
const defaultNodeVMOptions: any = {
|
const defaultNodeVMOptions: any = {
|
||||||
console: 'inherit',
|
console: 'inherit',
|
||||||
sandbox,
|
sandbox,
|
||||||
require: {
|
require: {
|
||||||
external: { modules: deps },
|
external: {
|
||||||
builtin: builtinDeps
|
modules: deps,
|
||||||
|
transitive: false // Prevent transitive dependencies
|
||||||
|
},
|
||||||
|
builtin: builtinDeps,
|
||||||
|
mock: secureWrappers // Replace HTTP libraries with secure wrappers
|
||||||
},
|
},
|
||||||
eval: false,
|
eval: false,
|
||||||
wasm: false,
|
wasm: false,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue