Merge commit from fork

* fix(actions): prevent disk access via require

* add test to ensure native modules are still possible
This commit is contained in:
Livio Spring
2026-07-17 08:23:31 +02:00
committed by GitHub
parent 94ac4237a9
commit baf6ed501b
2 changed files with 43 additions and 2 deletions
+7 -2
View File
@@ -16,7 +16,10 @@ type Config struct {
HTTP HTTPConfig
}
var ErrHalt = errors.New("interrupt")
var (
ErrHalt = errors.New("interrupt")
ErrFileLoad = errors.New("file-based modules are disabled")
)
type jsAction func(fields, fields) error
@@ -88,7 +91,9 @@ func executeScript(config *runConfig, ctxParam contextFields, apiParam apiFields
apiParam(config.apiParam)
}
registry := new(require.Registry)
registry := require.NewRegistryWithLoader(func(path string) ([]byte, error) {
return nil, ErrFileLoad
})
registry.Enable(config.vm)
for name, loader := range config.modules {
+36
View File
@@ -3,6 +3,7 @@ package actions
import (
"context"
"errors"
"strings"
"testing"
"time"
@@ -56,6 +57,41 @@ function testFunc() {
return false
},
},
{
name: "require file is disabled",
args: args{
api: nil,
script: `
require('./some-file.js');
function testFunc() {}`,
name: "testFunc",
opts: []Option{},
},
wantErr: func(err error) bool {
gojaErr := new(goja.Exception)
if errors.As(err, &gojaErr) {
return strings.Contains(gojaErr.Value().String(), ErrFileLoad.Error())
}
return false
},
},
{
name: "require custom module still possible",
args: args{
api: nil,
script: `
require('zitadel/http');
function testFunc() {}`,
name: "testFunc",
opts: []Option{
// We need to pass the option to allow loading the module via require('zitadel/http') in the script.
// Otherwise, the loader will assume it's a file and fail.
// No client is needed here, because the module is not used.
WithHTTP(context.Background(), nil),
},
},
wantErr: func(err error) bool { return err == nil },
},
}
for _, tt := range tests {