Wildcard Certificates and HTTPS: Validation and Trusted Proxies
Wildcard Certificates and HTTPS: Validation and Trusted Proxies
Search
Ask the AI

Wildcard Certificates and HTTPS: Validation and Trusted Proxies

A subdomain was reported to have no SSL certificate. I checked and found that a wildcard certificate covered it, with two months left to run.

The investigation also found that the subdomain’s login page was reachable over plain HTTP, with a password field and no redirect.

Having a certificate and enforcing HTTPS are two different things. This is about checking them separately, and about two things that sent me the wrong way while doing it.

Why a wildcard certificate looks absent

In certbot certificates or a domain control panel, a wildcard certificate does not appear once per subdomain. Its single record uses *.example.com in the SAN list to show the coverage.

For example, eight subdomains covered by one certificate still produce one record. Counting records can make the other seven appear unconfigured.

Fetch the certificate with SNI and inspect SAN and dates. The command below inspects fields; full validation also checks trust and hostname. For example, use -verify_hostname sub.example.com -verify_return_error with a trusted CA configuration in s_client.

echo | openssl s_client -servername sub.example.com \
  -connect sub.example.com:443 2>/dev/null \
  | openssl x509 -noout -subject -dates -ext subjectAltName

-servername is the part that matters. Modern servers host many sites on one IP and choose which certificate to send based on the SNI extension in the handshake. Omit it and you may get the default site’s certificate, then draw a wrong conclusion from it.

What I got back was DNS:*.example.com, DNS:example.com — a wildcard plus the bare domain, covering every first-level subdomain. The one that supposedly had no certificate had been in there all along.

A TLS service-identity wildcard matches one leftmost label. *.example.com does not cover a.b.example.com; an exact SAN or *.b.example.com can. A multi-label wildcard is not the solution.

Compare diagnostic connection paths

My first run of that command reported handshake failure for all four hostnames.

One of those sites had worked throughout the evening, so I first checked the environment in which the diagnostic command ran.

The record reports curl connecting while s_client failed. Compare proxy use, routes, trust stores and execution environments. s_client uses an ordinary TCP socket; the difference alone does not establish a raw-socket permission restriction.

When every target returns the same diagnostic failure, also check the tool and its environment. The DNS investigation later showed a similar problem.

DNS and service checks in a fake-IP environment

With certificates cleared, I wanted to check every subdomain. The plan was to probe which ones existed, then examine each.

So I resolved a list of common prefixes: www, admin, mail, api, cdn, test, git, and so on. Every single one resolved. Including several I had invented on the spot.

The addresses came back in 198.18.0.x. That range is reserved for network device benchmarking and has no business appearing in public DNS answers.

A fake-IP proxy can synthesise reserved addresses for queries selected by its configuration, then route by hostname. These answers cannot establish public DNS existence. Compare a trusted DNS path with the actual service inventory.

HTTPS responses supplement discovery, but real services can return 403,404 or 503 as well as 200/302. A default virtual host may return 200 for an unknown name. Curl’s 000 means no HTTP status was obtained; timeouts and TLS errors can cause it too.

The actual problem

Checking the four sites individually revealed another issue with protocol redirects.

Two of them do not redirect http:// to https://:

http://www...      301 -> https://www...     correct
http://admin...    301 -> https://admin...   correct
http://pivot...    200                       serves content directly
http://prairie...  302 -> http://prairie/... redirects, still http

The one returning 200 is webmail. Fetching the body:

curl -s http://pivot.example.com/ | grep -c 'type="password"'
# 1

An HTTP login page can be modified in transit. Establishing plaintext password submission also requires inspecting the form action, scripts and browser behaviour. Even an HTTPS action cannot prevent an attacker replacing the HTTP page with credential-stealing content.

The other case is subtler: it does redirect, but to another http address, landing on a two-factor page with two credential fields. The presence of a redirect makes it easy to assume the configuration is right.

How both were missed

Because the forced redirect on this setup is done by the origin’s nginx, and the rule lives only in the main site’s server block. Webmail and the file service were added later as separate services with their own configs, and nobody thought to add it there.

Such omissions can accumulate as services are added without producing an error. The services remain usable, but their redirect settings need to be compared.

Investigating a single broken service can narrow the checks to that service. A separate pass over all public hostnames helps find the omissions.

Fixing it

An edge HTTPS redirect applies to traffic passing through that proxy. DNS-only names and direct origin access need separate configuration. Check certificates, origin protocol and opposing redirects for loops.

Locate TLS termination before choosing a protocol signal. $scheme describes the connection to this Nginx. Trust X-Forwarded-Proto only from a known proxy that overwrites untrusted input. The retained rule also assumes a validated Host.

if ($http_x_forwarded_proto = "http") {
    return 301 https://$host$request_uri;
}

Use $scheme when Nginx directly terminates the visitor connection. Behind a proxy, use trusted forwarding information or a dedicated HTTP listener, and test complete HTTP and HTTPS redirect chains.

First HTTP requests and HSTS

When no HSTS policy is known and the browser actually sends HTTP first, that request precedes the redirect. Browsers may instead try HTTPS, and known HSTS or preload can upgrade the request before transmission. Visits do not universally begin in plaintext.

What closes that gap is HSTS — a response header telling the browser “from now on, always use HTTPS for this domain; do not try HTTP first”:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

The browser remembers this for max-age seconds. During that window, even if the user explicitly types http://, the browser rewrites it to HTTPS before issuing the request, so no plaintext request is ever produced.

Check three points before deploying HSTS:

  • Establish HSTS through a valid HTTPS response; a TLS-terminating edge can add it. Port number alone does not determine acceptance.
  • includeSubDomains affects descendant names; verify HTTPS availability and plan for remembered client policies.
  • Preloading requires submission and list acceptance; the header token alone does not add it. Removal can be requested, with browser-update delays.

The safe rollout is to start with a short max-age=300, watch for a few days to confirm no subdomain is cut off, then raise it toward a year. This parameter is “how long the user’s browser remembers,” not “how long the server keeps it” — set it wrong and you cannot unilaterally undo it.

Mixed content: the page is HTTPS, its resources are not

HTTP subresources on an HTTPS page are mixed content. Modern browsers upgrade some image, audio and video requests and block other insecure resources; failed upgrades can also prevent loading. Inspect the console and network trace.

This is especially common on systems like WordPress where content lives in a database: image URLs inserted while the site was still on HTTP remain in article bodies as absolute URLs, entirely untouched by any nginx change.

Find them through the browser console’s Mixed Content warnings, or by grepping the served content directly:

curl -s https://example.com/ | grep -o 'http://[^"'"'"']*' | sort -u | head

Inspect HTTP subresources from every origin, including external images, scripts and stylesheets. An ordinary top-level hyperlink is generally navigation, rather than an automatically loaded subresource of the current page.

Verify content, cache headers and the full redirect chain. A random query bypasses caching only if cache-key rules distinguish it; use a defined purge mechanism when needed.

A minimal checklist

Check these four items separately for each public hostname:

Does the certificate cover this hostname. Fetch it with -servername and read the SAN list, rather than counting rows in a panel.

Check HTTP-to-HTTPS behaviour for GET, form submissions and the complete Location chain. Missing redirects, HTTP actions and mixed requests can each expose credentials. HEAD is only one check.

Is the redirect target actually https. I hit a 302 pointing at another http URL. Checking only “is there a redirect” misses it.

Return HSTS through valid HTTPS and verify max-age and subdomain scope. It protects clients that know the policy; preload can cover first visits. Deploy it together with HTTP redirect checks.

Include the second item explicitly in acceptance checks, since a working service and a valid certificate can leave a missing redirect unnoticed.

Leave a Reply

Scroll down