From dd25f3e9a8344119f1a415d7045a2f6886460a43 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 4 Dec 2026 00:36:52 +0000 Subject: [PATCH] Keep payment method ids out of domain command output. leak-check flagged paymentMethodId because the generated registrar client names that field. Those hits are property names with no card id. The check still fails on a value, an example, or any other payment-method spelling. Domain order JSON included the id the quote selected. Strip it before printing. Text output never showed it, and checkout still sends it to the API. Co-authored-by: Shayguun --- internal/cli/domain_order.go | 6 +++++- internal/cli/domain_test.go | 6 ++++++ scripts/openapi-leak-check.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/internal/cli/domain_order.go b/internal/cli/domain_order.go index 4fb0f2e..bf95ee2 100644 --- a/internal/cli/domain_order.go +++ b/internal/cli/domain_order.go @@ -368,7 +368,11 @@ func printQuote(w io.Writer, q *generated.V1DomainOrderQuote) { func printOrderResult(e *domainEnv, o *generated.V1DomainOrder) error { if e.json { - return writeJSONTo(e.out, o) + // The order carries the card id the quote selected. It is used to + // check out and is not part of the command output. + sanitized := *o + sanitized.PaymentMethodId = nil + return writeJSONTo(e.out, &sanitized) } outf(e.out, "Order %s: %s\n", deref(o.Id), stateLabel(string(deref(o.State)), "DOMAIN_ORDER_STATE_")) tw := tabwriter.NewWriter(e.out, 0, 0, 2, ' ', 0) diff --git a/internal/cli/domain_test.go b/internal/cli/domain_test.go index 38f4c7f..3342f4c 100644 --- a/internal/cli/domain_test.go +++ b/internal/cli/domain_test.go @@ -151,6 +151,9 @@ func TestDomainRegisterHappyPath(t *testing.T) { if got := out.String(); !strings.Contains(got, "completed") || !strings.Contains(got, "example.com") || !strings.Contains(got, "succeeded") { t.Errorf("result: %s", got) } + if strings.Contains(out.String(), "pm-default") || strings.Contains(errOut.String(), "pm-default") { + t.Errorf("payment method id echoed: stdout %q stderr %q", out, errOut) + } } func TestDomainRegisterUsesGivenCard(t *testing.T) { @@ -319,6 +322,9 @@ func TestDomainRegisterJSON(t *testing.T) { if err := json.Unmarshal(out.Bytes(), &got); err != nil || got["state"] != "DOMAIN_ORDER_STATE_COMPLETED" { t.Fatalf("json %s: %v", out, err) } + if _, ok := got["paymentMethodId"]; ok || strings.Contains(out.String(), "pm-default") { + t.Fatalf("payment method id leaked into json: %s", out) + } } func TestWaitForDomainOrderTimeout(t *testing.T) { diff --git a/scripts/openapi-leak-check.sh b/scripts/openapi-leak-check.sh index e7cab04..a808b0f 100755 --- a/scripts/openapi-leak-check.sh +++ b/scripts/openapi-leak-check.sh @@ -67,8 +67,36 @@ scan() { done } +# paymentMethodId is the registrar field the CLI sends (--card) and reads back +# so checkout charges the card the quote was priced for. In the generated +# client that word appears only as a property name: a YAML key with nothing +# after the colon, or a Go struct field whose json tag repeats the name. +# Those lines hold no card id. Any other hit — a value, an example, a comment, +# renewalPaymentMethodId, payment_method — still fails this check. +# The CLI never prints the id; see printOrderResult. +payment_method_name_only() { + local content="$1" + printf '%s\n' "${content}" | grep -qE '^[[:space:]]+paymentMethodId:[[:space:]]*$' && return 0 + printf '%s\n' "${content}" | grep -qE '^[[:space:]]+PaymentMethodId[[:space:]]+\*string[[:space:]]+`json:"paymentMethodId(,omitempty)?"`[[:space:]]*$' && return 0 + return 1 +} + for p in "${PATTERNS[@]}"; do hits="$(scan "${p}")" + if [[ "${p}" == '[Pp]aymentMethod|payment_method' ]]; then + kept="" + while IFS= read -r hit || [[ -n "${hit}" ]]; do + [[ -z "${hit}" ]] && continue + # scan prefixes "path:line:"; the rest is the source line. + content="${hit#*:}" + content="${content#*:}" + if payment_method_name_only "${content}"; then + continue + fi + kept+="${hit}"$'\n' + done <<<"${hits}" + hits="${kept}" + fi if [[ -n "${hits}" ]]; then fail "pattern ${p} found in ${GEN_DIR}:" head -20 <<<"${hits}" >&2