Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 9, 2026

Changes proposed in this request

STS response headers may contain sensitive information (auth tokens, API keys, etc.) that should not be logged. Removed Headers from MsalServiceException.ToString() to prevent accidental exposure.

  • Modified MsalServiceException.ToString() to exclude Headers field from output
  • Headers property remains publicly accessible for programmatic access (no breaking changes)
  • Added test ServiceException_ToString_DoesNotIncludeHeaders() validating headers are excluded from string representation while remaining accessible via property

Before:

return base.ToString() + string.Format(
    CultureInfo.InvariantCulture,
    "\n\tStatusCode: {0} \n\tResponseBody: {1} \n\tHeaders: {2}",
    StatusCode, ResponseBody, Headers);

After:

return base.ToString() + string.Format(
    CultureInfo.InvariantCulture,
    "\n\tStatusCode: {0} \n\tResponseBody: {1}",
    StatusCode, ResponseBody);

Testing

  • Added unit test verifying headers not present in ToString() output
  • Validated Headers property remains accessible (existing test MsalServiceException_FromHttpResponse validates this)
  • Manual testing confirms no regressions

Performance impact

None. Reduced string allocation in ToString().

Documentation

  • All relevant documentation is updated.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] Remove Headers from exception ToString()</issue_title>
<issue_description>### Library version used

4.81.0

STS response headers can carry information that should not be logged. Remove it from exception toString() to avoid apps overlogging this.

Code is here: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/main/src/client/Microsoft.Identity.Client/MsalServiceException.cs#L248
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…g sensitive information

Co-authored-by: bgavrilMS <12273384+bgavrilMS@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove headers from exception ToString() method Remove Headers from MsalServiceException.ToString() to prevent logging sensitive data Jan 9, 2026
Copilot AI requested a review from bgavrilMS January 9, 2026 14:34
@bgavrilMS bgavrilMS marked this pull request as ready for review January 9, 2026 15:08
@bgavrilMS bgavrilMS requested a review from a team as a code owner January 9, 2026 15:08
@bgavrilMS bgavrilMS merged commit 213e542 into main Jan 9, 2026
11 checks passed
@bgavrilMS bgavrilMS deleted the copilot/remove-headers-from-exception branch January 9, 2026 18:52
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.

[Bug] Remove Headers from exception ToString()

4 participants