fix: apply security patches for configuration file and local executor
Some checks failed
build / build (pull_request) Failing after 37s
build / trigger-build-image (pull_request) Has been skipped

This commit is contained in:
蔡雨翔524370910013 2026-03-12 21:41:06 +08:00
parent 0a5b3bdc71
commit 0a2d783dcd
2 changed files with 22 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"strings"
"syscall"
"github.com/go-git/go-git/v5"
"github.com/koding/multiconfig"
@ -183,6 +184,19 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
return confPath, confStat, conventionalCommit, err
}
}
// Check file ownership
if stat, ok := confStat.Sys().(*syscall.Stat_t); ok {
uid := int(stat.Uid)
currentUid := os.Getuid()
if uid != 0 && uid != currentUid {
err = fmt.Errorf("insecure configuration file: owned by uid %d, expected 0 or %d", uid, currentUid)
slog.Error("insecure conf file", "path", confPath, "uid", uid, "expected_uid", currentUid)
return confPath, confStat, conventionalCommit, err
}
} else {
slog.Warn("could not determine file ownership, proceeding with caution", "path", confPath)
}
return confPath, confStat, conventionalCommit, err
}

View File

@ -3,12 +3,18 @@
// used for passing run time parameters.
package local
import "github.com/joint-online-judge/JOJ3/internal/stage"
import (
"os"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
var name = "local"
type Local struct{}
func init() {
if os.Getenv("JOJ3_ENABLE_LOCAL_EXECUTOR") == "true" {
stage.RegisterExecutor(name, &Local{})
}
}