Back to results for “Security”
.NET MAUI › Security & Authentication

How do you enforce SSL/certificate pinning in MAUI?

Intermediate

Answer

Validate the server certificate in the HttpClient handler by comparing its public key/thumbprint to a pinned value, rejecting mismatches. Configure via HttpClientHandler.ServerCertificateCustomValidationCallback (or platform handlers). Pinning defends against MITM but requires a rotation plan when certs change.
var handler = new HttpClientHandler
{
    ServerCertificateCustomValidationCallback = (m, cert, chain, e) =>
        cert!.GetCertHashString() == PinnedThumbprint
};
Real-world example A finance app pins its API certificate so a compromised network CA can't intercept traffic.

Common follow-ups: What's the downside of pinning? | Where do you plan for cert rotation?