caelum0x 4b501667e2 fix(cli,tui): tenant Name rendered raw in status/TUI — a fourth unsanitized terminal-escape-injection call site rounds 13/16/23 never reached
ration status (the single most-run command in this repo, per round 13's
own framing)'s printTenantHeader printed tenant.Name completely raw, with
no sanitization at all. Same gap, same root cause, across the TUI: the
Tenants tab table, the Activity tab's per-row TenantName, and the card
form's tenant picker + adjust-limit infoLine all rendered a Tenant's own
Name raw too. services/tenant-registry's Create only validates name
non-emptiness, no charset check — round 16 already proved a raw ESC byte
survives into a persisted Tenant record via "tenant create --name".
Rounds 13/16/23 sanitized CardholderName, the CLI's own tenant-create
echo, and the Activity feed's Summary, but never Tenant.Name as read
back through these five separate call sites.

Reproduced live against the real bare-metal 8-service stack
(scripts/start-individually.sh): created a tenant with
--name $'Evil\x1b[31;1mINJECTED\x1b[0m Status Co', then byte-counted real
stdout — `ration status --tenant <id>` carried 2 raw ESC bytes pre-fix,
0 after. Drove the real bin/tui through a tmux pty: Tenants tab and the
card-issue form's tenant picker both rendered the literal bracket text
pre-fix verification showed was otherwise a live ANSI escape (confirmed
via `tmux capture-pane -e` byte inspection, distinguishing it from tmux/
lipgloss's own legitimate styling codes).

Fix: sanitizeControlChars(tenant.Name) in status.go's printTenantHeader;
format.SanitizedCell(t.GetName(), ...) in tui/view/tenants.go;
textsanitize.StripControlChars on ActivityRow.TenantName in
tui/view/activity.go; and on both the tenant picker's display name and
newAdjustLimitForm's tenantName param in tui/model/cardform.go — all via
the same helpers this repo's prior sanitization rounds already
established.

go build/go vet/go test clean for services/cli and services/tui (0
regressions), gofmt clean, full make build-go (10 binaries) clean.
2026-10-29 17:26:40 +03:00

61 lines
2.2 KiB
Go

package view
import (
"github.com/charmbracelet/lipgloss"
ledgerpb "github.com/caelum0x/ration/pkg/pb/ledger"
"github.com/caelum0x/ration/services/tui/internal/format"
)
var tenantHeaders = []string{"NAME", "CCY", "RESERVE FLOOR", "AVAILABLE", "HELD", "HEADROOM", "STATUS", "CREATED"}
var tenantWidths = []int{18, 5, 14, 14, 12, 14, 7, 19}
// Tenants renders the tenants tab: one row per tenant with its reserve
// floor, current ledger balance and the headroom actually available for
// bridge funding (available - reserve floor), the number that drives every
// rationing decision in docs/AGENT-DESIGN.md.
func Tenants(tenants []*ledgerpb.Tenant, balances map[string]*ledgerpb.Balance, cursor int) string {
rows := make([][]string, 0, len(tenants))
for _, t := range tenants {
bal := balances[t.GetId()]
available := int64(0)
held := int64(0)
if bal != nil {
available = bal.GetAvailableMinorUnits()
held = bal.GetHeldMinorUnits()
}
headroom := available - t.GetReserveFloorMinorUnits()
status := "OK"
if headroom < 0 {
status = "BREACH"
}
rows = append(rows, []string{
// t.GetName() is operator-supplied free text with no
// server-side charset validation (services/tenant-registry/
// internal/tenant.Service.Create only checks non-emptiness) —
// same unsanitized-free-text-into-terminal class rounds
// 13/16/23 already closed for CardholderName/the CLI's own
// tenant-create echo/the Activity feed's Summary, but never
// for a Tenant's own Name as rendered by this tab. Sanitize
// via the same helper decisions.go/cards.go already use.
format.SanitizedCell(t.GetName(), tenantWidths[0]),
t.GetCurrency(),
format.Money(t.GetReserveFloorMinorUnits(), t.GetCurrency()),
format.Money(available, t.GetCurrency()),
format.Money(held, t.GetCurrency()),
format.Money(headroom, t.GetCurrency()),
status,
format.Unix(t.GetCreatedAtUnix()),
})
}
return Table(tenantHeaders, rows, tenantWidths, cursor, 6, tenantStatusStyle)
}
func tenantStatusStyle(label string) lipgloss.Style {
if label == "BREACH" {
return lipgloss.NewStyle().Foreground(colorBad).Bold(true)
}
return lipgloss.NewStyle().Foreground(colorGood)
}