From c443ffce57e9465e419280413f4c5673ab18b7ba Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 02:12:28 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20drop=20key=3Dvalue=20?= =?UTF-8?q?secrets=20from=20Matrix=20lines=20and=20stop=20the=20matrix=20s?= =?UTF-8?q?ource=20on=20Server.Close?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit matrixAcceptLine let short secrets like 'password: hunter2' through when the path was not denied; add a key=value drop rule that leaves Go ':=' and plain prose alone. Server.Close now also closes the matrix source so its run goroutine does not leak (close is already idempotent). Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- changelog.d/fixed-15971.md | 1 + src/pkg/dashboard/contribute_ws.go | 8 +++++++- src/pkg/dashboard/matrix_source_filter.go | 9 +++++++++ src/pkg/dashboard/matrix_source_test.go | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fixed-15971.md diff --git a/changelog.d/fixed-15971.md b/changelog.d/fixed-15971.md new file mode 100644 index 0000000000..4e520275de --- /dev/null +++ b/changelog.d/fixed-15971.md @@ -0,0 +1 @@ +- Matrix lines that look like short `key=value` secrets (for example `password: hunter2`) are now dropped, and `Server.Close` now stops the Matrix line source goroutine (#15971, #15972). diff --git a/src/pkg/dashboard/contribute_ws.go b/src/pkg/dashboard/contribute_ws.go index 0ca6e2c8c3..4db0e7f962 100644 --- a/src/pkg/dashboard/contribute_ws.go +++ b/src/pkg/dashboard/contribute_ws.go @@ -5068,12 +5068,18 @@ func (s *Server) CloseContributeHub() { } // Close shuts down server-managed background resources, including the -// contributor hub. +// contributor hub and the Matrix line source. func (s *Server) Close() { if s == nil { return } s.CloseContributeHub() + s.matrixMu.Lock() + m := s.matrix + s.matrixMu.Unlock() + if m != nil { + m.close() + } } func contributorStatePath(contributorsDir, currentPath, name string) string { diff --git a/src/pkg/dashboard/matrix_source_filter.go b/src/pkg/dashboard/matrix_source_filter.go index b1e49b9d0e..4434a25cb7 100644 --- a/src/pkg/dashboard/matrix_source_filter.go +++ b/src/pkg/dashboard/matrix_source_filter.go @@ -2,6 +2,7 @@ package dashboard import ( "path" + "regexp" "strings" "unicode" "unicode/utf8" @@ -13,6 +14,11 @@ import ( // line may carry; a longer run looks like a key, hash or encoded secret. const matrixEntropyRun = 32 +// matrixKeyValueSecret matches a secret-looking key followed by `=` or `:` and +// a value, so short secrets such as `password: hunter2` are dropped. Go's `:=` +// and `==` are excluded so ordinary code is not over-dropped. +var matrixKeyValueSecret = regexp.MustCompile(`(?i)(?:password|passwd|pwd|secret|api[_-]?key|access[_-]?key|auth[_-]?token|token)\s*(?:=[^=]|:[^=])\s*["']?[^\s"']`) + var matrixLockfiles = map[string]bool{ "go.sum": true, "package-lock.json": true, @@ -125,6 +131,9 @@ func matrixAcceptLine(raw string) (string, bool) { if matrixHasEntropyRun(line) { return "", false } + if matrixKeyValueSecret.MatchString(line) { + return "", false + } if logscrub.ContainsRedactionMarker(line) { return "", false } diff --git a/src/pkg/dashboard/matrix_source_test.go b/src/pkg/dashboard/matrix_source_test.go index 37c510f69a..be890a74d9 100644 --- a/src/pkg/dashboard/matrix_source_test.go +++ b/src/pkg/dashboard/matrix_source_test.go @@ -202,6 +202,12 @@ func TestMatrixAcceptLine(t *testing.T) { {name: "entropy run 31 ok", in: "id " + strings.Repeat("a", 31), want: "id " + strings.Repeat("a", 31), ok: true}, {name: "redaction marker", in: "value here"}, {name: "scrub changes", in: "key AKIA" + "IOSFODNN7EXAMPLE end"}, + {name: "yaml password", in: "password: hunter2"}, + {name: "env api key", in: "API_KEY=abc123"}, + {name: "quoted secret", in: `secret: "x"`}, + {name: "go short declare kept", in: "token := parse(r)", want: "token := parse(r)", ok: true}, + {name: "comment kept", in: "// the token is refreshed hourly", want: "// the token is refreshed hourly", ok: true}, + {name: "identifier kept", in: "tokenize(line)", want: "tokenize(line)", ok: true}, {name: "pane scrub changes", in: "use sk-" + "abcdef12 now"}, } for _, tc := range tests { @@ -481,3 +487,19 @@ func TestMatrixSourceExpiredHashInLivePR(t *testing.T) { t.Fatalf("totalHashes = %d, want 2", m.totalHashes) } } + +func TestServerCloseStopsMatrixSource(t *testing.T) { + s := &Server{} + if s.MatrixObserver(matrixTestConfig()) == nil { + t.Fatal("active matrix returned no observer") + } + src := s.matrix + s.Close() + select { + case <-src.done: + case <-time.After(5 * time.Second): + t.Fatal("Server.Close did not stop the matrix goroutine") + } + s.Close() + (&Server{}).Close() +} From 48a262e03f32586c13491f0f148f87eb49be8830 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 02:21:23 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20match=20quoted=20keys?= =?UTF-8?q?=20in=20the=20Matrix=20key=3Dvalue=20secret=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit matrixKeyValueSecret required the key to be followed directly by the separator, so JSON, PHP and Ruby forms like "password": "hunter2" or 'password' => 'x' slipped through. Allow an optional closing quote after the key and cover those shapes in TestMatrixAcceptLine. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/dashboard/matrix_source_filter.go | 10 ++++++---- src/pkg/dashboard/matrix_source_test.go | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pkg/dashboard/matrix_source_filter.go b/src/pkg/dashboard/matrix_source_filter.go index 4434a25cb7..0828eccb9f 100644 --- a/src/pkg/dashboard/matrix_source_filter.go +++ b/src/pkg/dashboard/matrix_source_filter.go @@ -14,10 +14,12 @@ import ( // line may carry; a longer run looks like a key, hash or encoded secret. const matrixEntropyRun = 32 -// matrixKeyValueSecret matches a secret-looking key followed by `=` or `:` and -// a value, so short secrets such as `password: hunter2` are dropped. Go's `:=` -// and `==` are excluded so ordinary code is not over-dropped. -var matrixKeyValueSecret = regexp.MustCompile(`(?i)(?:password|passwd|pwd|secret|api[_-]?key|access[_-]?key|auth[_-]?token|token)\s*(?:=[^=]|:[^=])\s*["']?[^\s"']`) +// matrixKeyValueSecret matches a secret-looking key, optionally closed by a +// quote as in JSON, PHP or Ruby (`"password": "x"`, `'password' => 'x'`), +// followed by `=`, `:` or `=>` and a value, so short secrets such as +// `password: hunter2` are dropped. Go's `:=` and `==` are excluded so ordinary +// code is not over-dropped. +var matrixKeyValueSecret = regexp.MustCompile(`(?i)(?:password|passwd|pwd|secret|api[_-]?key|access[_-]?key|auth[_-]?token|token)["']?\s*(?:=[^=]|:[^=])\s*["']?[^\s"']`) var matrixLockfiles = map[string]bool{ "go.sum": true, diff --git a/src/pkg/dashboard/matrix_source_test.go b/src/pkg/dashboard/matrix_source_test.go index be890a74d9..fd6304f514 100644 --- a/src/pkg/dashboard/matrix_source_test.go +++ b/src/pkg/dashboard/matrix_source_test.go @@ -205,6 +205,10 @@ func TestMatrixAcceptLine(t *testing.T) { {name: "yaml password", in: "password: hunter2"}, {name: "env api key", in: "API_KEY=abc123"}, {name: "quoted secret", in: `secret: "x"`}, + {name: "json password", in: `"password": "hunter2"`}, + {name: "json api key compact", in: `"api_key":"abc"`}, + {name: "php password", in: `'password' => 'hunter2'`}, + {name: "ruby symbol token", in: `token: "abc"`}, {name: "go short declare kept", in: "token := parse(r)", want: "token := parse(r)", ok: true}, {name: "comment kept", in: "// the token is refreshed hourly", want: "// the token is refreshed hourly", ok: true}, {name: "identifier kept", in: "tokenize(line)", want: "tokenize(line)", ok: true},