Repository navigation
refactor: ♻️ Consolidate label clean and host bypass - #1650
Conversation
Signed-off-by: Evaline Ju <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit details
Walkthrough
Merge Risk:
|
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This is a good consolidation. The four matchesAnyHost copies become internal/hostmatch.MatchesAny, using the lineage variant that case-folds and handles IPv6. The ledger, usage and agentop label sanitisers and truncators now all call pipeline.SanitizeControlRunes, pipeline.HasControlRunes and pipeline.TruncateLabel. I checked the behaviour of each removed copy against what replaces it:
- Ledger and usage
sanitizeLabel: the logic was byte-for-byte the same asSanitizeControlRunes, including the fast path that skips allocation and the handling of invalid UTF-8. Nothing changes. - agentop
tui.sanitizeLabel: it had an open-coded C0/C1/DEL/bidi switch plusIsControlRune, and now uses the same set. As a bonus, clean strings no longer allocate. - agentop
sanitizeCell: this widens from C0/DEL only to the full set. That is the intended fix, and the C0 assertions inconfigure_status_test.gostill hold. truncateLabelandcapUA: these now callTruncateLabel(s, n)with the same walk-back. The new pipeline test pins the exact cut length for 2-, 3- and 4-byte runes and for U+FFFD, and the 1-byte prefix is kept. That is tighter than the usage test it replaces.- Host bypass in ibac, sparc and cpex: the old code cut at the first
:, so any IPv6 literal became[. Matching now usesnet.SplitHostPortand lower-cases both sides. Case-folding only makes the bypass match the same DNS name the request already reaches, so it does not widen what an attacker can reach. cpex and lineage keep their outbound-only gating.
No must-fix issues. There is one inline suggestion, plus two small nits that fall outside the diff hunks:
core/pipeline/client.go:185: theIsControlRunedoc still says "The ledger's copy will carry the same clauses in the same order." After this PR the ledger has no copy, so that sentence is stale.- The commit subject
:recycle: Consolidate label clean and host bypasshas no conventional prefix (the PR title does). This is advisory only. - Optional:
docs/ibac-plugin.md,docs/sparc-plugin.mdanddocs/cpex-plugin.mdcould say thatbypass_hostsmatching is now case-insensitive and IPv6-aware, asdocs/lineage-wire-contract.mdalready does.
Author: evaline-ju (CONTRIBUTOR association; repo permission admin, so maintainer)
Areas reviewed: Go (core/pipeline, core/cost/{ledger,usage}, core/plugins/{ibac,sparc,cpex,lineage}, new core/plugins/internal/hostmatch, cmd/agentop), tests, security
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed off: yes
CI status: passing. CodeRabbit and Go CI (core peerproc, macOS) were still pending when I reviewed.
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
I re-reviewed at f0b7dce. The follow-up commit deals with everything from my earlier review of b64725a:
- Bracketed IPv6 with no port:
hostmatch.MatchesAnynow strips the brackets whennet.SplitHostPortfails, so[::1]matches::1. Thelen(host) > 1guard keeps a lone[safe, and the{"[::1]", true}case covers it in the test table. This does not widen the bypass. The same input with a port ([x]:p) already had its brackets dropped bySplitHostPort, so the portless form now behaves the same way. - Stale doc sentence: the "ledger's copy" sentence is gone from the
IsControlRunedoc incore/pipeline/client.go. The remaining "ledger's copy" mentions incore/cost/usagemean the stored label data, not a duplicate of the code, so they are still accurate. - Plugin docs:
docs/ibac-plugin.md,docs/sparc-plugin.mdanddocs/cpex-plugin.mdnow say thatbypass_hostsmatching is case-insensitive and strips the port and IPv6 brackets. This matches the implementation anddocs/lineage-wire-contract.md.
On this head, go test passes locally for core/plugins/{internal/hostmatch,ibac,sparc,lineage}, core/pipeline, core/cost/... and cmd/agentop/tui, and go vet and gofmt are clean. Two cmd/agentop tests fail here, TestServiceInstall_RefusesABrokenConfig and TestReportSessionInterruption. They fail the same way on main (3141461), because this sandbox has no systemd user bus and can't inspect loopback connections. They are not related to this PR.
No must-fix issues and no new inline comments. One advisory nit remains: the commit subjects (:recycle: ..., :memo::goal_net: ...) have no conventional prefix. The PR title does, and that is the part that gets checked.
Author: evaline-ju (CONTRIBUTOR association; repo permission admin, so maintainer)
Areas reviewed: Go (core/plugins/internal/hostmatch, core/pipeline, core/cost/{ledger,usage}, core/plugins/{ibac,sparc,cpex,lineage}, cmd/agentop), tests, docs, security
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed off: yes (DCO passing)
CI status: pending. DCO, PR title, action pinning, Hadolint and Dependency Review pass. Go CI, CodeQL and the image builds were still running when I reviewed.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
I re-reviewed at 397c3f5. The only change since f0b7dce, which I approved, is :bulb: Consolidate sanitize spelling. It is 8 comment-only line changes in five files: sanitised/sanitiser/sanitises/serialised/recolours become the -ize/-or forms in core/cost/ledger/{row,store,query_test}.go, core/cost/usage/usage.go and core/pipeline/client.go. No code, identifiers, test names or strings changed, so the behaviour I checked in the earlier reviews still holds.
One optional nit is inline. The sweep only covers the lines this PR already touched, so the same comment blocks still mix both spellings (for example Sanitising in rowLabel's doc, two lines below the corrected sanitized). A follow-up or a codespell rule would finish the job. It doesn't block this PR.
Author: evaline-ju (CONTRIBUTOR association; repo permission admin, so maintainer)
Areas reviewed: Go comments in core/cost/{ledger,usage} and core/pipeline (incremental f0b7dce..397c3f5); full-PR re-scan for agent/IDE config and security
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed off: yes (DCO passing)
CI status: passing. Every required check is green, including Go CI, CodeQL, Trivy and the image builds. Go CI (core peerproc, macOS) was still pending when I reviewed, and Spellcheck was skipped.
| // CWE-150. This is the primary guard for Endpoint, Model and Provenance, and defence in | ||
| // depth for Agent, which pipeline.ParseUserAgent already sanitized. | ||
| // | ||
| // THE ORDER MATTERS. Sanitising can triple a string's length — every replaced byte becomes |
There was a problem hiding this comment.
nit: The comment above now says sanitized, but this line still says Sanitising. The same split appears in usage.go (ringLabel's sanitised, then capped / sanitising can triple) and in client.go (sanitised (see, the sanitiser). This is optional: either finish the sweep in these doc blocks or leave it for a repo-wide codespell pass.
There was a problem hiding this comment.
I purposely only updated lines that were already going to be touched by the PR, not existing other comments
Summary
Replaces the duplicated label-cleaning and bypass-host matching code in the cost packages,
agentopand four plugins with one shared helper each. Labels now look the same on screen as in storage, and bypass_hosts in ibac, sparc and cpex now ignores case and handles IPv6 hosts, as lineage already didRelated issue(s)
Closes #1581
Summary by CodeRabbit