Skip to content

PLAT-1314/feat: add opt-in HTTP diagnostics on stderr - #12

Merged
brtkwr merged 4 commits into
mainfrom
bkunwar/plat-1314-http-diagnostics
Nov 2, 2026
Merged

brtkwr merged 4 commits into
mainfrom
bkunwar/plat-1314-http-diagnostics

Conversation

@brtkwr

@brtkwr brtkwr commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Context

PLAT-1314 specifies opt-in HTTP diagnostics: -v for timings and request IDs on successful and failed calls, and -vv for redacted request/response details. twoctl currently captures request IDs only in HTTP errors and has no verbosity flag.

Changes

  • Add -v/--verbose JSON diagnostics on stderr with method, URL, total duration, status, request ID, and transport/body-read errors. Pagination emits a diagnostic per page.
  • Add -vv request/response headers and bodies, redacting sensitive headers/query/JSON values and API-key-shaped strings while preserving numeric precision.
  • Bound detailed body logging to 4 MiB and read only a replay copy of request bodies. Diagnostic write failures do not change API results; stdout stays the API response.
  • Keep successful empty responses quiet by default, and add HTTP-level regressions for verbosity, redaction, pagination, failures, and body limits.

Scope / Non-goals

Durations include any retries and response-body reading; this does not change retry policy, credentials, or upstream API behavior. It starts from refreshed main including #9 and is independent of the current retry/context/keychain/version PRs. Existing Bharat ownership and recent activity/branch/PR checks found no competing diagnostics implementation.

Validation

On exact head bef76b673d71b9131526992f5627d0d882d629bd, CI run 41433103231 passed both jobs:

  • build: go build ./..., embedded-spec drift verification, and all tests through make test-cover passed, including the 80% coverage gate.
  • Total coverage 82.2% exceeded the 80% gate.
  • lint: all repository lints passed, including formatting.
  • Tests cover verbosity, request IDs, pagination, transport failures, numeric precision, request-body preservation and diagnostic limits, plus URL-valued body credentials (nested JSON and plain URLs), mixed-case/encoded query keys, userinfo, fragments and malformed URLs.
  • No tests ran locally. The integration merge was published without force-pushing and the resulting remote head was verified.

Ticket

Refs PLAT-1314.

Integration status — 2 November 2026

Merged current main (8a3ba6e9fb8269f4d6056c7419895902641ee356) into this branch without force-pushing. Resolved README and flag/reset conflicts by preserving both HTTP diagnostics and upstream retry/context/keychain changes. GitHub now reports no merge conflicts.

Review remains required. The existing P1 header-URL credential leak is unresolved and was not changed by this conflict-only repair. Green CI does not clear that finding.

✨ via Codex session

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T11:03:19.323154Z bef76b6 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44cf04b0e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/twoctl/cli/diagnostics.go Outdated
Comment on lines +126 to +127
case string:
return secretValueRe.ReplaceAllString(value, "[REDACTED]")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Redact credentials inside URL-valued body strings

When -vv logs a response containing a credential-bearing URL, this branch only redacts Two API-key-shaped substrings, so the credential remains in stderr. This occurs in the repository’s own PaymentLinkResponseSchema, whose payment_link example is https://checkout.two.inc/payment/initiation?token=abc123 (openapi/checkout-api.yaml:5560-5572): the key does not match the sensitive-name regex and abc123 does not match secretValueRe. Parse URL-valued strings and redact sensitive query parameters (or otherwise recognize embedded credential URLs) before emitting the supposedly redacted diagnostic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9c387b5. Body string redaction now parses URL values, redacts sensitive query parameters, userinfo and fragments, and fails closed on malformed URLs. Tests cover nested JSON, plain URLs and the real payment-link token example. CI passed on that head. The separate header-value finding is still open and is being addressed independently.

✨ via Codex session

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c387b5336

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if sensitiveHeaderRe.MatchString(key) {
out[key] = "[REDACTED]"
} else {
out[key] = secretValueRe.ReplaceAllString(out[key], "[REDACTED]")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Redact credentials embedded in URL-valued headers

When -vv processes a request or response header such as Location: https://checkout.two.inc/payment/initiation?token=abc123, the header name does not match sensitiveHeaderRe and the ordinary token does not match secretValueRe, so the credential is emitted to stderr unchanged. Apply the URL-aware redaction already used for body strings to non-sensitive-named header values before logging them.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bef76b673d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +37 to +38
message := strings.ReplaceAll(err.Error(), req.URL.String(), url)
record["error"] = secretValueRe.ReplaceAllString(message, "[REDACTED]")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Redact redirect URLs in transport errors

When a redirect target contains a credential-bearing URL and the redirect fails (for example, a signed Location URL whose host is unreachable or a redirect loop), Go includes that target URL in client.Do's error. This code only replaces the original request URL and then redacts Two API-key-shaped strings, so an ordinary value such as ?token=abc123 is emitted unchanged even with -v. Sanitize URLs embedded in the error or avoid logging the raw transport error.

Useful? React with 👍 / 👎.

@brtkwr
brtkwr merged commit 3b2f519 into main Nov 2, 2026
@brtkwr
brtkwr deleted the bkunwar/plat-1314-http-diagnostics branch November 2, 2026 14:03
brtkwr added a commit that referenced this pull request Nov 3, 2026
The diagnostics test from #12 posted an arbitrary body to order create,
which payload validation now rejects before the request is sent. It now
uses a probe operation whose schema declares the fields it sends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUnP8hJ3og3dxSHHcYij5n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants