Repository navigation
PLAT-1314/feat: add opt-in HTTP diagnostics on stderr - #12
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| case string: | ||
| return secretValueRe.ReplaceAllString(value, "[REDACTED]") |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
💡 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]") |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| message := strings.ReplaceAll(err.Error(), req.URL.String(), url) | ||
| record["error"] = secretValueRe.ReplaceAllString(message, "[REDACTED]") |
There was a problem hiding this comment.
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 👍 / 👎.
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
Context
PLAT-1314 specifies opt-in HTTP diagnostics:
-vfor timings and request IDs on successful and failed calls, and-vvfor redacted request/response details. twoctl currently captures request IDs only in HTTP errors and has no verbosity flag.Changes
-v/--verboseJSON diagnostics on stderr with method, URL, total duration, status, request ID, and transport/body-read errors. Pagination emits a diagnostic per page.-vvrequest/response headers and bodies, redacting sensitive headers/query/JSON values and API-key-shaped strings while preserving numeric precision.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:go build ./..., embedded-spec drift verification, and all tests throughmake test-coverpassed, including the 80% coverage gate.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