mirror of
https://github.com/langgenius/dify-sandbox.git
synced 2026-07-25 21:46:12 -04:00
[PR #204] fix: fix nodejs env missing some system call #206
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/langgenius/dify-sandbox/pull/204
Author: @fatelei
Created: 12/29/2025
Status: 🔄 Open
Base:
main← Head:system_call📝 Commits (1)
02ef5fafix: fix nodejs env missing some system call📊 Changes
9 files changed (+213 additions, -37 deletions)
View changed files
📝
docker/templates/base.dockerfile(+1 -0)📝
docker/templates/production.dockerfile(+2 -0)📝
internal/core/lib/seccomp.go(+44 -5)📝
internal/core/runner/nodejs/nodejs.go(+4 -0)📝
internal/core/runner/nodejs/prescript.js(+27 -0)📝
internal/static/nodejs_syscall/syscalls_amd64.go(+49 -20)📝
internal/static/nodejs_syscall/syscalls_arm64.go(+81 -3)📝
tests/integration_tests/nodejs_malicious_test.go(+1 -1)📝
tests/integration_tests/python_malicious_test.go(+4 -8)📄 Description
fix issue https://github.com/langgenius/dify/issues/28932
The Problem with ActKillProcess
ActKillProcess has issues with the TSYNC flag (synchronizes filter across threads) that causes spurious process kills. This appears to be a known issue with libseccomp or kernel behavior in certain scenarios.
The Solution
Use ActErrno.SetReturnCode(1) which:
internal/static/nodejs_syscall/syscalls_amd64.go
For newer syscalls like clone3 (435), rseq (293), statx (291), and io_uring (425-427):
This FAILS with libseccomp 2.6.0:
syscall, _ := sg.GetSyscallFromName("clone3")
ctx.AddRule(syscall, sg.ActAllow) // Error!
This WORKS - using raw number:
ctx.AddRule(sg.ScmpSyscall(435), sg.ActAllow) // Success
Reason: libseccomp 2.6.0 has a known limitation where it can resolve the syscall name but fails to add the rule for newer syscalls. Using raw syscall numbers bypasses this bug.
After chroot(), the filesystem root changes. Node.js's TLS modules (https, undici/fetch) expect CA certificates at:
While these files are copied into the chroot via REQUIRED_FS, Node.js doesn't automatically find them in the chrooted environment.
The Solution
Two-layer approach:
Environment variable (nodejs.go):
cmd.Env = append(cmd.Env, "NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt"), Helps https module find certificates
Explicit configuration (prescript.js):
const caCert = fs.readFileSync('/etc/ssl/certs/ca-certificates.crt', 'utf8')
For https module
https.globalAgent.options.ca = caCert
For undici (fetch)
const { setGlobalDispatcher, Agent } = globalThis.undici
const agent = new Agent({ connect: { ca: caCert } })
setGlobalDispatcher(agent)
Ensures fetch (undici) can verify TLS certificates
Why Both Are Needed
before bugfix
test below
in amd64 env
in arm64 env
in docker env
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.