Skip to content

Commit 3941be6

Browse files
committed
fix: available dependencies in sandbox
1 parent a82edce commit 3941be6

5 files changed

Lines changed: 63 additions & 14 deletions

File tree

docker/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ PORT=3000
4141
# LOG_SANITIZE_BODY_FIELDS=password,pwd,pass,secret,token,apikey,api_key,accesstoken,access_token,refreshtoken,refresh_token,clientsecret,client_secret,privatekey,private_key,secretkey,secret_key,auth,authorization,credential,credentials
4242
# LOG_SANITIZE_HEADER_FIELDS=authorization,x-api-key,x-auth-token,cookie
4343
# TOOL_FUNCTION_BUILTIN_DEP=crypto,fs
44-
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash
44+
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash,pg,mysql2,mongodb,ioredis,redis,typeorm,puppeteer,playwright,@zilliz/milvus2-sdk-node
4545
# ALLOW_BUILTIN_DEP=false
4646

4747

docker/worker/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ WORKER_PORT=5566
4141
# LOG_SANITIZE_BODY_FIELDS=password,pwd,pass,secret,token,apikey,api_key,accesstoken,access_token,refreshtoken,refresh_token,clientsecret,client_secret,privatekey,private_key,secretkey,secret_key,auth,authorization,credential,credentials
4242
# LOG_SANITIZE_HEADER_FIELDS=authorization,x-api-key,x-auth-token,cookie
4343
# TOOL_FUNCTION_BUILTIN_DEP=crypto,fs
44-
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash
44+
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash,pg,mysql2,mongodb,ioredis,redis,typeorm,puppeteer,playwright,@zilliz/milvus2-sdk-node
4545
# ALLOW_BUILTIN_DEP=false
4646

4747

packages/components/src/utils.test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { removeInvalidImageMarkdown, convertRequireToImport, COMMONJS_REQUIRE_REGEX, IMPORT_EXTRACTION_REGEX } from './utils'
1+
import {
2+
removeInvalidImageMarkdown,
3+
convertRequireToImport,
4+
COMMONJS_REQUIRE_REGEX,
5+
IMPORT_EXTRACTION_REGEX,
6+
executeJavaScriptCode
7+
} from './utils'
28

39
describe('removeInvalidImageMarkdown', () => {
410
describe('strips non-http/https image markdown', () => {
@@ -229,3 +235,55 @@ describe('Import extraction regex (utils.ts line 1596 pattern)', () => {
229235
expect(extractModules('console.log("hello")')).toEqual([])
230236
})
231237
})
238+
239+
// ---------------------------------------------------------------------------
240+
// NodeVM sandbox — availableDependencies allowlist
241+
// ---------------------------------------------------------------------------
242+
243+
describe('NodeVM sandbox — availableDependencies allowlist', () => {
244+
afterEach(() => {
245+
delete process.env.ALLOW_BUILTIN_DEP
246+
delete process.env.TOOL_FUNCTION_EXTERNAL_DEP
247+
})
248+
249+
describe('high-risk packages are blocked even when ALLOW_BUILTIN_DEP=true', () => {
250+
beforeEach(() => {
251+
process.env.ALLOW_BUILTIN_DEP = 'true'
252+
})
253+
254+
const removedPackages = [
255+
'pg',
256+
'mysql2',
257+
'mongodb',
258+
'ioredis',
259+
'redis',
260+
'typeorm',
261+
'puppeteer',
262+
'playwright',
263+
'@zilliz/milvus2-sdk-node'
264+
]
265+
266+
test.each(removedPackages)(
267+
"require('%s') is denied",
268+
async (pkg) => {
269+
await expect(
270+
executeJavaScriptCode(`const m = require('${pkg}'); return 'loaded'`, {}, { timeout: 10000 })
271+
).rejects.toThrow()
272+
},
273+
15000
274+
)
275+
})
276+
277+
it('packages remaining in availableDependencies are still accessible with ALLOW_BUILTIN_DEP=true', async () => {
278+
process.env.ALLOW_BUILTIN_DEP = 'true'
279+
const result = await executeJavaScriptCode(`const cheerio = require('cheerio'); return typeof cheerio.load`, {}, { timeout: 10000 })
280+
expect(result).toBe('function')
281+
}, 15000)
282+
283+
it('a removed package becomes accessible via TOOL_FUNCTION_EXTERNAL_DEP', async () => {
284+
process.env.ALLOW_BUILTIN_DEP = 'true'
285+
process.env.TOOL_FUNCTION_EXTERNAL_DEP = 'pg'
286+
const result = await executeJavaScriptCode(`const { Client } = require('pg'); return typeof Client`, {}, { timeout: 10000 })
287+
expect(result).toBe('function')
288+
}, 15000)
289+
})

packages/components/src/utils.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export const availableDependencies = [
8686
'@qdrant/js-client-rest',
8787
'@supabase/supabase-js',
8888
'@upstash/redis',
89-
'@zilliz/milvus2-sdk-node',
9089
'apify-client',
9190
'cheerio',
9291
'chromadb',
@@ -97,32 +96,24 @@ export const availableDependencies = [
9796
'google-auth-library',
9897
'graphql',
9998
'html-to-text',
100-
'ioredis',
10199
'langchain',
102100
'langfuse',
103101
'langsmith',
104102
'langwatch',
105103
'linkifyjs',
106104
'lunary',
107105
'mammoth',
108-
'mongodb',
109-
'mysql2',
110106
'node-html-markdown',
111107
'notion-to-md',
112108
'openai',
113109
'pdf-parse',
114110
'pdfjs-dist',
115-
'pg',
116-
'playwright',
117-
'puppeteer',
118-
'redis',
119111
'replicate',
120112
'srt-parser-2',
121-
'typeorm',
122113
'weaviate-client'
123114
]
124115

125-
const defaultAllowExternalDependencies = ['axios', 'moment', 'node-fetch']
116+
const defaultAllowExternalDependencies = ['axios', 'node-fetch']
126117

127118
export const defaultAllowBuiltInDep = ['assert', 'buffer', 'crypto', 'events', 'path', 'querystring', 'timers', 'url', 'zlib']
128119

packages/server/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ PORT=3000
4141
# LOG_SANITIZE_BODY_FIELDS=password,pwd,pass,secret,token,apikey,api_key,accesstoken,access_token,refreshtoken,refresh_token,clientsecret,client_secret,privatekey,private_key,secretkey,secret_key,auth,authorization,credential,credentials
4242
# LOG_SANITIZE_HEADER_FIELDS=authorization,x-api-key,x-auth-token,cookie
4343
# TOOL_FUNCTION_BUILTIN_DEP=crypto,fs
44-
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash
44+
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash,pg,mysql2,mongodb,ioredis,redis,typeorm,puppeteer,playwright,@zilliz/milvus2-sdk-node
4545
# ALLOW_BUILTIN_DEP=false
4646

4747

0 commit comments

Comments
 (0)