What HTTPS Adds on Top of HTTP
HTTPS is HTTP carried inside a secure channel provided by TLS (Transport Layer Security). The goal is not to change how your application routes requests or formats responses, but to protect what is sent over the network. With plain HTTP, anyone who can observe or interfere with the network path (a compromised Wi‑Fi access point, a malicious router, an ISP-level attacker, or malware on a gateway) can read requests and responses, steal cookies or tokens, inject scripts into HTML, or redirect users to lookalike sites. HTTPS aims to prevent three main classes of problems:
- Confidentiality: keep the data private so observers cannot read it.
- Integrity: detect tampering so attackers cannot modify traffic without being noticed.
- Authentication: prove the server is the one the client intended to reach (e.g.,
example.com), not an impostor.
TLS provides these properties by establishing shared cryptographic keys between the client and server, then using those keys to encrypt and authenticate every byte of application data. Importantly, TLS is designed so that even if an attacker can capture all encrypted traffic, they still cannot decrypt it without the session keys.
Threat Model: What TLS Defends Against
It helps to be explicit about what TLS is and is not protecting you from.
- Passive eavesdropping: Someone captures packets and reads sensitive data (passwords, session cookies, personal info). TLS prevents this by encrypting application data.
- Active tampering (man-in-the-middle): Someone modifies traffic in transit, injects content, or changes responses. TLS prevents undetected modification by using integrity checks (AEAD ciphers) on every record.
- Impersonation: Someone pretends to be your site and presents a fake server. TLS prevents this by requiring the server to present a certificate that chains to a trusted Certificate Authority (CA) and matches the hostname.
- Replay and downgrade attempts: Attackers may try to force weaker cryptography or replay old messages. Modern TLS versions include protections against these.
TLS does not protect against a compromised endpoint (malware on the client, a hacked server), nor does it make your application logic secure (e.g., it won’t stop SQL injection). It also does not hide the fact that a connection to a particular IP exists; and depending on configuration, some metadata like the server name may be visible (SNI), though newer mechanisms like ECH aim to reduce that exposure.
TLS in Practice: Certificates, Identity, and Trust
When a browser connects to https://api.example.com, it expects the server to prove it is authorized to use that name. This proof is a digital certificate containing:
Continue in our app.
You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.
Or continue reading below...Download the app
- The subject identity (hostnames in the Subject Alternative Name extension, e.g.,
api.example.com). - The server’s public key.
- Validity period (not before / not after).
- Issuer information (which CA signed it).
- A signature from the issuer that binds the identity to the public key.
The browser validates the certificate by building a chain from the server certificate to an intermediate CA certificate and finally to a root CA certificate already trusted by the operating system or browser. The browser also checks that the requested hostname matches one of the SAN entries and that the certificate is not expired or revoked (revocation checking varies by client and environment).
Common Certificate Types You’ll Encounter
- Single-name: one hostname (e.g.,
www.example.com). - Wildcard: covers a subdomain level (e.g.,
*.example.comcoversapi.example.combut nota.b.example.com). - Multi-SAN: multiple explicit hostnames in one certificate.
From a security perspective, the main difference is operational: wildcard certificates are convenient but broaden the blast radius if the private key leaks, because more hostnames are affected.
How the TLS Handshake Establishes Keys
TLS starts with a handshake: a short negotiation where the client and server agree on protocol version and cryptographic parameters, authenticate the server, and derive shared session keys. After the handshake, application data is sent in encrypted TLS records.
High-Level Flow (TLS 1.3)
TLS 1.3 is the modern baseline. The exact message sequence can vary, but conceptually it looks like this:
- ClientHello: the client proposes TLS version, supported cipher suites, and sends a key share for an ephemeral key exchange (typically ECDHE). It may also include SNI (the hostname) and ALPN (to negotiate HTTP/2 or HTTP/3).
- ServerHello: the server selects parameters and returns its key share.
- Encrypted Extensions + Certificate + CertificateVerify: the server sends its certificate chain and proves possession of the private key by signing handshake data.
- Finished: both sides send a final integrity-protected message confirming the handshake transcript.
After this, both sides have the same symmetric keys and can encrypt/decrypt traffic. The key exchange is typically ephemeral, which provides forward secrecy: even if the server’s long-term private key is compromised later, previously captured sessions cannot be decrypted because each session used unique ephemeral keys.
Cipher Suites and What They Mean
In TLS 1.3, cipher suites are simpler: they mainly specify the symmetric encryption and hashing used after the handshake. Common choices include:
TLS_AES_128_GCM_SHA256TLS_AES_256_GCM_SHA384TLS_CHACHA20_POLY1305_SHA256
These are AEAD ciphers (Authenticated Encryption with Associated Data). AEAD provides confidentiality and integrity together: if any byte is modified in transit, decryption fails and the connection is terminated.
What “Preventing Tampering” Looks Like on the Wire
With TLS, data is split into records. Each record is encrypted and includes an authentication tag. If an attacker flips a bit in the ciphertext, the authentication tag no longer matches, and the recipient detects the tampering immediately. This is different from older “encrypt-then-hope” designs; modern TLS is built around authenticated encryption so integrity is not optional.
In practical terms, this prevents:
- Injecting malicious JavaScript into an HTML response.
- Changing a JSON API response (e.g., altering prices or account IDs).
- Modifying redirects to send users to phishing pages.
- Altering cookies or headers in transit.
It also prevents “silent corruption” caused by misbehaving middleboxes, because any modification breaks authentication.
Certificate Issuance and Renewal (Practical Step-by-Step)
Most teams obtain certificates via ACME (Automated Certificate Management Environment), commonly using Let’s Encrypt. The steps below describe the typical workflow; exact commands vary by tooling and hosting environment.
Step 1: Decide Where TLS Terminates
You need to choose which component presents the certificate and performs the handshake:
- At the edge load balancer / reverse proxy: common in production. The proxy handles TLS and forwards plain HTTP to internal services (or re-encrypts with mTLS).
- At each application server: simpler for small deployments but harder to manage at scale.
This decision affects where you install certificates and where you configure protocols (HTTP/2, TLS versions, ciphers).
Step 2: Choose a Validation Method
ACME validates that you control the domain before issuing a certificate. Common methods:
- HTTP-01 challenge: you serve a specific token at
http://yourdomain/.well-known/acme-challenge/.... This requires port 80 to be reachable publicly. - DNS-01 challenge: you create a TXT record under
_acme-challenge.yourdomain. This works even if you cannot expose port 80 and is useful for wildcard certificates.
Step 3: Request the Certificate
Using an ACME client (often integrated into your reverse proxy), you request a certificate for your hostname(s). The client will:
- Generate a private key (or use an existing one).
- Prove domain control via HTTP-01 or DNS-01.
- Receive the certificate chain.
Operational note: protect the private key. If it leaks, an attacker can impersonate your site until the certificate expires or is revoked.
Step 4: Install and Configure the Server
At minimum you configure:
- The certificate and private key paths.
- Supported TLS versions (prefer TLS 1.3 and TLS 1.2; disable older versions).
- Cipher suites (use modern defaults; avoid legacy ciphers).
- ALPN to enable HTTP/2 where applicable.
Also ensure the server sends the full certificate chain (server cert plus intermediate). Missing intermediates are a common cause of “certificate not trusted” errors on some clients.
Step 5: Automate Renewal
Certificates from many public CAs are short-lived (often 90 days). Automation is expected. Set up a scheduled renewal job and a safe reload mechanism for your proxy/server so new certificates take effect without downtime.
Practical checklist for renewal automation:
- Renew at least daily (the client will only renew when within the renewal window).
- Reload the server after renewal (graceful reload preferred).
- Alert on renewal failures (expiring certs cause outages).
Hardening HTTPS: Configuration Choices That Matter
Enforce HTTPS with Redirects and HSTS
Redirecting http:// to https:// is a start, but it still allows an attacker to intercept the very first HTTP request and prevent the redirect (SSL stripping). HTTP Strict Transport Security (HSTS) instructs browsers to always use HTTPS for your domain for a period of time.
Typical approach:
- Serve a 301/308 redirect from HTTP to HTTPS.
- On HTTPS responses, add an HSTS header such as
Strict-Transport-Security: max-age=31536000; includeSubDomains.
Be careful with includeSubDomains: only enable it if every subdomain is ready for HTTPS. HSTS can effectively “brick” HTTP access in browsers until the max-age expires.
TLS Versions
Prefer:
- TLS 1.3: best security and performance.
- TLS 1.2: acceptable for compatibility if configured with modern ciphers.
Avoid enabling TLS 1.0/1.1 due to known weaknesses and ecosystem deprecation.
OCSP Stapling (Where Supported)
Revocation checking is complicated on the public web. OCSP stapling allows the server to periodically fetch a signed revocation status from the CA and “staple” it to the handshake, improving privacy and performance for clients that use it.
Session Resumption
Full handshakes cost CPU and add latency. TLS supports resumption so repeat connections can skip parts of the handshake:
- Session tickets: the server provides an encrypted ticket the client can present later.
- Session IDs: older mechanism, less common at scale.
In distributed environments, ticket key rotation and sharing across instances matters. If you rotate too aggressively, resumption rates drop; if you never rotate, you increase risk if a ticket key leaks.
Debugging and Verifying HTTPS (Practical Step-by-Step)
Step 1: Inspect the Certificate in a Browser
In most browsers you can click the lock icon to view:
- Certificate subject and SANs (does it match the hostname?).
- Issuer (which CA signed it?).
- Validity dates (is it expired or not yet valid?).
If users report warnings, first confirm they are visiting the expected hostname and that the certificate matches it exactly.
Step 2: Use OpenSSL to Check the Handshake
From a terminal, you can see what the server presents and which protocol/cipher is negotiated:
openssl s_client -connect example.com:443 -servername example.comLook for:
Protocol: ideally TLSv1.3 or TLSv1.2.Cipher: a modern AEAD cipher.Verify return code: 0 (ok): indicates the chain validated (from your machine’s trust store).
To print the certificate chain:
openssl s_client -connect example.com:443 -servername example.com -showcertsStep 3: Confirm the Full Chain Is Served
A common misconfiguration is serving only the leaf certificate without intermediates. Some clients can fetch intermediates, others cannot. If you see validation failures on certain devices, ensure your server is configured with the “fullchain” bundle (leaf + intermediate).
Step 4: Validate Hostname Coverage
If you serve multiple hostnames, confirm the certificate includes all of them in SANs. A certificate for example.com does not automatically cover www.example.com unless explicitly included or covered by a wildcard.
TLS Termination and Internal Traffic
Many architectures terminate TLS at a reverse proxy or load balancer, then forward traffic to internal services. This is fine, but it changes your trust boundary: traffic between the proxy and services may be unencrypted and could be observed inside your network if an attacker gains internal access.
Common patterns:
- Edge TLS termination + internal HTTP: simplest; rely on network controls (private subnets, firewall rules).
- Edge TLS termination + internal TLS: re-encrypt to backends; protects against internal sniffing and some lateral movement.
- mTLS (mutual TLS): both sides authenticate with certificates; useful for service-to-service authentication and zero-trust approaches.
If you terminate TLS at a proxy, ensure your application still knows the original scheme and client information via trusted headers (for example, X-Forwarded-Proto). Only trust these headers if they are set by your proxy and stripped from incoming client requests.
Mixed Content and Why HTTPS Can Still Leak Security
Even if your main HTML is served over HTTPS, loading subresources over HTTP (scripts, images, CSS) is called mixed content. Active mixed content (scripts) can fully compromise the page because an attacker can modify the script and run code in the user’s browser. Modern browsers block many forms of mixed content, but you should treat it as a deployment bug.
Practical steps to avoid mixed content:
- Use relative URLs or explicit
https://URLs for assets. - Ensure third-party resources support HTTPS.
- Use Content Security Policy (CSP) to restrict what can be loaded (CSP is an application-layer control, but it complements TLS by limiting damage if something goes wrong).
Performance Considerations: TLS Without the Myths
TLS adds overhead, but in modern stacks it is usually not the dominant cost. Key points:
- Handshake latency: TLS 1.3 reduces round trips compared to older versions. Session resumption further reduces cost for repeat connections.
- CPU cost: symmetric encryption is fast; the expensive part is the public-key operations during handshakes. Hardware acceleration and optimized libraries make this manageable for most workloads.
- HTTP/2 and HTTP/3: in browsers, HTTP/2 is typically used over TLS, and HTTP/3 uses QUIC with TLS 1.3 built in. Enabling modern protocols can improve performance more than the TLS cost you pay.
Practical tuning levers:
- Enable TLS 1.3.
- Enable session resumption (tickets) and ensure ticket keys are managed correctly across instances.
- Use modern cipher suites (server defaults are usually fine; avoid manual “tuning” unless you know why).
Common HTTPS/TLS Failure Modes and How to Fix Them
Certificate Name Mismatch
Symptom: Browser error indicating the certificate is not valid for the hostname.
Fix: Issue a certificate that includes the exact hostname in SANs (or use a wildcard appropriately). Confirm the server is presenting the correct certificate for that SNI name (multi-site servers can present the wrong cert if misconfigured).
Expired Certificate
Symptom: Browser blocks access; monitoring shows cert expiration.
Fix: Restore renewal automation, ensure the ACME challenge can complete, and reload the server after renewal. Add alerts well before expiration.
Incomplete Chain
Symptom: Works on some devices but fails on others.
Fix: Configure the server to serve the full chain bundle (leaf + intermediate). Verify with openssl s_client -showcerts.
Clock Skew
Symptom: “Not yet valid” or “expired” errors on specific clients.
Fix: Ensure client and server clocks are correct (NTP). Certificates are time-bound; incorrect clocks break validation.
TLS Interception by Corporate Proxies
Symptom: Users in certain networks see a different issuer (a corporate CA) and the connection is re-signed.
Fix: This is often intentional in managed environments. From a service operator perspective, ensure your app remains secure even if a client’s environment intercepts TLS (e.g., do not rely on TLS alone for authorization; use proper authentication and token handling). For internal apps, coordinate trust stores and policies.
Hands-On: Minimal Server-Side TLS Configuration Example
The exact configuration depends on your server, but the concepts are consistent: listen on 443, point to certificate and key, enable modern TLS, and redirect HTTP to HTTPS.
# Pseudocode-style configuration (conceptual, not tied to a specific server) server { listen 443 ssl http2; server_name example.com; ssl_certificate /etc/ssl/example/fullchain.pem; ssl_certificate_key /etc/ssl/example/privkey.pem; ssl_protocols TLSv1.3 TLSv1.2; add_header Strict-Transport-Security "max-age=31536000" always; location / { proxy_pass http://app_upstream; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-For $remote_addr; } } server { listen 80; server_name example.com; return 308 https://$host$request_uri; }When you adapt this to your environment, focus on the intent: correct certificate chain, modern protocols, HSTS only after you confirm HTTPS works everywhere you need it, and safe forwarding headers if you terminate TLS at a proxy.