Skip to content

Updating hash function for MsalAuth._client_credential_cache#347

Closed
rodrigobr-msft wants to merge 1 commit intomainfrom
users/robrandao/weak-hashes
Closed

Updating hash function for MsalAuth._client_credential_cache#347
rodrigobr-msft wants to merge 1 commit intomainfrom
users/robrandao/weak-hashes

Conversation

@rodrigobr-msft
Copy link
Copy Markdown
Contributor

This pull request updates the cryptographic hash algorithm used to compute certificate thumbprints in the MSAL authentication logic. The change improves security by switching from SHA-1 to SHA-256 for certificate fingerprinting.

Security improvement:

  • Updated the certificate thumbprint calculation in the _create_client_application method of msal_auth.py to use SHA-256 instead of the less secure SHA-1.

Copilot AI review requested due to automatic review settings March 31, 2026 22:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates MSAL certificate-based authentication to compute the certificate thumbprint using SHA-256 instead of SHA-1 when building the client_credential passed into ConfidentialClientApplication.

Changes:

  • Switched certificate fingerprinting from SHA-1 to SHA-256 for the client_credential['thumbprint'] value.
Comments suppressed due to low confidence (1)

libraries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py:234

  • There are unit tests for MsalAuth behavior, but the certificate-auth branch in _create_client_application (including thumbprint generation) isn’t covered. Please add a test that exercises AuthTypes.certificate with a real/generated PEM cert and asserts the credential dict passed to ConfidentialClientApplication contains the expected thumbprint algorithm/format.
                # Create an X509 object and calculate the thumbprint
                logger.info("Calculating thumbprint for the public certificate.")
                cert = load_pem_x509_certificate(
                    data=bytes(public_certificate, "UTF-8"), backend=default_backend()
                )
                thumbprint = cert.fingerprint(hashes.SHA256()).hex()

                self._client_credential_cache = {
                    "thumbprint": thumbprint,
                    "private_key": private_key,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

data=bytes(public_certificate, "UTF-8"), backend=default_backend()
)
thumbprint = cert.fingerprint(hashes.SHA1()).hex()
thumbprint = cert.fingerprint(hashes.SHA256()).hex()
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching the certificate thumbprint hash from SHA-1 to SHA-256 changes both the value and length (40 hex chars -> 64). Since this value is passed to MSAL as the client_credential['thumbprint'], please verify MSAL/AAD expects a SHA-256 thumbprint here; if MSAL is still using the x5t (SHA-1) header/claim, this will break certificate-based authentication. If SHA-256 is the goal, consider using the MSAL-supported field/claim for SHA-256 (e.g., x5t#S256 / a dedicated thumbprint_sha256 parameter) or providing both where supported.

Copilot uses AI. Check for mistakes.
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/weak-hashes branch April 1, 2026 21:40
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