Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
fix(repo): keep credentials out of repository clone URLs (#137)
Robert06221c71aa04ec60
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 864a7760..d3664e71 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,12 @@Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. LoopForge Local packages use `local-vX.Y.Z` tags and are published by manually running the `release-local` workflow.+## Unreleased++- Repository clone URLs no longer carry credentials. Saving a `cloneUrl` with a user name or password, such as `https://user:[email protected]/acme/app.git`, is rejected with a pointer to the Git token in personal settings; the repositories API, bootstrap payload, run, task and requirement views, and the runner task management list strip credentials from `cloneUrl` and `webUrl` of rows saved earlier; a `webUrl` with credentials is rejected on save; runner clone errors and redacted Git output mask them. `ssh://git@host/...` and `git@host:path` remotes are still accepted.++Repositories saved earlier with a token in `cloneUrl` keep cloning until they are saved again. Saving one from the studio stores the URL without the token, so first put the Git token in 个人配置, then save the repository. Until then the token also lands in each workspace's `.git/config`, where the agent can read it, so re-save such repositories soon after upgrading.+## 0.3.8 — header sign-in hardening and a GHCR mirror option- With `AGENTFLOW_TRUST_IDENTITY_HEADERS=true`, identity headers such as `Staffname` are ignored on requests that carry `X-Forwarded-For`, `Forwarded` or `X-Real-IP`, unless the gateway also sends `X-AgentFlow-Gateway-Secret` matching the new `AGENTFLOW_IDENTITY_HEADER_SECRET`. A client behind a pass-through reverse proxy could otherwise sign in as any account. Deployments with the option off are unaffected.diff --git a/internal/domain/clone_url.go b/internal/domain/clone_url.gonew file mode 100644index 00000000..09f40394--- /dev/null+++ b/internal/domain/clone_url.go@@ -0,0 +1,39 @@+package domain++import (+ "net/url"+ "strings"+)++// StripURLCredentials removes secrets embedded in a repository URL. HTTP(S)+// and git:// userinfo is always a credential (a token is often sent as the+// user name), so it is dropped. An ssh:// user name such as git@ only names+// the account and is kept; any password after it is dropped. scp-like+// `user@host:path` remotes and local paths cannot carry a password and are+// returned unchanged.+func StripURLCredentials(raw string) string {+ s := strings.TrimSpace(raw)+ i := strings.Index(s, "://")+ if i <= 0 || !strings.Contains(s[i+3:], "@") {+ return s+ }+ u, err := url.Parse(s)+ if err != nil || u.User == nil {+ return s+ }+ switch strings.ToLower(u.Scheme) {+ case "ssh", "git+ssh", "ssh+git":+ if _, hasPassword := u.User.Password(); !hasPassword {+ return s+ }+ u.User = url.User(u.User.Username())+ default:+ u.User = nil+ }+ return u.String()+}++// URLHasCredentials reports whether StripURLCredentials would change raw.+func URLHasCredentials(raw string) bool {+ return StripURLCredentials(raw) != strings.TrimSpace(raw)+}diff --git a/internal/domain/clone_url_test.go b/internal/domain/clone_url_test.gonew file mode 100644index 00000000..768853dd--- /dev/null+++ b/internal/domain/clone_url_test.go@@ -0,0 +1,30 @@+package domain++import "testing"++func TestStripURLCredentials(t *testing.T) {+ for in, want := range map[string]string{+ "https://user:[email protected]/acme/app.git": "https://github.com/acme/app.git",+ "https://[email protected]/acme/app.git": "https://github.com/acme/app.git",+ "http://oauth2:[email protected]/g/r.git": "http://git.example.com/g/r.git",+ "git://u:[email protected]/r.git": "git://git.example.com/r.git",+ "ssh://git:[email protected]/g/r.git": "ssh://[email protected]/g/r.git",+ "ssh://[email protected]:2222/g/r.git": "ssh://[email protected]:2222/g/r.git",+ "[email protected]:acme/app.git": "[email protected]:acme/app.git",+ "https://github.com/acme/app.git": "https://github.com/acme/app.git",+ " https://github.com/acme/[email protected] ": "https://github.com/acme/[email protected]",+ "/srv/repos/app": "/srv/repos/app",+ "": "",+ } {+ if got := StripURLCredentials(in); got != want {+ t.Errorf("StripURLCredentials(%q) = %q, want %q", in, got, want)+ }+ }+ if !URLHasCredentials("https://x:y@h/r.git") || URLHasCredentials("ssh://git@h/r.git") || URLHasCredentials("git@h:r.git") {+ t.Fatal("URLHasCredentials classification")+ }+ public := PublicRepository(Repository{CloneURL: "https://user:[email protected]/acme/app.git", GitToken: "t"})+ if public.CloneURL != "https://github.com/acme/app.git" || public.GitToken != "" {+ t.Fatalf("public repository leaks credentials: %+v", public)+ }+}diff --git a/internal/domain/project.go b/internal/domain/project.goindex cab80750..4d7b3b8f 100644--- a/internal/domain/project.go+++ b/internal/domain/project.go@@ -91,9 +91,20 @@ type Repository struct {func PublicRepository(r Repository) Repository {r.GitTokenConfigured = falser.GitToken = ""+ // Rows saved before credentials were rejected may still embed them.+ r.CloneURL = StripURLCredentials(r.CloneURL)+ r.WebURL = StripURLCredentials(r.WebURL)return r}+// PublicRepositoryContext drops URL credentials from a run or task snapshot+// shown to readers; the stored snapshot keeps them so legacy clones work.+func PublicRepositoryContext(rc RepositoryContext) RepositoryContext {+ rc.CloneURL = StripURLCredentials(rc.CloneURL)+ rc.WebURL = StripURLCredentials(rc.WebURL)+ return rc+}+func PublicRepositories(items []Repository) []Repository {out := make([]Repository, len(items))for i, r := range items {diff --git a/internal/domain/runner.go b/internal/domain/runner.goindex fb7ada1b..b80b1ff5 100644--- a/internal/domain/runner.go+++ b/internal/domain/runner.go@@ -390,12 +390,14 @@ func PublicRunnerTask(task RunnerTask) RunnerTask {if copyInvocation.Repository != nil {copyRepository := *copyInvocation.RepositorycopyRepository.GitToken = ""+ copyRepository.CloneURL = StripURLCredentials(copyRepository.CloneURL)copyInvocation.Repository = ©Repository}if len(copyInvocation.Repositories) > 0 {copyRepositories := make([]RunnerRepository, len(copyInvocation.Repositories))for i, repository := range copyInvocation.Repositories {repository.GitToken = ""+ repository.CloneURL = StripURLCredentials(repository.CloneURL)copyRepositories[i] = repository}copyInvocation.Repositories = copyRepositoriesdiff --git a/internal/domain/runner_test.go b/internal/domain/runner_test.goindex 51a88060..5eb66afa 100644--- a/internal/domain/runner_test.go+++ b/internal/domain/runner_test.go@@ -49,6 +49,24 @@ func TestPublicRunnerTaskScrubsMultiRepositoryTokens(t *testing.T) {}}+func TestPublicRunnerTaskStripsCloneURLCredentials(t *testing.T) {+ const legacyURL = "https://user:[email protected]/acme/app.git"+ task := RunnerTask{ID: "task-legacy", Invocation: &RunnerInvocation{+ Repository: &RunnerRepository{CloneURL: legacyURL},+ Repositories: []RunnerRepository{{CloneURL: legacyURL}, {CloneURL: "https://[email protected]/acme/b.git"}},+ }}+ inv := PublicRunnerTask(task).Invocation+ if inv.Repository.CloneURL != "https://github.com/acme/app.git" {+ t.Fatalf("repository clone URL = %q", inv.Repository.CloneURL)+ }+ if inv.Repositories[0].CloneURL != "https://github.com/acme/app.git" || inv.Repositories[1].CloneURL != "https://github.com/acme/b.git" {+ t.Fatalf("repositories clone URLs = %+v", inv.Repositories)+ }+ if task.Invocation.Repository.CloneURL != legacyURL || task.Invocation.Repositories[0].CloneURL != legacyURL {+ t.Fatal("the claiming runner still needs the stored clone URL")+ }+}+func TestAgentCLIRuntimeAuthModeIsPersonal(t *testing.T) {r := Runner{Runtimes: []RunnerRuntime{{Provider: "opencode", AuthMode: RuntimeAuthLocal},diff --git a/internal/gitwork/auth.go b/internal/gitwork/auth.goindex 6c6065bc..7a8ab84e 100644--- a/internal/gitwork/auth.go+++ b/internal/gitwork/auth.go@@ -10,6 +10,7 @@ import ("net/url""os""path/filepath"+ "regexp""strings")@@ -229,8 +230,30 @@ func RewriteRemoteForToken(remote, token string) string {return u.String()}-// Redact masks tokens (and the host-level EnvToken) in git output.+// urlUserinfo matches the userinfo of a URL anywhere in free text.+var urlUserinfo = regexp.MustCompile(`(?i)\b(https?|git|ssh|git\+ssh|ssh\+git)://([^\s/@]+)@`)++// redactURLUserinfo masks credentials embedded in URLs, including ones that+// were never passed in as tokens (for example pasted into a clone URL).+// HTTP(S) and git:// userinfo is masked whole; an ssh user name is kept.+func redactURLUserinfo(s string) string {+ return urlUserinfo.ReplaceAllStringFunc(s, func(match string) string {+ parts := urlUserinfo.FindStringSubmatch(match)+ scheme, info := parts[1], parts[2]+ if strings.HasPrefix(strings.ToLower(scheme), "ssh") || strings.HasSuffix(strings.ToLower(scheme), "+ssh") {+ if user, _, hasPassword := strings.Cut(info, ":"); hasPassword {+ return scheme + "://" + user + ":***@"+ }+ return match+ }+ return scheme + "://***@"+ })+}++// Redact masks tokens (and the host-level EnvToken) in git output, plus any+// credentials embedded in URLs.func Redact(s string, tokens ...string) string {+ s = redactURLUserinfo(s)seen := map[string]struct{}{}for _, raw := range append(tokens, EnvToken()) {for _, candidate := range []string{strings.TrimSpace(raw), func() string { _, sec := SplitToken(raw); return sec }()} {diff --git a/internal/gitwork/redact_url_test.go b/internal/gitwork/redact_url_test.gonew file mode 100644index 00000000..f0ef8308--- /dev/null+++ b/internal/gitwork/redact_url_test.go@@ -0,0 +1,24 @@+package gitwork++import (+ "strings"+ "testing"+)++func TestRedactMasksURLUserinfo(t *testing.T) {+ t.Setenv("AGENTFLOW_GIT_TOKEN", "")+ out := Redact("fatal: unable to access 'https://user:[email protected]/acme/app.git/': 403 and https://[email protected]/x.git", "unrelated-git-token")+ if strings.Contains(out, "s3cret-token") || strings.Contains(out, "ghp_abc123") || strings.Contains(out, "user:") {+ t.Fatalf("URL credentials survived redaction: %s", out)+ }+ if !strings.Contains(out, "https://***@github.com/acme/app.git") {+ t.Fatalf("redacted URL lost its host: %s", out)+ }+ ssh := Redact("ssh://[email protected]/r.git ssh://git:[email protected]/r.git")+ if ssh != "ssh://[email protected]/r.git ssh://git:***@git.example.com/r.git" {+ t.Fatalf("ssh redaction: %s", ssh)+ }+ if got := Redact("see https://github.com/acme/app and mail [email protected]"); got != "see https://github.com/acme/app and mail [email protected]" {+ t.Fatalf("plain text changed: %s", got)+ }+}diff --git a/internal/httpapi/catalog.go b/internal/httpapi/catalog.goindex 99b7ac21..a6dbf4d7 100644--- a/internal/httpapi/catalog.go+++ b/internal/httpapi/catalog.go@@ -239,7 +239,15 @@ func (h *catalogHandlers) repositories(c *gin.Context) {if v.DefaultBranch == "" {v.DefaultBranch = "master"}+ if domain.URLHasCredentials(v.WebURL) {+ c.JSON(400, map[string]string{"error": "webUrl 不能包含账号、密码或 Token,请去掉 @ 前的部分"})+ return+ }if v.CloneURL != "" {+ if domain.URLHasCredentials(v.CloneURL) {+ c.JSON(400, map[string]string{"error": "cloneUrl 不能包含账号、密码或 Token,请去掉 @ 前的部分,并在个人配置中填写 Git Token"})+ return+ }if err := gitwork.ValidateRemoteURL(v.CloneURL, !authRequired() || h.isPlatformAdmin(c.Request)); err != nil {c.JSON(400, map[string]string{"error": "cloneUrl 无效:" + err.Error()})returndiff --git a/internal/httpapi/dispatch.go b/internal/httpapi/dispatch.goindex 05f391f9..0e9cd6e7 100644--- a/internal/httpapi/dispatch.go+++ b/internal/httpapi/dispatch.go@@ -138,7 +138,7 @@ func dispatchIssue(d *deps, req dispatchRequest) (domain.Task, error) {input += "\n\nRepository context (frozen, multi-repository): every repository below is checked out side by side; treat them as equals"}for _, rc := range repositories {- input += fmt.Sprintf("\n- repository: %s (%s)\n - provider: %s\n - base branch: %s\n - clone URL: %s\n - local directory: ./%s (code changes for this repository MUST be written inside this directory)", rc.Name, rc.GongfengProjectID, rc.Provider, rc.BaseBranch, rc.CloneURL, rc.WorkspaceDir)+ input += fmt.Sprintf("\n- repository: %s (%s)\n - provider: %s\n - base branch: %s\n - clone URL: %s\n - local directory: ./%s (code changes for this repository MUST be written inside this directory)", rc.Name, rc.GongfengProjectID, rc.Provider, rc.BaseBranch, domain.StripURLCredentials(rc.CloneURL), rc.WorkspaceDir)input += fmt.Sprintf("\n - merge request target branch: %s", rc.BaseBranch)if rc.RequireExistingWorkBranch {input += fmt.Sprintf("\n - existing work branch: %s (continue directly on this remote branch; do not create or rename a work branch; fail if the branch does not exist; create or update its MR targeting %s)", rc.WorkBranch, rc.BaseBranch)diff --git a/internal/httpapi/issue_routes.go b/internal/httpapi/issue_routes.goindex 25a6331e..9019e21d 100644--- a/internal/httpapi/issue_routes.go+++ b/internal/httpapi/issue_routes.go@@ -324,7 +324,7 @@ func (h issuesHandlers) dispatchIssueRoute(c *gin.Context, issue domain.Issue) {detail = "重新运行 SOP"}_, _ = h.appendStoredOperation(c, issue.ID, "dispatch", detail)- c.JSON(201, task)+ c.JSON(201, publicTask(task))}// deleteIssue checks the complete history before cleaning failed/cancelled runs.diff --git a/internal/httpapi/repository_clone_url_test.go b/internal/httpapi/repository_clone_url_test.goindex 82a70dfb..92b4d485 100644--- a/internal/httpapi/repository_clone_url_test.go+++ b/internal/httpapi/repository_clone_url_test.go@@ -1,8 +1,12 @@package httpapiimport (+ "encoding/json""net/http"+ "strings""testing"++ "agentflow/internal/domain")func TestRepositorySaveRejectsUnsafeCloneURL(t *testing.T) {@@ -30,3 +34,113 @@ func TestRepositorySaveRejectsUnsafeCloneURL(t *testing.T) {t.Fatalf("ssh cloneUrl = %d: %s", rec.Code, rec.Body.String())}}++func TestRepositoryCloneURLNeverCarriesCredentials(t *testing.T) {+ f := cvBNewHTTPFixture(t)+ for _, cloneURL := range []string{+ "https://user:[email protected]/acme/app.git",+ "https://[email protected]/acme/app.git",+ "ssh://git:[email protected]/acme/app.git",+ } {+ rec := cvBRequest(t, f, http.MethodPost, "/api/repositories", map[string]any{+ "projectId": "platform", "name": "leak", "gongfengProjectId": "example/leak", "cloneUrl": cloneURL,+ }, true)+ if rec.Code != http.StatusBadRequest || strings.Contains(rec.Body.String(), "s3cret-token") {+ t.Fatalf("cloneUrl with credentials %q = %d: %s", cloneURL, rec.Code, rec.Body.String())+ }+ }+ rec := cvBRequest(t, f, http.MethodPost, "/api/repositories", map[string]any{+ "projectId": "platform", "name": "leak", "gongfengProjectId": "example/leak", "webUrl": "https://user:[email protected]/acme/app",+ }, true)+ if rec.Code != http.StatusBadRequest || strings.Contains(rec.Body.String(), "s3cret-token") {+ t.Fatalf("webUrl with credentials = %d: %s", rec.Code, rec.Body.String())+ }+ // A row stored before this check must not leak through the API either.+ if err := f.s.PutRepository(domain.Repository{ID: "legacy-leak", Name: "legacy", ProjectID: "platform", Provider: "github", DefaultBranch: "main", WebURL: "https://user:[email protected]/acme/app", CloneURL: "https://user:[email protected]/acme/app.git"}); err != nil {+ t.Fatal(err)+ }+ for _, path := range []string{"/api/repositories", "/api/repositories/legacy-leak", "/api/bootstrap"} {+ rec := cvBRequest(t, f, http.MethodGet, path, nil, true)+ if rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "s3cret-token") || !strings.Contains(rec.Body.String(), `"https://github.com/acme/app"`) || !strings.Contains(rec.Body.String(), "https://github.com/acme/app.git") {+ t.Fatalf("GET %s = %d leaks or drops the clone URL: %s", path, rec.Code, rec.Body.String())+ }+ }+}++func TestRunnerTaskListDropsCloneURLCredentials(t *testing.T) {+ f := cvBNewHTTPFixture(t)+ const legacyURL = "https://user:[email protected]/acme/app.git"+ if err := f.s.PutRunnerTask(domain.RunnerTask{ID: "rt-legacy", Provider: "mock", Status: "queued", Invocation: &domain.RunnerInvocation{+ Repository: &domain.RunnerRepository{CloneURL: legacyURL},+ Repositories: []domain.RunnerRepository{{CloneURL: legacyURL}},+ }}); err != nil {+ t.Fatal(err)+ }+ rec := cvBRequest(t, f, http.MethodGet, "/api/runners/tasks", nil, true)+ if rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "s3cret-token") || !strings.Contains(rec.Body.String(), "https://github.com/acme/app.git") {+ t.Fatalf("GET /api/runners/tasks = %d leaks or drops the clone URL: %s", rec.Code, rec.Body.String())+ }+ if stored, ok := f.s.RunnerTask("rt-legacy"); !ok || stored.Invocation.Repository.CloneURL != legacyURL {+ t.Fatalf("the claiming runner still needs the stored clone URL: %+v", stored.Invocation)+ }+}++func TestLegacyCloneURLCredentialsStayOutOfPromptAndRunViews(t *testing.T) {+ f := cvBNewHTTPFixture(t)+ if err := f.s.PutWorkflow(domain.WorkflowDefinition{ID: "legacy-flow", Name: "Legacy flow", SandboxProfileID: "local", Nodes: []domain.WorkflowNode{{ID: "approval", Name: "Approval", Type: "approval", MaxAttempts: 1}}}); err != nil {+ t.Fatal(err)+ }+ const legacyURL = "https://user:[email protected]/acme/app.git"+ if err := f.s.PutRepository(domain.Repository{ID: "legacy-run", Name: "legacy", ProjectID: "platform", Provider: "github", GongfengProjectID: "acme/app", DefaultBranch: "main", WebURL: "https://user:[email protected]/acme/app", CloneURL: legacyURL}); err != nil {+ t.Fatal(err)+ }+ if err := f.s.PutIssue(domain.Issue{ID: "iss-legacy", ProjectID: "platform", Title: "Legacy repo", AssigneeType: "agent", AssigneeID: "developer", WorkflowID: "legacy-flow", RepositoryID: "legacy-run"}); err != nil {+ t.Fatal(err)+ }+ rec := cvBRequest(t, f, http.MethodPost, "/api/issues/iss-legacy/dispatch", map[string]any{}, true)+ if rec.Code != http.StatusCreated || strings.Contains(rec.Body.String(), "s3cret-token") {+ t.Fatalf("dispatch = %d leaks credentials: %s", rec.Code, rec.Body.String())+ }+ var task domain.Task+ for _, candidate := range f.s.Tasks() {+ if candidate.IssueID == "iss-legacy" {+ task = candidate+ }+ }+ run, ok := f.s.Run(task.RunID)+ if !ok || run.Repository.CloneURL != legacyURL {+ t.Fatalf("stored run must keep the clone URL it clones with: %+v", run.Repository)+ }+ if strings.Contains(run.Input, "s3cret-token") || !strings.Contains(run.Input, "clone URL: https://github.com/acme/app.git") {+ t.Fatalf("prompt carries clone URL credentials: %q", run.Input)+ }+ for _, path := range []string{"/api/runs", "/api/runs/" + run.ID, "/api/tasks", "/api/tasks/" + task.ID} {+ rec := cvBRequest(t, f, http.MethodGet, path, nil, true)+ if rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "s3cret-token") || !strings.Contains(rec.Body.String(), "https://github.com/acme/app.git") {+ t.Fatalf("GET %s = %d leaks or drops the clone URL: %s", path, rec.Code, rec.Body.String())+ }+ }++ if err := f.s.PutWorkflow(domain.WorkflowDefinition{ID: "legacy-generic", Name: "Legacy generic", Generic: true, SandboxProfileID: "local", Nodes: []domain.WorkflowNode{{ID: "approval", Name: "Approval", Type: "approval", MaxAttempts: 1}}}); err != nil {+ t.Fatal(err)+ }+ project, ok := f.s.Project("platform")+ if !ok {+ t.Fatal("platform project missing")+ }+ project.DefaultRepositoryID = "legacy-run"+ if err := f.s.PutProject(project); err != nil {+ t.Fatal(err)+ }+ rec = cvBRequest(t, f, http.MethodPost, "/api/runs", map[string]any{"workflowId": "legacy-generic", "input": "x", "projectId": "platform"}, true)+ if rec.Code != http.StatusCreated || strings.Contains(rec.Body.String(), "s3cret-token") || !strings.Contains(rec.Body.String(), "https://github.com/acme/app.git") {+ t.Fatalf("POST /api/runs = %d leaks or drops the clone URL: %s", rec.Code, rec.Body.String())+ }+ var started domain.Run+ if err := json.Unmarshal(rec.Body.Bytes(), &started); err != nil {+ t.Fatal(err)+ }+ if stored, ok := f.s.Run(started.ID); !ok || len(stored.Repositories) == 0 || stored.Repositories[0].CloneURL != legacyURL {+ t.Fatalf("stored manual run must keep the clone URL it clones with: %+v", stored.Repositories)+ }+}diff --git a/internal/httpapi/rooms.go b/internal/httpapi/rooms.goindex 0e9fbce7..06a1244d 100644--- a/internal/httpapi/rooms.go+++ b/internal/httpapi/rooms.go@@ -329,7 +329,7 @@ func (h *roomsHandlers) dispatchToIssue(c *gin.Context, room domain.ChatRoom, st} else {msg.TaskID = task.IDmsg.RunID = task.RunID- result.Tasks = append(result.Tasks, task)+ result.Tasks = append(result.Tasks, publicTask(task))name := workflowNames[i]_, _ = h.repo.PatchIssue(stored.ID, func(iss *domain.Issue) error {iss.AppendOperation(domain.IssueOperation{Actor: author, ActorUserID: userID, Action: "dispatch", Detail: "协作群派发 SOP「" + name + "」"})diff --git a/internal/httpapi/runs.go b/internal/httpapi/runs.goindex b79f9a42..7e58bddb 100644--- a/internal/httpapi/runs.go+++ b/internal/httpapi/runs.go@@ -9,6 +9,7 @@ import ("agentflow/internal/domain""agentflow/internal/engine"+ "agentflow/internal/gitwork""agentflow/internal/observability""agentflow/internal/runtime"@@ -143,7 +144,7 @@ func (h *runsHandlers) runs(c *gin.Context) {respond(c, err)return}- c.JSON(201, v)+ c.JSON(201, publicRun(v, false))return}}@@ -347,6 +348,14 @@ func publicRun(run domain.Run, summary bool) domain.Run {for i := range run.Artifacts {run.Artifacts[i].Content = ""}+ // Runs keep the stored clone URL so a repository saved with credentials+ // before they were rejected still clones; readers never see them.+ run.Repository = domain.PublicRepositoryContext(run.Repository)+ run.Repositories = append([]domain.RepositoryContext(nil), run.Repositories...)+ for i := range run.Repositories {+ run.Repositories[i] = domain.PublicRepositoryContext(run.Repositories[i])+ }+ run.Input = gitwork.Redact(run.Input)newNodes := make(map[string]*domain.NodeRun, len(run.Nodes))for k, n := range run.Nodes {if n == nil {diff --git a/internal/httpapi/tasks.go b/internal/httpapi/tasks.goindex ee8af45a..1af3a998 100644--- a/internal/httpapi/tasks.go+++ b/internal/httpapi/tasks.go@@ -21,7 +21,11 @@ type tasksHandlers struct {func (h *tasksHandlers) tasks(c *gin.Context) {h.syncTasks()- c.JSON(200, h.repo.Tasks())+ tasks := h.repo.Tasks()+ for i := range tasks {+ tasks[i] = publicTask(tasks[i])+ }+ c.JSON(200, tasks)}func (h *tasksHandlers) task(c *gin.Context) {@@ -31,7 +35,12 @@ func (h *tasksHandlers) task(c *gin.Context) {c.JSON(http.StatusNotFound, map[string]string{"error": "task not found"})return}- c.JSON(http.StatusOK, task)+ c.JSON(http.StatusOK, publicTask(task))+}++func publicTask(task domain.Task) domain.Task {+ task.Repository = domain.PublicRepositoryContext(task.Repository)+ return task}// settleIssueTasks moves one issue's Tasks onto runs that already finished.diff --git a/internal/repo/requirement.go b/internal/repo/requirement.goindex 2c1137a7..d4ea8e6a 100644--- a/internal/repo/requirement.go+++ b/internal/repo/requirement.go@@ -73,7 +73,7 @@ func requirementConversation(issue domain.Issue, runs []domain.Run) *domain.Requ}workspaces++for _, rc := range run.RepositoryContexts() {- branch := domain.RequirementBranch{Repository: rc.Name, WebURL: rc.WebURL, BaseBranch: rc.BaseBranch, WorkBranch: rc.WorkBranch}+ branch := domain.RequirementBranch{Repository: rc.Name, WebURL: domain.StripURLCredentials(rc.WebURL), BaseBranch: rc.BaseBranch, WorkBranch: rc.WorkBranch}key := branch.Repository + "\x00" + branch.WorkBranchif branch.Repository == "" || seen[key] {continuediff --git a/internal/repo/requirement_test.go b/internal/repo/requirement_test.goindex 77010973..f72bb92f 100644--- a/internal/repo/requirement_test.go+++ b/internal/repo/requirement_test.go@@ -277,3 +277,11 @@ func TestRequirementSnapshotHTTPStore(t *testing.T) {t.Fatalf("frontend lane=%#v", frontend)}}++func TestRequirementConversationBranchesDropURLCredentials(t *testing.T) {+ run := domain.Run{Kind: domain.RunKindWorkspace, Repositories: []domain.RepositoryContext{{RepositoryID: "app", Name: "app", WebURL: "https://user:[email protected]/acme/app", WorkBranch: "feature/x"}}}+ conv := requirementConversation(domain.Issue{ID: "iss-1"}, []domain.Run{run})+ if conv == nil || len(conv.Branches) != 1 || conv.Branches[0].WebURL != "https://github.com/acme/app" {+ t.Fatalf("branches = %+v", conv)+ }+}diff --git a/internal/runner/daemon.go b/internal/runner/daemon.goindex 006d92f9..a4cf0d44 100644--- a/internal/runner/daemon.go+++ b/internal/runner/daemon.go@@ -1223,7 +1223,7 @@ func cloneRepository(ctx context.Context, workspace string, repo *domain.RunnerRctx = procwatch.WithObserver(ctx, func(event procwatch.Event) { log.Printf("runner checkout: %s", event.Message) })tail, err := gitwork.Watch(repositoryGitContext(ctx, *repo), workspace, watch, args...)if err != nil {- return fmt.Errorf("git clone %s: %w (%s)", repo.CloneURL, err, cloneOutput([]byte(tail), repo.GitToken))+ return fmt.Errorf("git clone %s: %w (%s)", domain.StripURLCredentials(repo.CloneURL), err, cloneOutput([]byte(tail), repo.GitToken))}// The branch steps below keep the bound they always had.cloneCtx := ctxdiff --git a/internal/runner/repository_checkout_test.go b/internal/runner/repository_checkout_test.goindex f0bb5d00..a4fcf53f 100644--- a/internal/runner/repository_checkout_test.go+++ b/internal/runner/repository_checkout_test.go@@ -274,3 +274,15 @@ func TestCheckoutRepositoryRejectsCommandRunningCloneURLs(t *testing.T) {}}}++func TestCloneFailureNeverEchoesCloneURLCredentials(t *testing.T) {+ // Port 1 on loopback refuses at once; git echoes the URL in its error.+ cloneURL := "http://user:[email protected]:1/acme/app.git"+ err := cloneRepository(context.Background(), t.TempDir(), &domain.RunnerRepository{CloneURL: cloneURL, Ref: "master"})+ if err == nil {+ t.Fatal("clone of an unreachable remote succeeded")+ }+ if strings.Contains(err.Error(), "s3cret-token") || !strings.Contains(err.Error(), "127.0.0.1:1/acme/app.git") {+ t.Fatalf("clone error leaks or hides the remote: %v", err)+ }+}