Chrome says my localhost certificate is invalid
NET::ERR_CERT_AUTHORITY_INVALIDShort 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.
Fix it fast
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 --trust2Match what you see, then jump to its fix
- 1
NET::ERR_CERT_AUTHORITY_INVALID on a certificate made by the .NET SDK.The development certificate exists but is not trustedFix - 2
NET::ERR_CERT_DATE_INVALID, and the project worked until now without changes.The development certificate has expiredFix - 3
The certificate was created with openssl and only a common name (CN=localhost).A certificate you made yourself has no subject alternative nameFix - 4
Visual Studio's IIS Express profile shows the warning while dotnet run is fine.The IIS Express certificate in Visual Studio is damagedFix
- 1
What does the error look like?
NET::ERR_CERT_AUTHORITY_INVALIDNET::ERR_CERT_DATE_INVALIDYour 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 --trust2Fix
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 --trust3Verify
The check command reports a valid, trusted certificate, and the page loads without a warning.
dotnet dev-certs https --check --trustConfirmed by learn.microsoft.com
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 --trust2Fix
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 --trust3Verify
After a full browser restart the warning is gone.
dotnet dev-certs https --check --trustConfirmed by learn.microsoft.com
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 subjectAltName2Fix
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 subjectAltNameConfirmed by rfc-editor.org
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 --trust2Fix
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 --trust3Verify
Start the IIS Express profile from a freshly started Visual Studio and open the HTTPS URL.
dotnet dev-certs https --check --trustConfirmed by learn.microsoft.com
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 fixWeb 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 fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Apollo Client is blocked by CORS when the GraphQL server runs on AWS Lambda
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Apollo Server does not set CORS for you when it runs behind a framework or integration, and on Lambda that layer is API Gateway.
5 causes, each with a fix