Instantly share code, notes, and snippets.

Embed
What would you like to do?
Why you probably shouldn't use a wildcard certificate

Recently, Let's Encrypt launched free wildcard certificates. While this is good news in and of itself, as it removes one of the last remaining reasons for expensive commercial certificates, I've unfortunately seen a lot of people dangerously misunderstand what wildcard certificates are for.

Therefore, in this brief post I'll explain why you probably shouldn't use a wildcard certificate, as it will put your security at risk.

A brief explainer

It's generally pretty poorly understood (and documented!) how TLS ("SSL") works, so let's go through a brief explanation of the parts that are important here.

The general (simplified) idea behind how real-world TLS deployments work, is that you:

  1. Generate a cryptographic keypair (private + public key)
  2. Generate a 'certificate' from that (containing the public key + some metadata, such as your hostname and when the certificate will expire)
  3. Send the certificate to a Certificate Authority (like Let's Encrypt), who will then validate the metadata - this is where it's ensured that you actually own the hostname you've created a certificate for, as the CA will check this.
  4. Receive a signed certificate - the original certificate, plus a cryptographic signature proving that a given CA validated it
  5. Serve up this signed certificate to your users' clients

The client will then do the following:

  1. Verify that the certificate was signed by a Certificate Authority that it trusts; the keys of all trusted CAs already exist on your system.
  2. If it's valid, treat the public key included with the certificate as the legitimate server's public key, and use that key to encrypt the communication with the server

This description is somewhat simplified, and I don't want to go into too much detail as to why this is secure from many attacks, but the general idea is this: nobody can snoop on your traffic or impersonate your server, so long as 1) no Certificate Authorities have their own keys compromised, and 2) your keypair + signed certificate have not been leaked.

So, what's a wildcard certificate really?

A typical TLS certificate will have an explicit hostname in its metadata; for example, Google might have a certificate for mail.google.com. That certificate is only valid on https://mail.google.com/ - not on https://google.com/, not on https://images.google.com/, and not on https://my.mail.google.com/ either. In other words, the hostname has to be an exact match. If you tried to use that certificate on https://my.mail.google.com/. you'd get a certificate error from your browser.

A wildcard certificate is different; as the name suggests, it uses a wildcard match rather than an exact match. You might have a certificate for *.google.com, and it would be valid on https://mail.google.com/ and https://images.google.com/ - but still not on https://google.com/ or https://my.mail.google.com/. In other words, the asterisk can match any one single 'segment' of a hostname, but nothing with a full stop in it.

There are some situations where this is very useful. Say that I run a website builder from a single server, and every user gets their own subdomain - for example, my website might be at https://joepie91.somesitebuilder.com/, whereas your website might be at https://catdogcat.somesitebuilder.com/.

It would be very impractical to have to request a new certificate for every single user that signs up; so, the easier option is to just request one for *.somesitebuilder.com, and now that single certificate works for all users' subdomains.

So far, so good.

So, why can't I do this for everything with subdomains?

And this is where we run into trouble. Note how in the above example, all of the sites are hosted on a single server. If you run a larger website or organization with lots of subdomains that host different things - say, for example, Google with their images.google.com and mail.google.com - then these subdomains will probably be hosted on multiple servers.

And that's where the security of wildcard certificates breaks down.

Remember how one of the two requirements for TLS security is "your keypair + signed certificate have not been leaked". Sometimes certificates do leak - servers sometimes get hacked, for example.

When this happens, you'd want to limit the damage of the compromise - ideally, your certificate will expire pretty rapidly, and it doesn't affect anything other than the server that was compromised anyway. After fixing the issue, you then revoke the old compromised certificate, replace it with a new, non-compromised one, and all your other servers are unaffected.

In our single-server website builder example, this is not a problem. We have a single server, it got compromised, the stolen certificate only works for that one single server; we've limited the damage as much as possible.

But, consider the "multiple servers" scenario - maybe just the images.google.com server got hacked, and mail.google.com was unaffected. However, the certificate on images.google.com was a wildcard certificate for *.google.com, and now the thief can use it to impersonate the mail.google.com server and intercept people's e-mail traffic, even though the mail.google.com server was never hacked!

Even though originally only one server was compromised, we didn't correctly limit the damage, and now the e-mail server is at risk too. If we'd had two certificates, instead - one for mail.google.com and one for images.google.com, each of the servers only having access to their own certificate - then this would not have happened.

The moral of the story

Each certificate should only be used for one server, or one homogeneous cluster of servers. Different services on different servers should have their own, usually non-wildcard certificates.

If you have a lot of hostnames pointing at the same service on the same server(s), then it's fine to use a wildcard certificate - so long as that wildcard certificate doesn't also cover hostnames pointing at other servers; otherwise, each service should have its own certificates.

If you have a few hostnames pointing at unique servers and everything else at one single service - eg. login.mysite.com and then a bunch of user-created sites - then you may want to put the wildcard-covered hostnames under their own prefix. For example, you might have one certificate for login.mysite.com, and one (wildcard) certificate for *.users.mysite.com.

In practice, you will almost never need wildcard certificates. It's nice that the option exists, but unless you're automatically generating subdomains for users, a wildcard certificate is probably an unnecessary and insecure option.

(To be clear: this is in no way specific to Let's Encrypt, it applies to wildcard certificates in general. But now that they're suddenly not expensive anymore, I think this problem requires a bit more attention.)

@mholt

This comment has been minimized.

Copy link

mholt commented Mar 14, 2018

Not long ago, wildcard certificates were sought because of the very thing that makes them risky: convenience. It's "easy" to share a single wildcard certificate across multiple machines and services, and renew only one certificate to have all your services secured for another 2 years. But that was when certificates were managed manually.

The justifiable use cases I see for wildcard certificates in the age of automation is essentially just:

  • When you need to secure more hostnames (subdomains) than the CA's rate limits allow

... yeah. That's about it. (Maybe also if you have a wildcard entry in your DNS zone file, but that's even still not a great reason by itself.)

Usually these legitimate use cases are SaaS providers issuing subdomains to each of their customers, or Sandstorm.io URLs, etc. But don't get a wildcard certificate just because one day you "might need it."

Caddy will only issue wildcard certificates if you define the site in your Caddyfile like a literal wildcard DNS zone: *.example.com. You can't put a full hostname like sub.example.com in your Caddyfile and ask Caddy to get a wildcard certificate for that. (EDIT: Okay, there is a legitimate use case for fully-spelled-out hostnames that need wildcards, see this comment - so we added a wildcard subdirective but advise caution when using it!)

On top of that, Caddy has always put only one name on each certificate, to help limit the risk in a similar way.

Remember, with software like Caddy, you don't even have to think about certificates anymore (if you don't want to). You don't have to manage them, so convenience is no matter.

Wildcards have limitations too. You can't get a wildcard for *.*.example.com or sub*.example.com or sub.*.example.com. If you're serving sites dynamically in a way that wildcards don't cover, you can usually use Caddy's On-Demand TLS to obtain a certificate "on demand" during the TLS handshake. This works for any hostname, not just a certain subdomain of a specific name.

Wildcards are great and really shine in the few cases where they should be used, and it's awesome that they're now free! But I think they got way more hype than they deserve (although the engineering behind it from the LE team is definitely praise-worthy). IMO the biggest news this week is the release of ACMEv2, which is simpler, safer, and more robust. Here's to more certificates!

@jawnsy

This comment has been minimized.

Copy link

jawnsy commented Mar 15, 2018

One small advantage of wildcard certificates is privacy: all certificates will appear in Certificate Transparency logs, so if you have a service you want to keep hidden, issuing a wildcard certificate and having your server respond to a single subdomain would be one way to do it.

@MoonUnit2

This comment has been minimized.

Copy link

MoonUnit2 commented Mar 15, 2018

It's all about convenience. If/when a server hosting your SSL certificate gets owned, you revoke the compromised certificate and reissue it, then redistribute it. Granted this can be a pain in the butt if you have the same certificate on multiple servers, but is it really a huge problem when you have to recreate the certificates every 90 days?

I will probably issue a regular certificate for my web site, but then issue a wildcard for my internal hosts, even though it will be used on multiple servers. If everything is automated, the hassle factor isn't huge.

@joepie91

This comment has been minimized.

Copy link
Owner Author

joepie91 commented Mar 15, 2018

@jawnsy: If it matters whether your hostnames end up in a CT log, you probably have bigger problems. Hostnames are explicitly not private information, and are not treated as such by software. So this wouldn't be a valid reason for a wildcard certificate, either; if disclosure of your hostnames is a problem, then fix the actual underlying problem, because it shouldn't be an issue in the first place if your setup is correct.

@iquito

This comment has been minimized.

Copy link

iquito commented Mar 15, 2018

@joepie91: I think "hostname privacy" is a valid concern. Of course it is not a real defense for anything, but I for example have some specific API subdomains pointing directly to my servers, while everything else is protected by Cloudflare. Security is not a concern (meaning the API is secure, protected, etc.), but DDoS certainly always has to be a concern nowadays - and every time it is important to serve something directly from dedicated servers you run into the possibility of a DDoS attack vector. If you want to prevent a DDoS less knowledge about attack vectors is a big advantage.

@joepie91

This comment has been minimized.

Copy link
Owner Author

joepie91 commented Mar 16, 2018

@iquito: The same thing still applies; hostnames are not private information, therefore if your ability to protect your infrastructure depends on your hostnames remaining private, you're doing something wrong in the first place. CT logs are one of many ways in which a hostname can unintentionally leak. This is therefore not a valid reason to use wildcard certificates.

Aside from that, I don't recommend using Cloudflare at all; I've written a longer piece about the reasons for that here (and those reasons are partly security-related, in particular regarding TLS). Their DDoS mitigation model is quite broken, as well; since they're not mitigating on a network level but rather just work as a reverse proxy with a big network pipe, they can't actually prevent somebody from directly attacking your infrastructure. Real network-level DDoS mitigation (ie. what Cloudflare doesn't offer) doesn't have this problem.

(Also, DDoS attacks are not actually as common as a lot of people believe. Unless you either piss off the wrong set of people, or become big enough, you're not likely to ever actually need any DDoS mitigation beyond what your hosting provider can offer out of the box. And I'm saying all this as somebody who has quite a lot of experience in being on the receiving end of such attacks.)

@abarclay

This comment has been minimized.

Copy link

abarclay commented Jan 15, 2019

@joepie91 I am fighting the battle right now at work to allow wildcard certificates. I disagree that they are ANY less secure than using a bunch of single domain certificates. Your description above stating, "the thief can use it to impersonate the mail.google.com server and intercept people's e-mail traffic" is not accurate at all. In order to intercept people's e-mail traffic, you would need to also subvert google's DNS in order to direct traffic to you pirated server OR you would need to have access to the encrypted traffic by subverting one of their routers or switches (given the use of session keys, I'm not even sure you could do that unless you were party to the WHOLE transaction! Finally, I'd like to ask you to go to www.google.com in your browser and examine the certificate.... hint. It's a wildcard cert. Those of us with knowledge of technology need to be very careful not to pass around incomplete information as that leads to panic and it makes a lot of unnecessary work to undo the damage.

@jurschel

This comment has been minimized.

Copy link

jurschel commented Jan 17, 2019

I'll do you one better go inspect the https://api.google.com cert. Makes me wonder about the validity of your arguments?

@sarink

This comment has been minimized.

Copy link

sarink commented Jan 19, 2019

If your certificate is compromised, wildcard or not, you're in trouble. A wildcard cert probably exists in multiple locations and probably is being shared around, therefore it has a greater surface area (probably), and is (probably) less secure. But to simply state, "wildcard certs are less secure", is patently untrue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment