HTTP Strict Transport Security (HSTS) is a powerful security policy that forces browsers to communicate with your website exclusively over HTTPS. When you add the includeSubDomains directive, this protection extends to every subdomain under your apex domain. While this comprehensive approach offers excellent security coverage, it can also introduce challenges if not implemented thoughtfully.
This guide explores when to deploy HSTS with includeSubDomains, how to sidestep common pitfalls like mixed-content breaks and preload complications, and strategies for safe rollback when you need to adjust your configuration.
Understanding HSTS and the includeSubDomains Directive
HSTS works by sending a special header from your server to the browser:
Strict-Transport-Security: max-age=31536000; includeSubDomains
This header tells the browser to automatically upgrade all HTTP requests to HTTPS for the specified duration. The includeSubDomains parameter extends this requirement to every subdomain, whether it's blog.example.com, api.example.com, or any other subdomain you create.
Why Consider includeSubDomains?
The primary advantage is comprehensive security coverage. Once set, you won't need to worry about individual subdomains being accessed over insecure HTTP connections. This is particularly valuable for organizations with numerous subdomains or development teams that frequently spin up new environments.
However, this broad coverage means every single subdomain must support HTTPS properly, or users will encounter connection errors.
Before You Deploy: A Pre-Flight Checklist
The most common HSTS mistakes happen because teams overlook a subdomain that isn't HTTPS-ready. Before enabling includeSubDomains, conduct a thorough audit:
1. Inventory All Active Subdomains
Start by listing every subdomain currently in use. This includes production sites, staging environments, internal tools, and any third-party services using your subdomains. Many organizations discover forgotten subdomains during this process.
Check your DNS records thoroughly. If you manage your domains through a registrar like NameSilo, review all A, AAAA, and CNAME records to identify active subdomains. 2. Verify HTTPS Coverage
Each subdomain must have a valid SSL certificate and be configured to serve traffic over HTTPS. Self-signed certificates won't work for public-facing sites, and expired certificates will cause browser warnings.
When provisioning certificates, you have several options. Wildcard certificates cover all first-level subdomains (*.example.com), while multi-domain certificates can cover specific subdomains. Certificate providers, including those offering SSL certificates, typically support both approaches. 3. Test for Mixed Content
Mixed content occurs when an HTTPS page loads resources like images, scripts, or stylesheets over HTTP. Browsers block or warn about this, breaking page functionality.
Use browser developer tools to audit each subdomain. The console will flag mixed content warnings. Pay special attention to:
- Third-party scripts and tracking pixels
- Content delivery networks (CDNs) that might still use HTTP URLs
- Hardcoded HTTP links in templates or databases
- User-generated content that might contain HTTP references
4. Review Email Services
If you use subdomains for email services, such as mail.example.com or webmail.example.com, confirm these interfaces are HTTPS-ready. Many organizations maintain separate email hosting that may require coordination with providers. 5. Check Development and Staging Environments
Development and staging subdomains often get overlooked because they're not customer-facing. However, once HSTS with includeSubDomains is active, developers will be unable to access these environments over HTTP. Ensure all development infrastructure supports HTTPS, or consider using a separate domain entirely for non-production work.
Safe Deployment Strategy
Rather than immediately deploying HSTS with includeSubDomains at maximum settings, use a gradual rollout approach:
Phase 1: Start Without includeSubDomains
Begin by implementing HSTS on your main domain only, without the includeSubDomains directive:
Strict-Transport-Security: max-age=300
Use a short max-age value (300 seconds or 5 minutes) initially. This allows the policy to expire quickly if you discover issues.
Phase 2: Gradually Increase max-age
After confirming everything works correctly, incrementally increase the max-age value:
Monitor your logs and error tracking systems at each step for any increase in connection failures or certificate errors.
Phase 3: Add includeSubDomains
Once you're confident about your apex domain, add the includeSubDomains directive with a short max-age:
Strict-Transport-Security: max-age=300; includeSubDomains
Again, start conservatively. This gives you an escape hatch if an overlooked subdomain causes problems.
Phase 4: Increase Duration
After thoroughly testing with includeSubDomains enabled, gradually increase the max-age value using the same progression as before.
Common Pitfalls and How to Avoid Them
The Forgotten Subdomain Trap
The most frequent issue occurs when a rarely-used subdomain lacks HTTPS support. Users who previously accessed it over HTTP will suddenly encounter connection errors.
Solution: Maintain a comprehensive inventory of all subdomains and their purposes. Set up monitoring alerts when new DNS records are created, ensuring they go through an HTTPS readiness check before being activated.
The Third-Party Service Problem
Some organizations use subdomains that point to third-party services. For example, support.example.com might CNAME to a helpdesk provider's infrastructure. If that provider doesn't support HTTPS or uses a certificate that doesn't cover your subdomain, users will be unable to access the service.
Solution: Before implementing includeSubDomains, verify that all third-party services support HTTPS with proper certificates. If they don't, you may need to use a different domain structure or work with the vendor to enable HTTPS support.
The Development Environment Lockout
After enabling HSTS with includeSubDomains, developers often find themselves locked out of local development environments or staging servers that were previously HTTP-only.
Solution: Use separate domains for development work, or ensure all development infrastructure supports HTTPS. Tools like mkcert can generate locally-trusted certificates for development purposes.
The Mixed Content Cascade
Even one HTTP resource can break page functionality once HSTS is enforced. The challenge is that mixed content issues might exist on pages that aren't frequently visited, only surfacing after deployment.
Solution: Use automated scanning tools to crawl your entire site and check for mixed content. Content Security Policy (CSP) reporting can also help identify mixed content issues in production.
Understanding HSTS Preload
The HSTS preload list is a catalog of domains hardcoded into browsers that should only be accessed over HTTPS. Submitting your domain to this list offers the strongest protection, but it comes with significant commitments:
- Your domain must serve HSTS with includeSubDomains and a max-age of at least one year
- You must include the preload directive in your header
- The policy applies permanently across all browsers that use the preload list
- Removal from the list is slow and doesn't affect browsers immediately
Should You Preload?
Preloading makes sense for domains that are fully committed to HTTPS and unlikely to need HTTP access for any subdomain. However, the difficulty of reversal makes it inappropriate for domains that might need flexibility.
- All current and future subdomains will definitely support HTTPS
- You've been running HSTS with includeSubDomains successfully for several months
- Your organization has the infrastructure to maintain HTTPS across all services
- You're still testing or learning about HSTS
- You frequently create temporary subdomains for various purposes
- You rely on third-party services that might not support HTTPS
- You anticipate any need for HTTP access in the future
Safe Rollback Strategies
Despite careful planning, you might need to remove or reduce HSTS protection. The browser-caching nature of HSTS makes this challenging but not impossible.
Emergency Rollback
If you need immediate relief from HSTS, set the max-age to 0:
Strict-Transport-Security: max-age=0
This tells browsers to immediately stop enforcing HSTS. However, users must visit your site and receive this header for the change to take effect. Users who don't visit during the rollback window will continue experiencing the old policy until it expires.
Gradual Reduction
For a less drastic approach, progressively reduce the max-age value over time. This allows you to maintain some security while addressing specific subdomain issues.
You can also remove just the includeSubDomains directive while keeping HSTS active on your apex domain:
Strict-Transport-Security: max-age=31536000
Dealing with Preload List Removal
If your domain is on the preload list and you need to remove it, submit a removal request through the HSTS preload list website. However, understand that:
- The removal process takes time
- Browsers only update their preload lists with new releases
- Users won't see the change until they update their browsers
- The process can take months to complete fully
This is why preloading should only be considered after extensive testing and organizational commitment.
Monitoring and Maintenance
After deploying HSTS with includeSubDomains, establish ongoing monitoring:
Certificate Expiration Tracking
Set up alerts well before certificates expire. A certificate expiring on a subdomain covered by HSTS will lock users out until you renew it. Many hosting providers offer automated certificate renewal, which helps prevent this situation. DNS Change Monitoring
Implement processes to review new subdomains before they go live. Any new subdomain must be HTTPS-ready before being created in DNS.
Error Rate Monitoring
Watch for increases in SSL/TLS errors in your logs. Spikes often indicate certificate problems or misconfigurations affecting HSTS-protected subdomains.
Regular Security Audits
Periodically audit your entire domain structure to verify all subdomains maintain proper HTTPS configuration and valid certificates.
Best Practices for Long-Term Success
- Document Your HSTS Configuration: Maintain clear documentation of which domains and subdomains have HSTS enabled, with what parameters, and when changes were made.
- Establish Clear Processes: Create procedures for provisioning new subdomains that include HTTPS verification as a required step.
- Train Your Team: Ensure everyone who works with your infrastructure understands HSTS and its implications for subdomains.
- Plan for Certificate Management: Implement automated certificate renewal and monitoring to prevent expiration-related outages.
- Use Staging for Testing: Always test HSTS changes in a staging environment that mirrors production before applying them to live sites.
Conclusion
HSTS with includeSubDomains provides comprehensive security for your entire domain structure, forcing all traffic to encrypted connections. However, this power comes with responsibility. The directive affects every subdomain under your domain, and reversing the policy takes time due to browser caching.
Success requires thorough preparation: audit all subdomains, ensure universal HTTPS support, eliminate mixed content, and deploy gradually with short max-age values initially. Avoid the preload list until you've run HSTS with includeSubDomains successfully for an extended period and are certain about permanent commitment.
By following a measured approach and maintaining vigilant monitoring, you can implement includeSubDomains safely while avoiding the common pitfalls that have trapped less careful deployers. The result is a more secure web presence that protects your users across your entire domain structure.