Skip to content

Commit 31434e5

Browse files
authored
Chore/allow axios node fetch (#5264)
* disable available dependencies by default, only allow when ALLOW_BUILTIN_DEP is set to true * update contributing.md * update pnpm lock * Enhance security by adding secure wrappers for Axios and Node Fetch in utils.ts, and update dependency handling to include default external dependencies. * Fix formatting in pnpm-lock.yaml
1 parent 84a0a45 commit 31434e5

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

packages/components/src/utils.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { TextSplitter } from 'langchain/text_splitter'
1818
import { DocumentLoader } from 'langchain/document_loaders/base'
1919
import { NodeVM } from '@flowiseai/nodevm'
2020
import { Sandbox } from '@e2b/code-interpreter'
21-
import { secureFetch, checkDenyList } from './httpSecurity'
21+
import { secureFetch, checkDenyList, secureAxiosRequest } from './httpSecurity'
2222
import JSON5 from 'json5'
2323

2424
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
@@ -85,7 +85,6 @@ export const availableDependencies = [
8585
'@upstash/redis',
8686
'@zilliz/milvus2-sdk-node',
8787
'apify-client',
88-
'axios',
8988
'cheerio',
9089
'chromadb',
9190
'cohere-ai',
@@ -103,10 +102,8 @@ export const availableDependencies = [
103102
'linkifyjs',
104103
'lunary',
105104
'mammoth',
106-
'moment',
107105
'mongodb',
108106
'mysql2',
109-
'node-fetch',
110107
'node-html-markdown',
111108
'notion-to-md',
112109
'openai',
@@ -122,6 +119,8 @@ export const availableDependencies = [
122119
'weaviate-ts-client'
123120
]
124121

122+
const defaultAllowExternalDependencies = ['axios', 'moment', 'node-fetch']
123+
125124
export const defaultAllowBuiltInDep = [
126125
'assert',
127126
'buffer',
@@ -1547,14 +1546,44 @@ export const executeJavaScriptCode = async (
15471546
? defaultAllowBuiltInDep.concat(process.env.TOOL_FUNCTION_BUILTIN_DEP.split(','))
15481547
: defaultAllowBuiltInDep
15491548
const externalDeps = process.env.TOOL_FUNCTION_EXTERNAL_DEP ? process.env.TOOL_FUNCTION_EXTERNAL_DEP.split(',') : []
1550-
const deps = process.env.ALLOW_BUILTIN_DEP === 'true' ? availableDependencies.concat(externalDeps) : externalDeps
1549+
let deps = process.env.ALLOW_BUILTIN_DEP === 'true' ? availableDependencies.concat(externalDeps) : externalDeps
1550+
deps.push(...defaultAllowExternalDependencies)
1551+
deps = [...new Set(deps)]
1552+
1553+
// Create secure wrappers for HTTP libraries
1554+
const secureWrappers: ICommonObject = {}
1555+
1556+
// Axios
1557+
const secureAxiosWrapper = async (config: any) => {
1558+
return await secureAxiosRequest(config)
1559+
}
1560+
secureAxiosWrapper.get = async (url: string, config: any = {}) => secureAxiosWrapper({ ...config, method: 'GET', url })
1561+
secureAxiosWrapper.post = async (url: string, data: any, config: any = {}) =>
1562+
secureAxiosWrapper({ ...config, method: 'POST', url, data })
1563+
secureAxiosWrapper.put = async (url: string, data: any, config: any = {}) =>
1564+
secureAxiosWrapper({ ...config, method: 'PUT', url, data })
1565+
secureAxiosWrapper.delete = async (url: string, config: any = {}) => secureAxiosWrapper({ ...config, method: 'DELETE', url })
1566+
secureAxiosWrapper.patch = async (url: string, data: any, config: any = {}) =>
1567+
secureAxiosWrapper({ ...config, method: 'PATCH', url, data })
1568+
1569+
secureWrappers['axios'] = secureAxiosWrapper
1570+
1571+
// Node Fetch
1572+
const secureNodeFetch = async (url: string, options: any = {}) => {
1573+
return await secureFetch(url, options)
1574+
}
1575+
secureWrappers['node-fetch'] = secureNodeFetch
15511576

15521577
const defaultNodeVMOptions: any = {
15531578
console: 'inherit',
15541579
sandbox,
15551580
require: {
1556-
external: { modules: deps },
1557-
builtin: builtinDeps
1581+
external: {
1582+
modules: deps,
1583+
transitive: false // Prevent transitive dependencies
1584+
},
1585+
builtin: builtinDeps,
1586+
mock: secureWrappers // Replace HTTP libraries with secure wrappers
15581587
},
15591588
eval: false,
15601589
wasm: false,

0 commit comments

Comments
 (0)