Skip to content

Commit

Permalink
refactor: Fix sandbox escape by disabling the preload parameter. (#96)
Browse files Browse the repository at this point in the history
* refactor: Fix sandbox escape by disabling the preload parameter.

* Update python.go

* Update nodejs.go

* Update config.go

* refactor: Fix sandbox escape by disabling the preload parameter.

* Update config.go

* update

* update
  • Loading branch information
hexian2001 authored Oct 16, 2024
1 parent 3e39e12 commit 3a73859
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ max_requests: 50
worker_timeout: 5
python_path: /usr/local/bin/python3
enable_network: True # please make sure there is no network risk in your environment
enable_preload: False # please keep it as False for security purposes
allowed_syscalls: # please leave it empty if you have no idea how seccomp works
proxy:
socks5: ''
Expand Down
5 changes: 5 additions & 0 deletions internal/service/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func RunNodeJsCode(code string, preload string, options *runner_types.RunnerOpti
return types.ErrorResponse(-400, err.Error())
}


if !static.GetDifySandboxGlobalConfigurations().EnablePreload {
preload = ""
}

timeout := time.Duration(
static.GetDifySandboxGlobalConfigurations().WorkerTimeout * int(time.Second),
)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func RunPython3Code(code string, preload string, options *runner_types.RunnerOpt
return types.ErrorResponse(-400, err.Error())
}

if !static.GetDifySandboxGlobalConfigurations().EnablePreload {
preload = ""
}

timeout := time.Duration(
static.GetDifySandboxGlobalConfigurations().WorkerTimeout * int(time.Second),
)
Expand Down
5 changes: 5 additions & 0 deletions internal/static/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func InitConfig(path string) error {
difySandboxGlobalConfigurations.EnableNetwork, _ = strconv.ParseBool(enable_network)
}

enable_preload := os.Getenv("ENABLE_PRELOAD")
if enable_preload != "" {
difySandboxGlobalConfigurations.EnablePreload, _ = strconv.ParseBool(enable_preload)
}

allowed_syscalls := os.Getenv("ALLOWED_SYSCALLS")
if allowed_syscalls != "" {
strs := strings.Split(allowed_syscalls, ",")
Expand Down
3 changes: 2 additions & 1 deletion internal/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ type DifySandboxGlobalConfigurations struct {
PythonDepsUpdateInterval string `yaml:"python_deps_update_interval"`
NodejsPath string `yaml:"nodejs_path"`
EnableNetwork bool `yaml:"enable_network"`
EnablePreload bool `yaml:"enable_preload"`
AllowedSyscalls []int `yaml:"allowed_syscalls"`
Proxy struct {
Socks5 string `yaml:"socks5"`
Https string `yaml:"https"`
Http string `yaml:"http"`
} `yaml:"proxy"`
}
}

0 comments on commit 3a73859

Please sign in to comment.