Skip to content

Backport: no response-body reflection in API errors (#4421) - #4427

Open
stevenvegt wants to merge 2 commits into
V6.2from
backport-4421-v6.2
Open

Backport: no response-body reflection in API errors (#4421)#4427
stevenvegt wants to merge 2 commits into
V6.2from
backport-4421-v6.2

Conversation

@stevenvegt

Copy link
Copy Markdown
Member

What

Backport of #4421 (never reflect fetched response bodies in API responses) to V6.2.

Handlers that make an outbound request now return a static error description and pass the underlying error as the internal (logged, never serialized) error. Fetched content that is useful for debugging is debug-logged truncated via the new core.TruncateHTTPBody instead of being placed in a returned error. Covers the OpenID4VCI and OpenID4VP callback handlers, the token client's unparseable-response error, the did:web resolver's parse error, and the Discovery Service client.

Conflict resolution notes

Everything applied cleanly except auth/api/iam/openid4vci.go and its test: master's handleOpenID4VCICallback gained the OpenID4VCI 1.0 nonce-endpoint machinery after V6.2 branched, so the reflection fixes were applied by hand onto the V6.2 shape of the handler. Same pattern, same wording where the sites correspond (access token fetch, credential fetch, credential parse with truncated debug log, credential verify). The V6.2-only proof-building error was given the same treatment (static description, cause moved to the internal error). The nonce-endpoint sites from master do not exist on V6.2. Test assertions were adapted the same way, including the sentinel test that the unparseable credential body is not reflected in the OAuth2 error description.

The release notes conflict was resolved by adding an Unreleased section with only the #4421 bullet; it will combine trivially with #4424 when both merge.

Not applicable to V5.4: none of the affected modules (auth/api/iam, auth/client/iam, discovery, vdr/didweb) exist there, and the V5.4 auth v1 client already only logs response bodies (clipped) without reflecting them.

Testing

  • go build ./... passes; go test on auth/..., core/..., discovery/... and vdr/didweb is green on this branch.

)

* fix(auth): never reflect fetched response bodies in API responses

Several callback handlers formatted err.Error() (or a raw response body)
into the OAuth2 error_description or RFC7807 detail returned to the caller.
This can be used in an attack chain to disclose internal response data.

This PR fixes that by not including the error in the response body but instead log it in truncated form to the debug logs.

Assisted-by: AI
@qltysh

qltysh Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

3 new issues

Tool Category Rule Count
qlty Structure Function with many returns (count = 8): handleOpenID4VCICallback 3

@qltysh

qltysh Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (6)

RatingFile% DiffUncovered Line #s
Coverage rating: B Coverage rating: B
vdr/didweb/web.go100.0%
Coverage rating: B Coverage rating: B
core/http_client.go100.0%
Coverage rating: B Coverage rating: B
auth/api/iam/openid4vp.go50.0%745
Coverage rating: B Coverage rating: C
discovery/api/server/client/http.go100.0%
Coverage rating: B Coverage rating: B
auth/api/iam/openid4vci.go100.0%
Coverage rating: B Coverage rating: B
auth/client/iam/client.go100.0%
Total96.9%
🤖 Increase coverage with AI coding...
In the `backport-4421-v6.2` branch, add test coverage for this new code:

- `auth/api/iam/openid4vp.go` -- Line 745

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@stevenvegt stevenvegt changed the title Backport: no response-body reflection in API errors (#4421) to V6.2 Backport: no response-body reflection in API errors (#4421) Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants