Skip to content

fix: redact sensitive API error headers - #817

Open
ryanduguid wants to merge 3 commits into
XeroAPI:masterfrom
ryanduguid:fix/redact-api-error-headers
Open

fix: redact sensitive API error headers#817
ryanduguid wants to merge 3 commits into
XeroAPI:masterfrom
ryanduguid:fix/redact-api-error-headers

Conversation

@ryanduguid

Copy link
Copy Markdown

Summary

  • redact credential-bearing request and response headers before they are retained in ApiError
  • preserve safe diagnostic headers such as Accept, request IDs, content type, and rate-limit metadata
  • add regression coverage against the serialized payload constructed by generated API clients

This is intentionally additive to the currently open error-object work (#812 / #816): whichever error representation is adopted should not expose request credentials or response cookies.

Validation

  • npm test -- --runInBand src/test/apiError.spec.ts
  • npm test -- --runInBand
  • npm run build
  • git diff --check

@ryanduguid
ryanduguid marked this pull request as draft August 12, 2026 17:49
@ryanduguid
ryanduguid marked this pull request as ready for review August 18, 2026 15:06
tokenRequest() and queryApi() rejected the raw AxiosError, bypassing the
ApiError redactor entirely. AxiosError.toJSON() serialises error.config, so
a caller doing JSON.stringify(err) recovered the Basic base64(clientId:
clientSecret) header and the refresh_token body from the token request, and
the Bearer access token from queryApi (which backs the public
updateTenants()).

Both catch blocks now build an ApiError and reject the redacted, serialised
result, matching the pattern already used by every generated API client.

Adds nock-driven integration tests that fail against the unfixed client,
covering both paths with real axios failures rather than object literals.
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