Skip to content

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

Open
brtkwr wants to merge 3 commits into
mainfrom
bkunwar/plat-1314-http-diagnostics
Open

brtkwr wants to merge 3 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 9c387b5336c5e4993ae3a0ef7785e6d750dbd8c9, CI run 40862346375 passed both jobs:

  • build: go build ./..., embedded-spec drift verification, and all tests through make test-cover passed, including the 80% coverage 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 local tests. Review fixes were pushed through the GitHub connector with an expected-head lease; the remote head and changed file contents were verified.

Ticket

Refs PLAT-1314.

✨ 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-10-29T11:06:10.488696Z 9c387b5 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 👍 / 👎.

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.

1 participant