Repository navigation
fix(auth): drop raw IdP error bodies from CLI errors - #27
Conversation
When a device-code, polling, or refresh request gets a non-2xx answer with no `error` code, oauth2.RetrieveError.Error() embeds the raw response body after a newline. The auth commands wrapped that error with %w, so a hostile IdP or a TLS interceptor could forge stderr lines. main.go already escapes control characters (PR #25) but keeps newlines. Replace the three wraps with idpError, which rebuilds the message from the HTTP status code and, when present, the error code and description, each cut to 200 bytes and escaped. Invalid UTF-8 is quoted as well, since a form-encoded response can decode to a raw 0x9b (8-bit CSI). Other errors still wrap with %w. Refs: linuxfoundation/lfx-self-serve-ops#1719 Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: David Deal <ddeal@linuxfoundation.org>
|
@dealako I'm starting review 1 of this pull request now (started 2026-11-20 23:40 UTC using review agent v0.1.34). This usually takes a few minutes. I'll update this comment with the summary when I'm done. If there's no summary here after about 45 minutes, the review stopped: push a new commit, or post a comment that begins with a mention of me followed by Thanks for the clear write-up and the thorough tests, David. SummaryThis pull request replaces the three raw DecisionThis pull request passed automated review. This repository is set to review only, so I never approve pull requests here. A maintainer needs to review and approve it before merge. DetailsOverall impression: Documentation reminder: changed Rule files: read Questions, problems, or feedback: https://github.com/linuxfoundation/lfx-review-agent/issues |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the authentication-error sanitization change.
No open issues 🎉
What changed in this PR
This PR hardens LFX CLI authentication errors by dropping raw identity-provider response bodies, closing the newline-forging gap left by the earlier terminal-output escaping change.
Changes:
- Routes device-code, polling, and refresh failures through a shared error helper.
- Reports numeric HTTP status codes and bounded, escaped OAuth error fields while preserving wrapping for other errors.
- Adds tests for body removal, control-character escaping, UTF-8-safe truncation, invalid UTF-8, and error wrapping.
| File | Description |
|---|---|
internal/commands/auth.go |
Adds sanitized identity-provider error formatting at all three authentication error sites. |
internal/commands/auth_test.go |
Adds regression tests for safe error output and preserved wrapping behavior. |
Review effort: Balanced
lfx-one
left a comment
There was a problem hiding this comment.
This pull request passed automated review. This repository is set to review only, so I never approve pull requests here. A maintainer needs to review and approve it before merge.
Documentation
This pull request changes behavior that may also be described outside this repository, such as product pages or an external docs site. I can't read those, so please check them; the author and maintainers own those updates. Changed here:
identity provider error messages for login and token refresh (HTTP status only, escaped code and description)(behavior changed)
audigregorie
left a comment
There was a problem hiding this comment.
PR Review — #27: fix(auth): drop raw IdP error bodies from CLI errors
Branch: bug/IdP-token-endpoint-error → main
Reviewed commits: 0ba1f7eba73f0c66411d26ebea6ee363bb258705..8b92d00cf891ab84fbd8db4b71307995af2cd40a
Commits: 1 | Files changed: 2 | Scope: Go CLI authentication error handling
Issue counts: Critical: 0 | Major: 0 | Minor: 0
Issue threads from this run: 0 | Unposted findings: 0
No defensible defects retained after the applicable source-review passes.
What's Done Well ✅
- All three OAuth error exits use the sanitizer, while expiry, denial, and revoked-session messages remain unchanged.
- Raw response bodies and server-controlled HTTP reason phrases are excluded. Displayed error fields are bounded and escape both control characters and invalid UTF-8.
- Other errors retain
%wwrapping; the API and Goa command callers propagate the sanitized refresh error without relying on its former concrete type.
Review coverage and limitations
- Both changed files were read in full at the pinned head; removed wrappers were inspected in the merge-base diff.
- Traced device login, token refresh,
auth token,runAPI,resolveAuthenticatedBaseURL,goaService.run, and the final stderr sanitizer. Compared existing terminal-safety and error-propagation patterns. - Checked the linked issue's fix criteria: https://github.com/linuxfoundation/lfx-self-serve-ops/issues/1719. Source supports the described status-only uncoded errors, bounded/escaped coded errors, numeric status use, and unchanged special cases.
- Inspected official
golang.org/x/oauth2v0.38.0 source (deviceauth.go,internal/token.go,token.go, and relevantoauth2.gotoken-source methods), confirming RetrieveError response construction and propagation rather than relying on the issue's older dependency assumptions. - Completed consistency, truthfulness, available-rules, correctness, edge-case, security, integration/data, and regression passes, including missing codes, malformed error bodies, control bytes, truncation boundaries, and ordinary transport errors.
CLAUDE.mdis absent from the pinned checkout. The fixed Angular/NestJS/cross-app checklists are not applicable to this Go CLI change.- Tests were not executed or assessed for strength. The PR's reported test/lint results were not independently verified. Lint, type checks, and builds were not run; this is source inspection, not runtime verification.
- No additional follow-up work identified within this review's scope.
Rating: ⭐⭐⭐⭐⭐
Review outcome: APPROVE — no retained defects
Zero findings do not imply exhaustive runtime verification.
emsearcy
left a comment
There was a problem hiding this comment.
Styling (from revive, per Go standard style):
internal/commands/auth.go:779:7: const maxIdPErrorTextBytes should be maxIDPErrorTextBytes
MegaLinter's revive var-naming rule failed on maxIdPErrorTextBytes. Rename it to maxIDPErrorTextBytes, and rename the test for a body without an error code so cspell has no new unknown word. Refs: linuxfoundation/lfx-self-serve-ops#1719 Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: David Deal <ddeal@linuxfoundation.org>
|
@dealako I'm starting review 2 of this pull request now (started 2026-11-23 17:38 UTC using review agent v0.1.34). This usually takes a few minutes. I'll update this comment with the summary when I'm done. If there's no summary here after about 45 minutes, the review stopped: push a new commit, or post a comment that begins with a mention of me followed by Thanks for the quick turnaround on the lint finding, David. SummaryThe new commit renames the error-text cap constant to DecisionThis pull request passed automated review. This repository is set to review only, so I never approve pull requests here. A maintainer needs to review and approve it before merge. DetailsOverall impression: The commit 👏 Nice work: You fixed the lint finding within minutes of it being reported, and you renamed the test as well so cspell has no new unknown word. Rule files: read Questions, problems, or feedback: https://github.com/linuxfoundation/lfx-review-agent/issues |
lfx-one
left a comment
There was a problem hiding this comment.
This pull request passed automated review. This repository is set to review only, so I never approve pull requests here. A maintainer needs to review and approve it before merge.
The new commit only renames the error-text cap to maxIDPErrorTextBytes (the revive finding) and the matching test; I found no new issues.
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThe PR replaces raw identity-provider error messages at the device-code, polling, and refresh call sites.
No actionable issues found. dealako explicitly chose status-only output for responses without an error code. dealako also acknowledged helper-only tests and manual call-site review. Tests were reviewed, not run. Reviews (1) · Last reviewed commit: "style(auth): use revive's IDP initialism..." · Reviewed by Greptile |
|
@emsearcy Done. Commit f095d61 renames the constant to |
Review Feedback AddressedCommit: f095d61 Changes Made
No Change Needed
Feedback Items Addressed2 of 2 actionable feedback items addressed, both from general review bodies. Threads Resolved0 of 0. The PR has no inline review threads. MegaLinter and every other check pass on f095d61. |
Review feedback has been addressed in commit f095d61. Re-requesting your review.
Summary
When the device-code, polling, or refresh request gets a non-2xx answer with no
errorcode,oauth2.RetrieveError.Error()builds its message asoauth2: cannot fetch token: <Status>\nResponse: <raw body>, with up to 1 MiB of body.lfxwrapped that error with%wand printed it to stderr. A hostile IdP, or a TLS interceptor with an OS-trusted certificate for the Auth0 domain, could forge stderr lines on any command that refreshes a token (CWE-150).PR #25 already escapes control characters in
main.go, but it keeps newlines, and its description left this ticket open for that gap.Fixes linuxfoundation/lfx-self-serve-ops#1719 (Claude Security finding
find_01Uy8E9MynboQV3pejq3FVrd).Changes
idpErrorhelper ininternal/commands/auth.go, used by the three wraps:request device code,unexpected error waiting for login, andrefresh access token.errorcode: the message is<prefix>: identity provider returned HTTP <code>. The body is dropped.errorcode: the code and description follow the status, each cut to 200 bytes on a rune boundary and escaped. Invalid UTF-8 is quoted too, since a form-encoded response can decode%9Bto a raw 8-bit CSI byte.Response.StatusCode, notResponse.Status, because the reason phrase is server-controlled.%w.expired_token,access_denied, deadline,invalid_grant) and themain.goescaping are unchanged.Status-only output for uncoded responses is a deliberate choice for this fix. Maintainers can add richer IdP error messages later if they want them.
Testing
make check: 0 issues.make test: pass. gitleaks: clean.internal/commands/auth_test.go:\x1b[2Jand\nand no error code gives a message with neither byte.0x9b) in the description is quoted.RetrieveErrorerrors still wrap.🤖 Generated with Claude Code