HSTS
What is HSTS?
HTTP Strict Transport Security (HSTS) is a security mechanism that helps websites enforce secure HTTPS connections. HSTS prevents browsers from establishing insecure HTTP connections to a website, even if the user explicitly enters HTTP in the URL.
How HSTS Works
HSTS works through a special HTTP header sent by the server to the Web Browser. This header tells the browser that all future connections to this domain should only occur over HTTPS.
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
HSTS Directives in Detail
max-age
The max-age directive defines how long the browser should store the HSTS policy. The value is specified in seconds.
Recommended Values:
- Minimum: 1 year (31,536,000 seconds)
- Optimal: 2 years (63,072,000 seconds)
- Maximum: 2 years (browser limit)
includeSubDomains
This directive extends the HSTS policy to all Sub-domains of the current domain.
Example:
- Domain:
example.com - With
includeSubDomains: Applies towww.example.com,api.example.com,blog.example.com - Without
includeSubDomains: Applies only toexample.com
preload
The preload directive enables inclusion in the HSTS Preload List of browsers, ensuring security from the first visit.
SEO Benefits of HSTS
1. Security Ranking Signal
Google considers HTTPS as a ranking factor. HSTS further strengthens this signal, as it demonstrates a higher level of security.
2. Prevents Mixed Content
HSTS automatically prevents Mixed Content issues that can lead to SEO disadvantages.
3. Improved Core Web Vitals
By enforcing HTTPS usage, potential performance issues from HTTP redirects are eliminated.
4. Trustworthiness
Visitors and search engines trust websites with HSTS more, which positively impacts user experience and thus SEO.
HSTS Installation
1. Server Configuration
Apache (.htaccess):
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Nginx:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
IIS (web.config):
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; preload" />
</customHeaders>
</httpProtocol>
</system.webServer>
2. HSTS Preload List
Steps for Inclusion:
- Website must fully support HTTPS
- Implement HSTS header with
preloaddirective - Register at hstspreload.org
- Wait for browser updates (can take several months)
HSTS Testing and Validation
Browser Tools
- Chrome DevTools: Security tab shows HSTS status
- Firefox Developer Tools: Security tab with HSTS information
- Online Tools: SSL Labs SSL Test, HSTS Preload Checker
Test Commands
# Check HSTS header
curl -I https://example.com | grep -i strict-transport
# Check HSTS Preload status
curl -s https://hstspreload.org/api/v2/status?domain=example.com
Common HSTS Problems
1. Incorrect Implementation
Problem: HSTS header set on HTTP pages
Solution: Implement HSTS only on HTTPS pages
2. Too Short max-age
Problem: max-age=0 or very short values
Solution: At least 1 year (31,536,000 seconds)
3. Missing includeSubDomains
Problem: Subdomains not covered
Solution: Add includeSubDomains directive
4. Preload Without Preparation
Problem: Domain in Preload List without complete HTTPS coverage
Solution: First complete HTTPS implementation, then Preload
HSTS Surveillance
1. Header Monitoring
Regular verification that HSTS headers are being sent correctly.
2. Preload Status
Monitoring of Preload status in various browsers.
3. Mixed Content Detection
Automatic detection of Mixed Content issues.
Best Practices for HSTS
1. Gradual Implementation
- Phase 1: HSTS without
includeSubDomainsandpreload - Phase 2: Add
includeSubDomains - Phase 3: Add
preloaddirective - Phase 4: Register with Preload List
2. Backup Strategies
- HSTS Removal Plan: Preparation for emergencies
- Digital Certificate Management: Automatic certificate renewal
- Monitoring: Continuous monitoring of HTTPS availability
3. Documentation
- HSTS Policy: Internal documentation of HSTS configuration
- Rollback Plan: Procedure for HSTS deactivation
- Team Training: Knowledge transfer to all stakeholders
HSTS vs. Other Security Measures
HSTS and Different Website Types
E-Commerce Websites
Special Requirements:
- Highest security standards required
- Consider PCI-DSS compliance
- Check payment provider integration
Corporate Websites
Recommendations:
- HSTS for all subdomains
- Preload List registration
- Comprehensive documentation
Blog/Content Websites
Minimum Requirements:
- Basic HSTS implementation
- Regular monitoring
- Simple rollback strategy
Future of HSTS
HTTP/3 Integration
HSTS will remain relevant in HTTP/3 environments and continue to evolve.
Browser Evolution
New browser features will extend and improve HSTS functionality.
Automation
Increasing automation of HSTS implementation and monitoring.
Last Updated: October 21, 2025