Skip to content

πŸ› fix(logread): redact an own secret value in its JSON-escaped form - #16914

Merged
hivecommons-hive[bot] merged 2 commits into
hivecommons:v6from
Danathar:fix/logread-secret-json-escaped
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
hivecommons:v6from
Danathar:fix/logread-secret-json-escaped

Conversation

@Danathar

@Danathar Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

log_read redacts the hive's own secret values (the dashboard token, secret files, secret-named environment values) before it returns log lines. It missed a value that contains a quote, a backslash or a control character, so that value came back readable. This PR redacts it. Values made only of letters, digits and ordinary punctuation were always redacted.

What went wrong

The logs are stored as JSON. A value such as pa"ss\word-0123456789 is therefore on disk as pa\"ss\\word-0123456789. The redaction looked for each secret in its plain, URL-encoded and base64 forms. None of them matches the JSON-escaped text:

{"msg":"connecting","password":"<redacted:hive-secret-value>"}      plain value: redacted
{"msg":"connecting","password":"pa\"ss\\word-0123456789"}           quote and backslash: returned as is

This matters for passwords more than for tokens, which rarely contain such characters. Reading logs needs the read-write role.

What changes

The redaction also looks for each value as it is written inside a JSON string, with and without HTML escaping. Nothing else about the scrubbing changes, and ordinary text is not affected.

Files

  • src/crux/logread/secrets.go: secretForms adds jsonEscapedForms.
  • src/crux/logread/secret_json_form_test.go: new.
  • src/docs/design/admin-mcp.md: the "Scrubbing" paragraph lists the form.
  • changelog.d/security-logread-secret-json-escaped.md

Tests

  • TestOwnSecretIsRedactedInItsJSONEscapedForm: six values written through the real slog JSON handler and read back with Read.
  • TestOwnSecretIsRedactedInHTMLEscapedJSON
  • TestJSONEscapedFormsAddNothingForPlainValues
  • With the new forms switched off, the quote, tab and escape-character cases and the HTML-escaped case fail.
  • The whole ./crux/logread/ package passes.

πŸ€– Generated with Claude Code

The read-time secret scrubber replaces each of the hive's own secret
values in its plain, URL-encoded and base64 forms. The hive log, the
request log and the output sources are JSON, so a value that holds a
quote, a backslash or a control character is on disk only JSON-escaped,
and none of those forms matched it: the value was returned readable.

secretForms now also yields the value as written inside a JSON string,
with and without HTML escaping.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 6, 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 hanthor 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

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

PR Title Relation Files
#16884 ✨ feat(adminmcp): read and act on the Activity monitor; writes run as the verified caller same files src/docs/design/admin-mcp.md

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks correct to me; one small doc suggestion.

Read src/crux/logread/secrets.go at 4a21f49. jsonEscapedForms (line 98) feeds secretForms, and NewSecretScrubber (lines 31-62) already dedups forms through a set and orders the replacer longest-first, so a value with nothing to escape gains no duplicate entry and the escaped form of a value that does cannot be shadowed by a shorter one. log/slog's JSON handler escapes strings the way encoding/json does with HTML escaping off, so the escapeHTML=false form matches the hive log exactly and the true form covers the encoding/json-written output sources; the test matrix (quote/backslash, control chars, <>&, non-ASCII) exercises both.

Suggestion, not a defect: the SecretScrubber type comment at secrets.go:20-22 still says the replacer covers "plain, URL-encoded and base64 forms". Worth adding "JSON-escaped" there to match the admin-mcp.md paragraph this PR updates, since that comment is the first thing the next reader sees.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor
4a21f49

ℹ️ Sentinel notice β€” informational; author is trusted (owner), merge is not blocked

Hive flagged this PR (author @Danathar, head 4a21f499430d) because it matches behaviors that can override security controls, escalate privileges or damage the codebase. This is a heuristic, not an accusation β€” a maintainer should confirm the change is intended before it merges.

  • sensitive_path β€” changes 1 sensitive path(s) (Touches a sensitive path (OWNERS, workflows, policies, hive config, security docs, …))
    • src/crux/logread/secrets.go

Hive did not add the sentinel-alert label because this author is trusted. The finding remains recorded for audit and the dashboard Security tab; set sentinel.trusted_authors_block: true to require the blocking label for trusted authors too.

Review suggestion on this PR: the SecretScrubber comment still listed the
plain, URL-encoded and base64 forms only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Done in the latest commit: the SecretScrubber type comment now lists the JSON-escaped form with the others. Comment only; ./crux/logread/ still passes.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the change against crux/logread/secrets.go on v6; it slots cleanly into the existing form-set mechanism and I found no defect.

Verified

  • NewSecretScrubber (secrets.go:30-61) dedupes forms through a map[string]bool and sorts longest-first before building the strings.Replacer, so for a value with nothing to escape the two new forms collapse into the existing plain one (as TestJSONEscapedFormsAddNothingForPlainValues asserts) and no duplicate pair reaches the replacer. The MinSecretValueLen filter is applied per form, same as the URL/base64 forms.
  • Replace (:66-75) counts markers in output minus input, so the JSON forms don't change the counting contract.
  • The JSON form produced by encoding/json matches what log/slog's JSON handler writes: appendEscapedJSONString ($GOROOT/src/log/slog/json_handler.go:185) uses the non-HTML safeSet, short escapes for \n \r \t, and \u00XX for other control bytes β€” the same as SetEscapeHTML(false); the SetEscapeHTML(true) form covers records written by plain json.Marshal. The test suite writes through the real slog handler, so this is exercised rather than assumed.
  • go build ./crux/logread/ on ef9e202 is clean; CI is green apart from pending tide. Design doc paragraph and changelog fragment updated with the diff.

Looks correct to me.

β€” hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

hivecommons-hive Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Reviewed by reviewer-2 β€” no findings.

Reviewer notes

Read src/crux/logread/secrets.go at ef9e202 and the slog handler it has to match. Looks correct to me.

  • jsonEscapedForms (secrets.go:98-113) produces the EscapeHTML=false and EscapeHTML=true encodings. log/slog's JSON handler uses appendEscapedJSONString, which is encoding/json's string encoder with escapeHTML off (json_handler.go:184), so the first form is byte-identical to what the hive log writes, including \u001b-style control escapes; the second covers json.Marshal records.
  • Forms are deduplicated in NewSecretScrubber (secrets.go:32-41), so a value with nothing to escape adds no new replacer entry, and the marker contains no quote or backslash, so a redacted line stays valid JSON.
  • TestOwnSecretIsRedactedInItsJSONEscapedForm goes through the real slog.NewJSONHandler and Read, so it exercises the on-disk form rather than a hand-written fixture.

No findings from any perspective.

Evidence bundle `#16914ef9e202` sha256:f11e281f47c90caa853b3b6afef848624fad93ab536a8d0952cb2a0b07bbc567 β€” download from the dashboard or `hivectl review evidence #16914`.

@hivecommons-hive
hivecommons-hive Bot merged commit d3c9ce9 into hivecommons:v6 Nov 6, 2026
68 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant