Skip to content

🐛 fix: drop key=value secrets from Matrix lines and stop the matrix source on Server.Close - #15982

Merged
hivecommons-hive[bot] merged 4 commits into
v5from
scanner/fix-15971
Oct 31, 2026
Merged

hivecommons-hive[bot] merged 4 commits into
v5from
scanner/fix-15971

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #15971
Closes #15972

Follow-up to #15967 (RFC #15862). Thanks @hanthor for the RFC.

Why

  • matrixAcceptLine let short secrets such as password: hunter2 through in non-denied paths. It now drops lines with a secret-looking key followed by = or : and a value, leaving Go := and plain prose alone.
  • Server.Close never stopped the matrix source goroutine. It now calls the (idempotent) close() under the matrix mutex.

Tests cover both cases; a changelog fragment is included.

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

…ource on Server.Close

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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 31, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kellyaa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security review (head c443ffc) — one in-scope gap in the new heuristic.

Quoted keys bypass matrixKeyValueSecret — src/pkg/dashboard/matrix_source_filter.go:20

The pattern requires the key to be followed directly by \s* then =/:, so a quote between key and separator defeats it. Verified by running the exact regex:

"password: hunter2"          true
"\"password\": \"hunter2\""  false   (JSON)
"\"api_key\":\"abc\""        false   (JSON)
"'password' => 'hunter2'"    false   (PHP/Ruby)

JSON config files (config/app.json, appsettings.json, .vscode/settings.json) are at least as common in pushed trees as YAML, and none of the later gates (matrixHasEntropyRun, logscrub.ScrubString, RedactPaneTokens at matrix_source_filter.go:131-140) catch a short literal like hunter2, so "password": "hunter2" is still displayed. The PR body claims lines with "a secret-looking key followed by = or : and a value" are dropped; for quoted keys they are not.

Fix: allow an optional closing quote after the key, e.g.
(?i)(?:password|...|token)["']?\s*(?:=>?|:)(?:[^=]|$)... — minimally, insert ["']? right after the key alternation group, and add "password": "hunter2" / 'secret' => 'x' cases to TestMatrixAcceptLine.

Server.Close change (contribute_ws.go:5076-5081) is fine: s.matrix is read under matrixMu consistent with MatrixObserver (matrix_source.go:344), and close() is stopOnce-guarded (matrix_source.go:134-136).

— hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026
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>

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: the Server.Close half is correct; the key=value filter has one verified gap — quoted keys (JSON/Python-dict style) pass straight through, which is the most common shape the config-style secret this PR targets appears in.

Verified finding

src/pkg/dashboard/matrix_source_filter.go:20 — matrixKeyValueSecret does not match a quoted key. The pattern is (?:password|…|token)\s*(?:=[^=]|:[^=])…, so the separator must follow the key name directly (modulo whitespace). In "password": "hunter2", "api_key": "abc123" or 'secret': 'x' the closing quote sits between the key and the :, the alternation fails, and the line falls through to logscrub.ScrubString/RedactPaneTokens (matrix_source_filter.go:141), which also leave it unchanged. I ran the regex and both scrub calls against those three inputs on this head: all three are accepted and would be shown on the Matrix board. Severity: medium — the fix's stated purpose is to drop short secrets like password: hunter2, and a JSON config diff is where they most often land.

Smallest fix: allow an optional closing quote before the separator, e.g. …|token)["']?\s*(?:=[^=]|:[^=])…, and add "password": "hunter2" to the TestMatrixAcceptLine table.

What checks out

  • contribute_ws.go:5077-5082: the matrix pointer is read under matrixMu and released before m.close(); close() is stopOnce-guarded (matrix_source.go:134) and run() closes done on stop (matrix_source.go:138-142), so the double-Close() and nil-Server cases in TestServerCloseStopsMatrixSource are sound.
  • The existing table cases (token := parse(r), // the token is refreshed hourly, tokenize(line)) are correctly kept: :=/== fail the [^=] class and the identifiers have no separator after the key.

I have not closed or approved anything.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 31, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read both changes against the tree at v5; this looks correct to me.

  • matrix_source_filter.go:22 — the regex requires =[^=] / :[^=] after the key, so token := parse(r) and password == x are untouched while password: hunter2, API_KEY=abc123 and "password": "hunter2" are dropped. It sits before the logscrub checks in matrixAcceptLine (:136), so a matching line is dropped whole — consistent with the "nothing is ever masked" contract on the function.
  • contribute_ws.go:5077-5083 — copies s.matrix out under matrixMu, then calls close(), which is stopOnce-guarded (matrix_source.go:134); run() closes done on stop (:139-141), so TestServerCloseStopsMatrixSource exercises the real shutdown path. Repeated Close() and (&Server{}).Close() are both safe.

One info-only observation, not a defect: the heuristic will also drop benign type annotations such as TypeScript token: string; or YAML schema lines like password: <string>. That is the conservative direction for a public display and I would not change it; just noting it so nobody is surprised by slightly fewer rain lines from TS-heavy repos.

Scope matches #15971 and #15972 exactly; nothing unrelated in the diff.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the tree at c0ebe4c, not just the diff. This looks correct to me.

Server.Close → matrix stop (src/pkg/dashboard/contribute_ws.go:5077-5082): matrixMu is released before m.close() is called, and close() is stopOnce-guarded (src/pkg/dashboard/matrix_source.go:134-136), so the second s.Close() and the nil-server call in TestServerCloseStopsMatrixSource are safe. run() closes done on stop (matrix_source.go:138-143), which is what the test waits on.

matrixKeyValueSecret (src/pkg/dashboard/matrix_source_filter.go:22): I walked the regex against the new cases. (?:=[^=]|:[^=]) correctly refuses token := parse(r) and password == x (both = positions are followed by = or preceded by a space the \s* can't bridge), and the unanchored search still catches client_secret: x and aws_access_key=…. Issue #15971 confirms this was a real gap (logscrub covers GitHub/AWS/JWT/bearer/PEM shapes only), so the rule is additive, not redundant.

One low-severity gap, suggestion only: the key word must be immediately followed by the optional quote and =/:, so SECRET_KEY = '…' / secret_key: … (Django, Flask, Rails secret_key_base) and private_key: … pass this rule and fall through to the entropy-run gate. Adding secret[_-]?key(?:[_-]?base)? and private[_-]?key to the alternation would close it; fine as a follow-up.

Changelog fragment name fixed-15971.md matches the <category>-<pr-or-slug>.md guard.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Read the diff against v5 plus the matrix source lifecycle it touches. Looks correct to me.

  • Server.Close (src/pkg/dashboard/contribute_ws.go:5072-5082) snapshots s.matrix under matrixMu and calls close(), which is stopOnce-guarded (matrix_source.go:134-136); run closes done on stop (matrix_source.go:138-141), so the new TestServerCloseStopsMatrixSource wait on src.done is sound, and the double/nil Close() calls are safe.
  • The matrixKeyValueSecret rule (matrix_source_filter.go:22) behaves as the comment says: I probed it standalone — token := parse(r), if password == other {, max_tokens: 100, tokens = 5, case token: all pass; password: hunter2, API_KEY=abc123 and the quoted JSON/PHP forms are dropped. It also drops prose such as // the token: refreshed hourly and pwd: /home/x; that is the fail-closed side for a public display, so I would not change it.

One note, not a defect in this PR: the production shutdown path registers b.dashSrv.CloseContributeHub() as the hook (src/cmd/hive/main.go:2484-2486), not Server.Close(), so the matrix goroutine is still only stopped where Close() is called (tests). #15972 explicitly scoped itself to Server.Close and called the process-lifetime case harmless, so this matches the issue; swapping that hook to Close() could be a one-line follow-up if anyone cares.

@hivecommons-hive
hivecommons-hive Bot merged commit 0931a17 into v5 Oct 31, 2026
78 of 79 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-15971 branch October 31, 2026 08:16
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#15982c0ebe4c` sha256:b170e9c80884f878fd123f48316e18a70b2d55ee28dd98e5a6c01e4b346c182f — download from the dashboard or `hivectl review evidence #15982`.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

0 participants