← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

HTTP Strict Transport Security (HSTS)

Security CWE-319 OWASP A5:2021 PHP 5.0+ Beginner
debt(d5/e3/b3/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list owasp-zap, ssllabs, and lighthouse — all specialist/external scanning tools. Missing or misconfigured HSTS headers won't be caught by a compiler or default linter; you need to run a dedicated security scanner or audit tool against a live HTTPS endpoint.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is essentially a one-liner header addition (Strict-Transport-Security: max-age=31536000; includeSubDomains), but correctly deploying it requires verifying all subdomains support HTTPS, ensuring the header only appears on HTTPS responses, and optionally submitting to the preload list — making it slightly more than a pure single-line patch but still well within one component.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is web contexts only, and the burden is mostly a configuration/header-emission concern. Once correctly configured at the server or middleware layer, the rest of the codebase is largely unaffected. There is some ongoing discipline required (subdomains, load-balancer TLS termination), but it doesn't reshape every future change.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field states that developers believe HSTS protects users on their first visit, but the Trust On First Use problem means the very first HTTP request is still unprotected. This directly contradicts the implied guarantee of the feature name ('strict transport security'), mirrors a misunderstanding common even among experienced developers, and requires understanding HSTS preloading to fully resolve — a non-obvious secondary mechanism.

About DEBT scoring →

Also Known As

HTTP Strict Transport Security Strict-Transport-Security header HTTPS enforcement

TL;DR

A response header that instructs browsers to always connect via HTTPS for a specified duration, preventing protocol downgrade attacks.

Explanation

HSTS (RFC 6797) is delivered via the Strict-Transport-Security header: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload. Once received, the browser refuses plain HTTP connections to that domain for the max-age duration — even if the user types http://. This eliminates SSL stripping and downgrade attacks at the browser level. The preload directive submits the domain to browser vendor hardcoded lists (hstspreload.org). In PHP, emit the header on all HTTPS responses: header('Strict-Transport-Security: max-age=31536000; includeSubDomains').

Common Misconception

HSTS protects users on their very first visit. The first visit still happens over HTTP before the HSTS header is received — the "Trust On First Use" problem. HSTS preloading solves this by shipping domains in browsers before any visit.

Why It Matters

HSTS forces browsers to use HTTPS even if a user types http://, preventing SSL-stripping attacks that silently downgrade the connection.

Common Mistakes

  • Setting a very short max-age (e.g. 60 seconds) that effectively disables the protection.
  • Not including includeSubDomains when subdomains are also served over HTTPS.
  • Setting HSTS on a response served over plain HTTP — browsers ignore it.
  • Sending HSTS from behind a load balancer that terminates TLS, ensuring the header only appears on HTTPS responses.

Code Examples

✗ Vulnerable
// Only setting HSTS on login page — leaves other pages vulnerable to stripping
✓ Fixed
header('Strict-Transport-Security: max-age=31536000; includeSubDomains'); // on ALL pages

Added 15 Mar 2026
Edited 22 Mar 2026
Views 75
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M
No pings yet today
No pings yesterday
Scrapy 17 Amazonbot 7 Perplexity 6 SEMrush 6 Ahrefs 5 PetalBot 5 Google 4 Unknown AI 3 Majestic 1 Meta AI 1 Twitter/X 1 Brave Search 1 Applebot 1
crawler 55 crawler_json 2 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Add Strict-Transport-Security: max-age=31536000; includeSubDomains to all HTTPS responses; submit to the HSTS preload list for maximum protection
📦 Applies To
PHP 5.0+ web
🔗 Prerequisites
🔍 Detection Hints
Missing HSTS header on HTTPS responses; max-age too short <1 year; no includeSubDomains; HTTP not redirecting to HTTPS
Auto-detectable: ✓ Yes owasp-zap ssllabs lighthouse
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: File
CWE-523 CWE-319


✓ schema.org compliant