fix: apply security patches for configuration file and local executor #97
No reviewers
Labels
No Label
bug
component
executor
component
framework
component
parser
component
UI
duplicate
enhancement
help wanted
invalid
priority
p0
priority
p1
priority
p2
priority
p3
question
wontfix
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: JOJ/JOJ3#97
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "arthurcai/JOJ3:master"
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?
Privilege Escalation through Hacking Configuration File (
localexecutor)**A student can add files as
.gitea/workflows/*.yamlas configuration. They can invokejoj3with custom-conf-rootand-conf-namearguments pointing to files within their own workspace.A student can provide a malicious
conf.jsonusing yaml executing bash commands that uses thelocalexecutor. Thelocalexecutor bypasses thego-judgesandbox and runs arbitrary shell commands directly viaexec.Command. Sincejoj3is running as the privilegedttuser, the attacker gains full code execution astt, allowing them to steal secrets (e.g.,~/.config), tokens, or write to arbitrary locations.Even if
push.yamlis locked and specifies-conf-root /home/tt/.config/joj/push, the vulnerability is exploitable via-fallback-conf-nameand-conf-name. By providing a-fallback-conf-name,joj3's [GetConfPath()] will fail to findconf.jsonunder the lockedconfRoot(because the student can commit an invalid scope), and it will execute the fallback logicfilepath.Join(confRoot, fallbackConfName). This path manipulation escapes the locked root directory and executes the malicious JSON file sitting in the student's repository.The above is tried and realized in this action. The above is written partly by Artificial Intelligence.
The code is used to fix the bug.
WIP: fix: apply security patches for configuration file and local executorto fix: apply security patches for configuration file and local executor@ -186,0 +194,4 @@return confPath, confStat, conventionalCommit, err}} else {slog.Warn("could not determine file ownership, proceeding with caution", "path", confPath)What if we just terminate it here?
maybe end + write logs to raise an alert on grafana?
@ -11,3 +15,3 @@func init() {stage.RegisterExecutor(name, &Local{})if os.Getenv("JOJ3_ENABLE_LOCAL_EXECUTOR") == "true" {Where is it used?
Just thinking that the Local executor is unsafe if conf.go is bypassed, so you can add an env for the students' executor so that it doesn't run the local executor, while other usages can still be fulfilled.
What does it mean by students' executor?
I found that I'm wrong. Many stages seem to use the local executor.
This part is not needed.
@ -186,0 +188,4 @@if stat, ok := confStat.Sys().(*syscall.Stat_t); ok {uid := int(stat.Uid)currentUid := os.Getuid()if uid != 0 && uid != currentUid {Will the conf file be owned by root?
i was wondering the same: we have
studentandtt. i think no other user (includingroot) is involved.Then uid != 0 is not needed.
Pull request closed