Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Chrome says my localhost certificate is invalid

ErrorNET::ERR_CERT_AUTHORITY_INVALID

Short answer

A local HTTPS certificate is rejected for one of three reasons: it was never trusted, it expired (ASP.NET Core development certificates last about 12 months), or a certificate you made yourself has no subject alternative name for localhost. Check which one, then reissue or trust it and restart the browser.

  • Applies to .NET 10, OpenSSL 3.0, Visual Studio 2022, Chrome 142
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Click Not secure, open the certificate and read its expiry date and subject alternative names, or ask the .NET tool whether a trusted certificate exists.

    dotnet dev-certs https --check --trust
  2. 2Match what you see, then jump to its fix

    1. 1NET::ERR_CERT_AUTHORITY_INVALID on a certificate made by the .NET SDK.The development certificate exists but is not trustedFix
    2. 2NET::ERR_CERT_DATE_INVALID, and the project worked until now without changes.The development certificate has expiredFix
    3. 3The certificate was created with openssl and only a common name (CN=localhost).A certificate you made yourself has no subject alternative nameFix
    4. 4Visual Studio's IIS Express profile shows the warning while dotnet run is fine.The IIS Express certificate in Visual Studio is damagedFix

What does the error look like?

  • NET::ERR_CERT_AUTHORITY_INVALID
  • NET::ERR_CERT_DATE_INVALID
  • Your connection is not private (https://localhost)

Cause 1 of 4

The development certificate exists but is not trusted

1Check

Installing the SDK puts the ASP.NET Core HTTPS development certificate in your user store without trusting it. Trusting is a separate, one-time step.

dotnet dev-certs https --check --trust

2Fix

Remove the old certificates, create and trust a new one, then close every browser window and open the app in a new one, because the browser caches the trust result.

dotnet dev-certs https --clean
dotnet dev-certs https --trust

3Verify

The check command reports a valid, trusted certificate, and the page loads without a warning.

dotnet dev-certs https --check --trust

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

The development certificate has expired

1Check

ASP.NET Core development certificates are valid for a limited period, typically 12 months. Look at the Valid to date in the certificate viewer.

dotnet dev-certs https --check --trust

2Fix

Clean and trust again, restart the running app so Kestrel loads the new certificate, and restart your IDE.

dotnet dev-certs https --clean
dotnet dev-certs https --trust

3Verify

After a full browser restart the warning is gone.

dotnet dev-certs https --check --trust

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

A certificate you made yourself has no subject alternative name

1Check

Clients must match the host in the URL against the certificate's identity, and RFC 9110 says a client must not use the common name for that. Print the extensions and look for DNS:localhost.

openssl x509 -in localhost.crt -noout -ext subjectAltName

2Fix

Create the certificate again with the name in a subjectAltName extension, then trust the new file in your system or browser.

openssl req -x509 -newkey rsa:2048 -noenc -days 365 \
  -keyout localhost.key -out localhost.crt \
  -subj "/CN=localhost" \
  -addext "subjectAltName = DNS:localhost,IP:127.0.0.1"

3Verify

The extension output now lists DNS:localhost.

openssl x509 -in localhost.crt -noout -ext subjectAltName

Confirmed by rfc-editor.org

Did this fix it?

Cause 4 of 4

The IIS Express certificate in Visual Studio is damaged

1Check

On Windows, look in the Current User certificate store for a localhost certificate. The ASP.NET Core one has the friendly name ASP.NET Core HTTPS development certificate. The IIS Express localhost certificate is a different one.

dotnet dev-certs https --check --trust

2Fix

Do not delete the IIS Express certificate by hand. Run Repair from the Visual Studio installer, then clean and trust the ASP.NET Core certificate as above.

dotnet dev-certs https --clean
dotnet dev-certs https --trust

3Verify

Start the IIS Express profile from a freshly started Visual Studio and open the HTTPS URL.

dotnet dev-certs https --check --trust

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Put a reminder to run dotnet dev-certs https --clean and --trust each year.
  • When you generate a certificate with openssl, always add -addext with the subjectAltName.
  • Never ship a development certificate in a container image or virtual machine.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

OpenAPI does not work in an ASP.NET Core minimal API

404 Not Found at /openapi/v1.json

ASP.NET Core 9 and later generate OpenAPI documents with the Microsoft.AspNetCore.OpenApi package: AddOpenApi registers it and MapOpenApi serves /openapi/v1.json.

3 causes, each with a fix

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.