Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8263 fix(agents): reject reserved custom arguments on save (#9560)

mrlonely73f5664ca483
diff --git a/apps/docs/content/docs/agents-create.mdx b/apps/docs/content/docs/agents-create.mdx
index 5e9eda24ef..cb7647985f 100644
--- a/apps/docs/content/docs/agents-create.mdx
+++ b/apps/docs/content/docs/agents-create.mdx
@@ -140,6 +140,8 @@ Critical runtime variables such as `PATH`, `HOME`, and `MULTICA_*` cannot be ove
Custom arguments are passed to the AI coding tool as an array, item by item, without shell expansion. Whether an argument is valid is up to the tool; model configuration that already has a dedicated field doesn't need to be repeated here.
+Arguments reserved by the runtime adapter are rejected when creating an agent, editing its custom arguments, or changing its runtime. The error names the conflicting argument. For example, Multica runs Claude Code with `--permission-mode bypassPermissions`; setting `--permission-mode dontAsk` in custom arguments is rejected. Clearing custom arguments with `[]` allows a runtime change when the saved arguments conflict with the target runtime.
+
<Callout type="warning">
Do not put credentials or other secrets in custom arguments. They remain in the child process's argv and may be visible to other local processes through `ps` or `/proc`; use environment variables (`custom_env`) instead. Daemon logs redact argument values, but that does not protect the operating system's process list.
</Callout>
diff --git a/apps/docs/content/docs/agents-create.zh.mdx b/apps/docs/content/docs/agents-create.zh.mdx
index 129e8e9a0c..8684279e9b 100644
--- a/apps/docs/content/docs/agents-create.zh.mdx
+++ b/apps/docs/content/docs/agents-create.zh.mdx
@@ -140,6 +140,8 @@ Access 决定哪些成员可以运行这名智能体(分配、@提及或对话
自定义参数按数组逐项传给 AI 编程工具,不经过 shell 展开。参数名称是否有效由对应工具决定;已有独立字段的模型配置不需要在这里重复设置。
+创建智能体、修改自定义参数或更换运行时时,运行时适配器保留的参数会被拒绝,错误信息会指出冲突的参数。例如,Multica 使用 `--permission-mode bypassPermissions` 运行 Claude Code,在自定义参数里设置 `--permission-mode dontAsk` 会被拒绝。已保存的参数与目标运行时冲突时,可以同时传入 `[]` 清空自定义参数,再完成更换。
+
<Callout type="warning">
不要把凭据或其他 secret 放进自定义参数。它们会留在子进程的 argv 中,同机其他进程可能通过 `ps` 或 `/proc` 看到;请改用环境变量(`custom_env`)。守护进程日志会遮蔽参数值,但无法保护操作系统的进程列表。
</Callout>
diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.go
index 9261cb5c14..e08bcc2ddc 100644
--- a/server/internal/handler/agent.go
+++ b/server/internal/handler/agent.go
@@ -1512,6 +1512,10 @@ func (h *Handler) CreateAgent(w http.ResponseWriter, r *http.Request) {
return
}
+ if err := agent.ValidateCustomArgs(runtime.Provider, req.CustomArgs); err != nil {
+ writeError(w, http.StatusBadRequest, err.Error())
+ return
+ }
if runtime.Provider == "qoder_cloud" {
raw, _ := json.Marshal(req.RuntimeConfig)
if err := validateQoderAgentConfig(raw); err != nil {
@@ -2103,6 +2107,21 @@ func (h *Handler) UpdateAgent(w http.ResponseWriter, r *http.Request) {
return
}
}
+ if req.CustomArgs != nil || req.RuntimeID != nil {
+ var customArgs []string
+ if req.CustomArgs != nil {
+ customArgs = *req.CustomArgs
+ } else if len(existing.CustomArgs) > 0 {
+ if err := json.Unmarshal(existing.CustomArgs, &customArgs); err != nil {
+ writeError(w, http.StatusInternalServerError, "failed to read existing custom_args")
+ return
+ }
+ }
+ if err := agent.ValidateCustomArgs(provider, customArgs); err != nil {
+ writeError(w, http.StatusBadRequest, err.Error())
+ return
+ }
+ }
if provider == "qoder_cloud" {
if runtimeChange {
raw := existing.RuntimeConfig
diff --git a/server/internal/handler/agent_custom_args_test.go b/server/internal/handler/agent_custom_args_test.go
new file mode 100644
index 0000000000..fd3c8c8559
--- /dev/null
+++ b/server/internal/handler/agent_custom_args_test.go
@@ -0,0 +1,107 @@
+package handler
+
+import (
+ "encoding/json"
+ "net/http"
+ "reflect"
+ "strings"
+ "testing"
+
+ "github.com/multica-ai/multica/server/internal/testutil"
+)
+
+func TestCreateAgent_CustomArgs(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+ claudeID := dbfx.Runtime(t, "custom-args-claude", testutil.Cols{"provider": "claude"})
+ ompID := dbfx.Runtime(t, "custom-args-omp", testutil.Cols{"provider": "omp"})
+ piID := dbfx.Runtime(t, "custom-args-pi", testutil.Cols{"provider": "pi"})
+ for _, tc := range []struct {
+ name string
+ runtimeID string
+ args []string
+ want int
+ rejectedFlag string
+ }{
+ {"permission mode", claudeID, []string{"--permission-mode", "dontAsk", "--tools", "Bash"}, http.StatusBadRequest, "--permission-mode"},
+ {"inline permission mode", claudeID, []string{"--permission-mode=dontAsk"}, http.StatusBadRequest, "--permission-mode"},
+ {"quoted permission mode", claudeID, []string{"'--permission-mode'", "dontAsk"}, http.StatusBadRequest, "--permission-mode"},
+ {"allowed arguments", claudeID, []string{"--tools", "Bash", "--allowedTools", "Bash(multica issue *)"}, http.StatusCreated, ""},
+ {"empty arguments", claudeID, []string{}, http.StatusCreated, ""},
+ {"omp no session", ompID, []string{"--no-session"}, http.StatusBadRequest, "--no-session"},
+ {"omp inline session directory", ompID, []string{"--session-dir=/other"}, http.StatusBadRequest, "--session-dir"},
+ {"omp quoted resume", ompID, []string{"'--resume'", "other"}, http.StatusBadRequest, "--resume"},
+ {"pi no session", piID, []string{"--no-session"}, http.StatusCreated, ""},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ name := "custom-args-create-" + tc.name
+ dbfx.Cleanup(t, `DELETE FROM agent WHERE workspace_id = $1 AND name = $2`, testWorkspaceID, name)
+ w := testutil.Call(t, testHandler.CreateAgent, newRequest(http.MethodPost, "/api/agents", map[string]any{
+ "name": name, "runtime_id": tc.runtimeID, "custom_args": tc.args,
+ })).Want(tc.want)
+ if tc.want == http.StatusBadRequest {
+ if !strings.Contains(w.Body.String(), tc.rejectedFlag) {
+ t.Fatalf("error must identify the rejected flag: %s", w.Body.String())
+ }
+ if count := dbfx.Count(t, `SELECT count(*) FROM agent WHERE workspace_id = $1 AND name = $2`, testWorkspaceID, name); count != 0 {
+ t.Fatalf("rejected create persisted %d agents", count)
+ }
+ }
+ })
+ }
+}
+
+func TestUpdateAgent_CustomArgs(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+ claudeID := dbfx.Runtime(t, "custom-args-claude", testutil.Cols{"provider": "claude"})
+ codexID := dbfx.Runtime(t, "custom-args-codex", testutil.Cols{"provider": "codex"})
+ ompID := dbfx.Runtime(t, "custom-args-omp", testutil.Cols{"provider": "omp"})
+ piID := dbfx.Runtime(t, "custom-args-pi", testutil.Cols{"provider": "pi"})
+ allowed := []string{"--verbose"}
+ blocked := []string{"--permission-mode", "dontAsk"}
+ ompBlocked := []string{"--no-session"}
+ for _, tc := range []struct {
+ name string
+ runtimeID string
+ storedArgs []string
+ body map[string]any
+ want int
+ wantArgs []string
+ }{
+ {"reject update", claudeID, allowed, map[string]any{"custom_args": blocked}, http.StatusBadRequest, allowed},
+ {"reject runtime switch", codexID, blocked, map[string]any{"runtime_id": claudeID}, http.StatusBadRequest, blocked},
+ {"switch and clear", codexID, blocked, map[string]any{"runtime_id": claudeID, "custom_args": []string{}}, http.StatusOK, []string{}},
+ {"repair existing args", claudeID, blocked, map[string]any{"custom_args": allowed}, http.StatusOK, allowed},
+ {"rename existing agent", claudeID, blocked, map[string]any{"name": "custom-args-renamed"}, http.StatusOK, blocked},
+ {"reject omp update", ompID, allowed, map[string]any{"custom_args": ompBlocked}, http.StatusBadRequest, allowed},
+ {"reject omp runtime switch", piID, ompBlocked, map[string]any{"runtime_id": ompID}, http.StatusBadRequest, ompBlocked},
+ {"omp switch and clear", piID, ompBlocked, map[string]any{"runtime_id": ompID, "custom_args": []string{}}, http.StatusOK, []string{}},
+ {"repair omp args", ompID, ompBlocked, map[string]any{"custom_args": allowed}, http.StatusOK, allowed},
+ {"allow pi session args", piID, allowed, map[string]any{"custom_args": ompBlocked}, http.StatusOK, ompBlocked},
+ {"switch from omp to pi", ompID, ompBlocked, map[string]any{"runtime_id": piID}, http.StatusOK, ompBlocked},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ stored, err := json.Marshal(tc.storedArgs)
+ if err != nil {
+ t.Fatal(err)
+ }
+ id := dbfx.Agent(t, "custom-args-update-"+tc.name, tc.runtimeID, testutil.Cols{"custom_args": stored})
+ testutil.Call(t, testHandler.UpdateAgent, withURLParam(newRequest(http.MethodPut, "/api/agents/"+id, tc.body), "id", id)).Want(tc.want)
+ var runtimeID string
+ var args []string
+ dbfx.QueryRow(t, `SELECT runtime_id::text, custom_args FROM agent WHERE id = $1`, id).Scan(&runtimeID, &args)
+ if !reflect.DeepEqual(args, tc.wantArgs) {
+ t.Fatalf("stored args = %v, want %v", args, tc.wantArgs)
+ }
+ if tc.want == http.StatusBadRequest && runtimeID != tc.runtimeID {
+ t.Fatalf("rejected update changed runtime to %s", runtimeID)
+ }
+ if tc.want == http.StatusOK && tc.body["runtime_id"] != nil && runtimeID != tc.body["runtime_id"] {
+ t.Fatalf("runtime = %s, want %s", runtimeID, tc.body["runtime_id"])
+ }
+ })
+ }
+}
diff --git a/server/pkg/agent/launch.go b/server/pkg/agent/launch.go
index fd510849a4..a7009234dd 100644
--- a/server/pkg/agent/launch.go
+++ b/server/pkg/agent/launch.go
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
+ "fmt"
"log/slog"
"os/exec"
"strings"
@@ -455,6 +456,8 @@ var launchPrefixBlockedArgs = map[string]map[string]blockedArgMode{
"hermes": hermesBlockedArgs,
"kimi": kimiBlockedArgs,
"kiro": kiroBlockedArgs,
+ "mcode": mcodeBlockedArgs,
+ "muse": museBlockedArgs,
"opencode": opencodeBlockedArgs,
"openclaw": openclawBlockedArgs,
"pi": piBlockedArgs,
@@ -469,6 +472,30 @@ var launchPrefixBlockedArgs = map[string]map[string]blockedArgMode{
"zeroclaw": zeroclawBlockedArgs,
}
+// ValidateCustomArgs rejects arguments that the runtime always discards at launch.
+func ValidateCustomArgs(agentType string, args []string) error {
+ protocolFamily := agentType
+ if family, ok := RuntimeProtocolFamily(agentType); ok {
+ protocolFamily = family
+ }
+ blocked := launchPrefixBlockedArgs[protocolFamily]
+ for _, arg := range args {
+ flag := unshellQuoteArg(arg)
+ if idx := strings.Index(flag, "="); idx > 0 {
+ flag = flag[:idx]
+ }
+ _, isBlocked := blocked[flag]
+ if agentType == "omp" {
+ _, sessionArg := ompSessionArgs[flag]
+ isBlocked = isBlocked || sessionArg
+ }
+ if isBlocked {
+ return fmt.Errorf("custom_args: %q is managed by Multica for runtime %q and cannot be overridden; remove it from custom_args", flag, agentType)
+ }
+ }
+ return nil
+}
+
// FilterLaunchPrefix is the exported form for callers outside this package —
// the daemon, which builds Commands for CLI probes that never reach New.
// Without it a `--version` probe and a task launch would disagree about what
diff --git a/server/pkg/agent/launch_test.go b/server/pkg/agent/launch_test.go
index ad9ad4fc69..2f4d05f5d5 100644
--- a/server/pkg/agent/launch_test.go
+++ b/server/pkg/agent/launch_test.go
@@ -22,6 +22,57 @@ func prefixIndex(argv, want []string) int {
return -1
}
+func TestValidateCustomArgs(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ provider string
+ args []string
+ flag string
+ }{
+ {"permission mode", "claude", []string{"--permission-mode", "dontAsk"}, "--permission-mode"},
+ {"inline permission mode", "claude", []string{"--permission-mode='dontAsk'"}, "--permission-mode"},
+ {"quoted permission mode", "claude", []string{"\"--permission-mode=dontAsk\""}, "--permission-mode"},
+ {"protocol flag", "codex", []string{"--listen", "ws://localhost:1234"}, "--listen"},
+ {"builtin alias", "omp", []string{"--mode", "rpc"}, "--mode"},
+ {"omp session", "omp", []string{"--session", "other"}, "--session"},
+ {"omp session directory", "omp", []string{"--session-dir", "/other"}, "--session-dir"},
+ {"omp no session", "omp", []string{"--no-session"}, "--no-session"},
+ {"omp continue", "omp", []string{"--continue"}, "--continue"},
+ {"omp continue alias", "omp", []string{"-c"}, "-c"},
+ {"omp resume", "omp", []string{"--resume"}, "--resume"},
+ {"omp resume alias", "omp", []string{"-r", "other"}, "-r"},
+ {"omp fork", "omp", []string{"--fork", "other"}, "--fork"},
+ {"omp session id", "omp", []string{"--session-id", "other"}, "--session-id"},
+ {"omp inline session directory", "omp", []string{"--session-dir='/other'"}, "--session-dir"},
+ {"omp quoted resume", "omp", []string{"\"--resume=other\""}, "--resume"},
+ {"pi session options", "pi", []string{"--session-dir", "/other", "--no-session", "--continue", "-c", "--resume", "-r", "--fork", "other", "--session-id", "other"}, ""},
+ {"omp allowed flags", "omp", []string{"--tools", "read"}, ""},
+ {"blocked subcommand", "mcode", []string{"login"}, "login"},
+ {"wire permission mode", "muse", []string{"--yolo"}, "--yolo"},
+ {"allowed flags", "claude", []string{"--tools", "Bash", "--allowedTools", "Bash(multica issue *)"}, ""},
+ {"other provider", "codex", []string{"--permission-mode", "dontAsk"}, ""},
+ {"unknown provider", "custom", []string{"--permission-mode", "dontAsk"}, ""},
+ {"empty args", "claude", nil, ""},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ err := ValidateCustomArgs(tc.provider, tc.args)
+ if tc.flag == "" {
+ if err != nil {
+ t.Fatal(err)
+ }
+ return
+ }
+ if err == nil || !strings.Contains(err.Error(), tc.flag) {
+ t.Fatalf("error = %v, want rejection naming %q", err, tc.flag)
+ }
+ if tc.provider == "omp" && !strings.Contains(err.Error(), `runtime "omp"`) {
+ t.Fatalf("error must identify the OMP runtime: %v", err)
+ }
+ })
+ }
+}
+
// TestLaunchPrefixPrecedesProtocolFlags is GH #7046 in one assertion. `ccms
// start q36` only reaches the real Claude binary after its `start` subcommand
// is selected, so a `-p` that arrives first is parsed by the wrapper, which
@@ -101,6 +152,24 @@ func TestFilterLaunchPrefixKeepsSubcommandsDropsProtocolFlags(t *testing.T) {
}
}
+func TestFilterLaunchPrefixMcodeAndMuse(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ provider string
+ prefix []string
+ want []string
+ }{
+ {"mcode", []string{"acp", "--region", "test-region"}, []string{"acp"}},
+ {"muse", []string{"serve", "--yolo"}, []string{"serve"}},
+ } {
+ t.Run(tc.provider, func(t *testing.T) {
+ if got := FilterLaunchPrefix(tc.provider, tc.prefix, slog.Default()); !slices.Equal(got, tc.want) {
+ t.Fatalf("prefix = %v, want %v", got, tc.want)
+ }
+ })
+ }
+}
+
// TestNewFiltersLaunchPrefixOnce proves the filter runs at the single point
// that knows the protocol family, so no backend has to remember to call it.
func TestNewFiltersLaunchPrefixOnce(t *testing.T) {