Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(cli): redact autopilot webhook credentials (#7365)
iiwisha3bd38da6a69
diff --git a/apps/docs/content/docs/autopilots.ja.mdx b/apps/docs/content/docs/autopilots.ja.mdxindex 4c07660718..a18e4e7ada 100644--- a/apps/docs/content/docs/autopilots.ja.mdx+++ b/apps/docs/content/docs/autopilots.ja.mdx@@ -143,11 +143,14 @@ Multica は最近の実行が継続的に失敗していないか定期的に確## CLI を使う```bash+multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```+`autopilot get` はデフォルトで `webhook_token`、`webhook_path`、`webhook_url` を `null` にし、代わりに `has_webhook_token` と `webhook_token_hint` を返します。実際の認証情報が必要な場合に限り `--show-secrets` を追加してください。CLI は警告を stderr に出力するため、パイプされた JSON は有効なままです。+すべての引数は [CLI](/cli)を参照してください。## 次のステップdiff --git a/apps/docs/content/docs/autopilots.ko.mdx b/apps/docs/content/docs/autopilots.ko.mdxindex 3b1edef941..d40c51744c 100644--- a/apps/docs/content/docs/autopilots.ko.mdx+++ b/apps/docs/content/docs/autopilots.ko.mdx@@ -143,11 +143,14 @@ Multica는 최근 실행이 계속 실패하는지 정기적으로 확인합니## CLI 사용```bash+multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```+`autopilot get`은 기본적으로 `webhook_token`, `webhook_path`, `webhook_url`을 `null`로 설정하고 대신 `has_webhook_token`과 `webhook_token_hint`를 반환합니다. 실제 자격 증명이 꼭 필요할 때만 `--show-secrets`를 추가하세요. CLI는 경고를 stderr로 출력하므로 파이프로 전달되는 JSON은 유효하게 유지됩니다.+전체 인수는 [CLI 사용](/cli)을 참고하세요.## 다음 단계diff --git a/apps/docs/content/docs/autopilots.mdx b/apps/docs/content/docs/autopilots.mdxindex d4d451ddb8..1574359d6e 100644--- a/apps/docs/content/docs/autopilots.mdx+++ b/apps/docs/content/docs/autopilots.mdx@@ -143,11 +143,14 @@ Pausing manually stops schedules, webhooks, and **Run now**. Deletion is actuall## Use the CLI```bash+multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```+`autopilot get` sets `webhook_token`, `webhook_path`, and `webhook_url` to `null` by default, and returns `has_webhook_token` plus `webhook_token_hint` instead. Add `--show-secrets` only when you intentionally need the live credential; the CLI prints a warning to stderr so piped JSON stays valid.+See [Using the CLI](/cli) for the full parameters.## Next stepsdiff --git a/apps/docs/content/docs/autopilots.zh.mdx b/apps/docs/content/docs/autopilots.zh.mdxindex e9aaeb82da..63d7a74311 100644--- a/apps/docs/content/docs/autopilots.zh.mdx+++ b/apps/docs/content/docs/autopilots.zh.mdx@@ -143,11 +143,14 @@ Multica 会定期检查近期运行是否持续失败:过去 7 天内已完成## 使用 CLI```bash+multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```+`autopilot get` 默认把 `webhook_token`、`webhook_path` 和 `webhook_url` 设为 `null`,并返回 `has_webhook_token` 与 `webhook_token_hint`。只有确实需要获取当前有效凭证时才添加 `--show-secrets`;CLI 会把警告输出到 stderr,确保管道中的 JSON 仍然有效。+完整参数见[使用 CLI](/cli)。## 接下来diff --git a/server/cmd/multica/cmd_autopilot.go b/server/cmd/multica/cmd_autopilot.goindex d4db16a027..32c5ed59ff 100644--- a/server/cmd/multica/cmd_autopilot.go+++ b/server/cmd/multica/cmd_autopilot.go@@ -28,7 +28,7 @@ var autopilotListCmd = &cobra.Command{var autopilotGetCmd = &cobra.Command{Use: "get <id>",- Short: "Get autopilot details (includes triggers)",+ Short: "Get autopilot details (webhook credentials redacted by default)",Args: exactArgs(1),RunE: runAutopilotGet,}@@ -115,6 +115,7 @@ func init() {// getautopilotGetCmd.Flags().String("output", "json", "Output format: table or json")+ autopilotGetCmd.Flags().Bool("show-secrets", false, "Include live webhook credentials in JSON output (unsafe for logs)")// createautopilotCreateCmd.Flags().String("title", "", "Autopilot title (required)")@@ -223,6 +224,12 @@ func runAutopilotList(cmd *cobra.Command, _ []string) error {}func runAutopilotGet(cmd *cobra.Command, args []string) error {+ output, _ := cmd.Flags().GetString("output")+ showSecrets, _ := cmd.Flags().GetBool("show-secrets")+ if showSecrets && output != "json" {+ return fmt.Errorf("--show-secrets requires --output json")+ }+client, err := newAPIClient(cmd)if err != nil {return err@@ -241,7 +248,12 @@ func runAutopilotGet(cmd *cobra.Command, args []string) error {return fmt.Errorf("get autopilot: %w", err)}- output, _ := cmd.Flags().GetString("output")+ if showSecrets {+ fmt.Fprintln(os.Stderr, "Warning: --show-secrets exposes live webhook credentials; keep this output out of logs and shared transcripts.")+ } else {+ redactAutopilotWebhookCredentials(resp)+ }+if output == "json" {return cli.PrintJSON(os.Stdout, resp)}@@ -261,6 +273,49 @@ func runAutopilotGet(cmd *cobra.Command, args []string) error {return nil}+func redactAutopilotWebhookCredentials(resp map[string]any) {+ triggers, ok := resp["triggers"].([]any)+ if !ok {+ return+ }+ for _, raw := range triggers {+ trigger, ok := raw.(map[string]any)+ if !ok {+ continue+ }+ _, hasTokenField := trigger["webhook_token"]+ _, hasPathField := trigger["webhook_path"]+ _, hasURLField := trigger["webhook_url"]+ if !hasTokenField && !hasPathField && !hasURLField {+ continue+ }++ token := strVal(trigger, "webhook_token")+ hasToken, _ := trigger["has_webhook_token"].(bool)+ hasToken = hasToken ||+ strVal(trigger, "kind") == "webhook" ||+ token != "" ||+ strVal(trigger, "webhook_path") != "" ||+ strVal(trigger, "webhook_url") != ""+ trigger["has_webhook_token"] = hasToken+ if hint := webhookTokenHint(token); hint != "" {+ trigger["webhook_token_hint"] = hint+ } else {+ trigger["webhook_token_hint"] = nil+ }+ trigger["webhook_token"] = nil+ trigger["webhook_path"] = nil+ trigger["webhook_url"] = nil+ }+}++func webhookTokenHint(token string) string {+ if len(token) < 4 {+ return ""+ }+ return token[len(token)-4:]+}+func runAutopilotCreate(cmd *cobra.Command, _ []string) error {client, err := newAPIClient(cmd)if err != nil {diff --git a/server/cmd/multica/cmd_autopilot_test.go b/server/cmd/multica/cmd_autopilot_test.goindex c31fa3a2ba..e5a84efbea 100644--- a/server/cmd/multica/cmd_autopilot_test.go+++ b/server/cmd/multica/cmd_autopilot_test.go@@ -43,6 +43,262 @@ func newAutopilotUpdateTestCmd() *cobra.Command {return cmd}+func newAutopilotGetTestCmd() *cobra.Command {+ cmd := &cobra.Command{Use: "get"}+ cmd.Flags().String("output", "json", "")+ cmd.Flags().Bool("show-secrets", false, "")+ return cmd+}++func TestRunAutopilotGetRedactsWebhookCredentialsByDefault(t *testing.T) {+ const (+ autopilotID = "11111111-1111-1111-1111-111111111111"+ webhookToken = "awt_super-secret-7890"+ webhookPath = "/api/webhooks/autopilots/" + webhookToken+ webhookURL = "https://hooks.example.com" + webhookPath+ )++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/api/autopilots/"+autopilotID {+ http.NotFound(w, r)+ return+ }+ _ = json.NewEncoder(w).Encode(map[string]any{+ "autopilot": map[string]any{"id": autopilotID, "title": "Deploy"},+ "triggers": []map[string]any{+ {+ "id": "trigger-1",+ "kind": "webhook",+ "webhook_token": webhookToken,+ "webhook_path": webhookPath,+ "webhook_url": webhookURL,+ "has_signing_secret": true,+ "signing_secret_hint": "abcd",+ },+ },+ })+ }))+ defer srv.Close()++ t.Setenv("MULTICA_SERVER_URL", srv.URL)+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")+ t.Setenv("MULTICA_TOKEN", "test-token")++ out, err := captureStdout(t, func() error {+ return runAutopilotGet(newAutopilotGetTestCmd(), []string{autopilotID})+ })+ if err != nil {+ t.Fatalf("runAutopilotGet: %v", err)+ }+ for _, secret := range []string{webhookToken, webhookPath, webhookURL} {+ if strings.Contains(out, secret) {+ t.Fatalf("default output leaked webhook credential %q:\n%s", secret, out)+ }+ }++ var got map[string]any+ if err := json.Unmarshal([]byte(out), &got); err != nil {+ t.Fatalf("default output is not valid JSON: %v\n%s", err, out)+ }+ triggers, ok := got["triggers"].([]any)+ if !ok || len(triggers) != 1 {+ t.Fatalf("triggers = %#v, want one trigger", got["triggers"])+ }+ trigger, ok := triggers[0].(map[string]any)+ if !ok {+ t.Fatalf("trigger = %#v, want object", triggers[0])+ }+ for _, field := range []string{"webhook_token", "webhook_path", "webhook_url"} {+ if trigger[field] != nil {+ t.Errorf("%s = %#v, want null", field, trigger[field])+ }+ }+ if trigger["has_webhook_token"] != true {+ t.Errorf("has_webhook_token = %#v, want true", trigger["has_webhook_token"])+ }+ if trigger["webhook_token_hint"] != "7890" {+ t.Errorf("webhook_token_hint = %#v, want %q", trigger["webhook_token_hint"], "7890")+ }+ if trigger["signing_secret_hint"] != "abcd" {+ t.Errorf("signing_secret_hint = %#v, want existing non-credential metadata preserved", trigger["signing_secret_hint"])+ }+}++func TestRunAutopilotGetShowSecretsIsExplicitAndWarns(t *testing.T) {+ const (+ autopilotID = "11111111-1111-1111-1111-111111111111"+ webhookToken = "awt_super-secret-7890"+ webhookPath = "/api/webhooks/autopilots/" + webhookToken+ webhookURL = "https://hooks.example.com" + webhookPath+ )++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/api/autopilots/"+autopilotID {+ http.NotFound(w, r)+ return+ }+ _ = json.NewEncoder(w).Encode(map[string]any{+ "autopilot": map[string]any{"id": autopilotID, "title": "Deploy"},+ "triggers": []map[string]any{+ {+ "id": "trigger-1",+ "kind": "webhook",+ "webhook_token": webhookToken,+ "webhook_path": webhookPath,+ "webhook_url": webhookURL,+ },+ },+ })+ }))+ defer srv.Close()++ t.Setenv("MULTICA_SERVER_URL", srv.URL)+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")+ t.Setenv("MULTICA_TOKEN", "test-token")++ cmd := newAutopilotGetTestCmd()+ _ = cmd.Flags().Set("show-secrets", "true")+ stderr := captureStderr(t)+ out, err := captureStdout(t, func() error {+ return runAutopilotGet(cmd, []string{autopilotID})+ })+ errOut := stderr.read()+ if err != nil {+ t.Fatalf("runAutopilotGet: %v", err)+ }+ for _, secret := range []string{webhookToken, webhookPath, webhookURL} {+ if !strings.Contains(out, secret) {+ t.Errorf("--show-secrets output missing %q:\n%s", secret, out)+ }+ }+ if !strings.Contains(strings.ToLower(errOut), "warning") ||+ !strings.Contains(strings.ToLower(errOut), "webhook credentials") ||+ !strings.Contains(strings.ToLower(errOut), "logs") {+ t.Fatalf("stderr = %q, want credential exposure warning", errOut)+ }+ if strings.Contains(errOut, webhookToken) {+ t.Fatalf("warning itself leaked webhook token: %q", errOut)+ }+}++func TestRunAutopilotGetTableOutputDoesNotExposeWebhookCredentials(t *testing.T) {+ const (+ autopilotID = "11111111-1111-1111-1111-111111111111"+ webhookToken = "awt_super-secret-7890"+ )++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path != "/api/autopilots/"+autopilotID {+ http.NotFound(w, r)+ return+ }+ _ = json.NewEncoder(w).Encode(map[string]any{+ "autopilot": map[string]any{+ "id": autopilotID,+ "title": "Deploy",+ "status": "active",+ "execution_mode": "run_only",+ },+ "triggers": []map[string]any{+ {+ "id": "trigger-1",+ "kind": "webhook",+ "webhook_token": webhookToken,+ "webhook_path": "/api/webhooks/autopilots/" + webhookToken,+ "webhook_url": "https://hooks.example.com/api/webhooks/autopilots/" + webhookToken,+ },+ },+ })+ }))+ defer srv.Close()++ t.Setenv("MULTICA_SERVER_URL", srv.URL)+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")+ t.Setenv("MULTICA_TOKEN", "test-token")++ cmd := newAutopilotGetTestCmd()+ _ = cmd.Flags().Set("output", "table")+ out, err := captureStdout(t, func() error {+ return runAutopilotGet(cmd, []string{autopilotID})+ })+ if err != nil {+ t.Fatalf("runAutopilotGet: %v", err)+ }+ if strings.Contains(out, webhookToken) {+ t.Fatalf("table output leaked webhook token:\n%s", out)+ }+ if !strings.Contains(out, "Deploy") || !strings.Contains(out, "run_only") {+ t.Fatalf("table output lost ordinary autopilot details:\n%s", out)+ }+}++func TestRedactAutopilotWebhookCredentialsDoesNotDependOnTriggerKind(t *testing.T) {+ const webhookToken = "awt_schema-drift-secret-1234"+ trigger := map[string]any{+ "id": "trigger-1",+ "webhook_token": webhookToken,+ "webhook_path": "/api/webhooks/autopilots/" + webhookToken,+ "webhook_url": "https://hooks.example.com/api/webhooks/autopilots/" + webhookToken,+ }+ resp := map[string]any{"triggers": []any{trigger}}++ redactAutopilotWebhookCredentials(resp)++ for _, field := range []string{"webhook_token", "webhook_path", "webhook_url"} {+ if trigger[field] != nil {+ t.Errorf("%s = %#v, want null", field, trigger[field])+ }+ }+ if trigger["has_webhook_token"] != true || trigger["webhook_token_hint"] != "1234" {+ t.Fatalf("redaction metadata = has:%#v hint:%#v", trigger["has_webhook_token"], trigger["webhook_token_hint"])+ }+}++func TestRedactAutopilotWebhookCredentialsReportsServerRedactedToken(t *testing.T) {+ trigger := map[string]any{+ "id": "trigger-1",+ "kind": "webhook",+ "webhook_token": nil,+ "webhook_path": nil,+ "webhook_url": nil,+ }+ resp := map[string]any{"triggers": []any{trigger}}++ redactAutopilotWebhookCredentials(resp)++ if trigger["has_webhook_token"] != true {+ t.Fatalf("has_webhook_token = %#v, want true for a permission-redacted webhook", trigger["has_webhook_token"])+ }+ if trigger["webhook_token_hint"] != nil {+ t.Fatalf("webhook_token_hint = %#v, want null when the server withheld the token", trigger["webhook_token_hint"])+ }+}++func TestWebhookTokenHintDoesNotExposeShortToken(t *testing.T) {+ const shortToken = "abc"+ if hint := webhookTokenHint(shortToken); hint != "" {+ t.Fatalf("webhookTokenHint(%q) = %q, want empty hint", shortToken, hint)+ }+}++func TestRunAutopilotGetRejectsShowSecretsWithTableOutput(t *testing.T) {+ t.Setenv("MULTICA_SERVER_URL", "http://127.0.0.1")+ t.Setenv("MULTICA_WORKSPACE_ID", "ws-1")+ t.Setenv("MULTICA_TOKEN", "test-token")++ cmd := newAutopilotGetTestCmd()+ _ = cmd.Flags().Set("output", "table")+ _ = cmd.Flags().Set("show-secrets", "true")++ err := runAutopilotGet(cmd, []string{"11111111-1111-1111-1111-111111111111"})+ if err == nil {+ t.Fatal("expected --show-secrets with table output to fail")+ }+ if !strings.Contains(err.Error(), "--show-secrets requires --output json") {+ t.Fatalf("error = %v, want output-mode guidance", err)+ }+}+func TestResolveAgent(t *testing.T) {agentsResp := []map[string]any{{"id": "11111111-1111-1111-1111-111111111111", "name": "Lambda"},diff --git a/server/internal/service/builtin_skills/multica-autopilots/SKILL.md b/server/internal/service/builtin_skills/multica-autopilots/SKILL.mdindex b35790b35b..526542175e 100644--- a/server/internal/service/builtin_skills/multica-autopilots/SKILL.md+++ b/server/internal/service/builtin_skills/multica-autopilots/SKILL.md@@ -49,7 +49,7 @@ multica autopilot trigger-rotate-url <autopilot-id> <trigger-id> --yes --outputUse `trigger` only when the user explicitly asks for a manual run. Use `trigger-rotate-url` only when rotating a webhook URL; the old URL stops being valid.-Webhook trigger output can include a URL/token. Do not paste webhook tokens or signing material into comments, logs, docs, or PRs. Redact secrets.+`autopilot get` redacts `webhook_token`, `webhook_path`, and `webhook_url` by default while reporting whether a token exists and its non-sensitive hint. Only add `--show-secrets` when the user explicitly asks to retrieve the live webhook credential; the command warns on stderr. Do not paste webhook tokens or signing material into comments, logs, docs, or PRs.## Debuggingdiff --git a/server/internal/service/builtin_skills/multica-autopilots/references/autopilots-source-map.md b/server/internal/service/builtin_skills/multica-autopilots/references/autopilots-source-map.mdindex 8600c27686..4c20b58ed8 100644--- a/server/internal/service/builtin_skills/multica-autopilots/references/autopilots-source-map.md+++ b/server/internal/service/builtin_skills/multica-autopilots/references/autopilots-source-map.md@@ -1,7 +1,7 @@# Autopilots source map- `server/cmd/multica/cmd_autopilot.go` registers `list`, `get`, `create`, `update`, `delete`, `trigger`, `runs`, `trigger-add`, `trigger-update`, `trigger-delete`, and `trigger-rotate-url`.-- The CLI maps reads/writes to `/api/autopilots`, `/api/autopilots/{id}`, `/api/autopilots/{id}/trigger`, `/api/autopilots/{id}/runs`, and trigger subroutes.+- The CLI maps reads/writes to `/api/autopilots`, `/api/autopilots/{id}`, `/api/autopilots/{id}/trigger`, `/api/autopilots/{id}/runs`, and trigger subroutes. `autopilot get` nulls `webhook_token`, `webhook_path`, and `webhook_url` in normal JSON output and adds `has_webhook_token` plus `webhook_token_hint`; `--show-secrets` is an explicit JSON-only escape hatch that prints a credential-exposure warning to stderr.- `server/internal/service/autopilot.go` has `DispatchAutopilot`, synchronous delivery-idempotent `AdmitAutopilotWebhookDelivery`, and worker-side `DispatchAutopilotForWebhookDelivery`; it creates `autopilot_run` and switches on `execution_mode`.- `create_issue` calls `dispatchCreateIssue`; `run_only` calls `dispatchRunOnly`.- `resolveAutopilotLeader` resolves squad-assigned autopilots to the squad leader.