What does HSTS stand for and what is its main purpose?
HSTS stands for HTTP Strict Transport Security. Its main purpose is to tell browsers to only connect to a website using HTTPS, improving security by preventing insecure HTTP connections.
Click to reveal answer
beginner
How do you enable HSTS in an nginx server configuration?
You add the header Strict-Transport-Security in the server block for HTTPS, for example:
What does the max-age directive in the HSTS header control?
The max-age directive sets how long (in seconds) the browser should remember to only use HTTPS for the site. For example, max-age=31536000 means 1 year.
Click to reveal answer
intermediate
What is the effect of adding includeSubDomains in the HSTS header?
Adding includeSubDomains tells browsers to apply the HSTS policy to all subdomains of the site, not just the main domain.
Click to reveal answer
intermediate
Why should the HSTS header be sent only over HTTPS connections?
Because HSTS tells browsers to only use HTTPS, sending it over HTTP would be insecure and could allow attackers to intercept or strip the header.
Click to reveal answer
What is the correct nginx directive to add the HSTS header?
The correct nginx directive is add_header with the full header name Strict-Transport-Security and the value including max-age and optionally includeSubDomains. The always flag ensures it is added on all responses.
What does the max-age value in the HSTS header represent?
AThe number of subdomains to include
BThe number of seconds the browser should enforce HTTPS only
CThe number of requests allowed over HTTP
DThe timeout for HTTPS connections
✗ Incorrect
max-age sets the time in seconds that the browser remembers to only use HTTPS for the site.
Why is it important to include includeSubDomains in the HSTS header?
ATo apply HSTS policy to all subdomains as well
BTo exclude subdomains from HSTS
CTo enable HTTP connections on subdomains
DTo disable HTTPS on subdomains
✗ Incorrect
Including includeSubDomains tells browsers to enforce HTTPS on all subdomains, improving overall security.
What happens if you send the HSTS header over an HTTP connection?
AIt can be intercepted or stripped by attackers
BIt forces the browser to use HTTPS immediately
CIt disables HTTPS for the site
DIt has no effect
✗ Incorrect
Sending HSTS over HTTP is insecure because attackers can intercept or remove the header, defeating its purpose.
Which of these is a valid HSTS header value?
A"max-age=31536000; excludeSubDomains"
B"max-age=one year; includeSubDomains"
C"max-age=31536000; includeSubDomains"
D"max-age=0; includeSubDomains"
✗ Incorrect
The value must use seconds for max-age and can include includeSubDomains. "one year" is invalid, and excludeSubDomains is not a valid directive.
Explain how to configure the HSTS header in nginx and why it is important.
Think about telling browsers to always use HTTPS and how nginx sends headers.
You got /5 concepts.
Describe the risks of not using HSTS on a website that supports HTTPS.
Consider what happens if browsers are allowed to connect over HTTP.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the Strict-Transport-Security (HSTS) header in nginx?
easy
A. To force browsers to use HTTPS instead of HTTP for the site
B. To redirect HTTP requests to a different domain
C. To enable caching of static files in the browser
D. To compress responses sent to the client
Solution
Step 1: Understand HSTS header purpose
The HSTS header tells browsers to only use HTTPS for the site, improving security.
Step 2: Compare options with HSTS function
Only To force browsers to use HTTPS instead of HTTP for the site matches this purpose; others describe unrelated features.
Final Answer:
To force browsers to use HTTPS instead of HTTP for the site -> Option A
Quick Check:
HSTS = Force HTTPS [OK]
Hint: HSTS means browsers must use HTTPS always [OK]
Common Mistakes:
Confusing HSTS with redirects
Thinking HSTS controls caching
Assuming HSTS compresses data
2. Which of the following is the correct nginx syntax to add an HSTS header that lasts for 1 year and applies to all subdomains?
easy
A. add_header Strict-Transport-Security max-age=31536000 includeSubDomains always;
B. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
C. add_header Strict-Transport-Security "max-age=31536000 includeSubDomains";
D. add_header Strict-Transport-Security max-age=31536000; includeSubDomains always;
Solution
Step 1: Check correct syntax for add_header
The header value must be a quoted string with directives separated by semicolons, and 'always;' ensures it is added on all responses.
Step 2: Validate option formatting
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; correctly quotes the value and uses semicolon between directives with 'always;'. Others miss quotes or semicolons or misplace 'always'.
Final Answer:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; -> Option B
B. The 'always' directive must be inside the quotes
C. max-age value is too large and rejected by nginx
D. The header value is missing quotes, causing syntax error
Solution
Step 1: Check syntax for add_header directive
The header value must be enclosed in quotes. Missing quotes cause nginx to ignore the header.
Step 2: Validate other parts
'always' must be outside quotes, max-age=31536000 is valid, includeSubDomains is valid directive.
Final Answer:
The header value is missing quotes, causing syntax error -> Option D
Quick Check:
Quotes missing = header not sent [OK]
Hint: Always quote header values in add_header [OK]
Common Mistakes:
Placing 'always' inside quotes
Not quoting header value
Misunderstanding valid directives
5. You want to preload your site in browsers' HSTS preload list. Which nginx header configuration is correct to achieve this for 6 months including subdomains?
hard
A. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
B. add_header Strict-Transport-Security "max-age=15768000; preload" always;
C. add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
D. add_header Strict-Transport-Security "max-age=15768000; includeSubDomains" always;
Solution
Step 1: Calculate max-age for 6 months
6 months ≈ 15768000 seconds (6 * 30 * 24 * 3600).
Step 2: Include required directives for preload
Preload requires max-age, includeSubDomains, and preload directive all present.
Step 3: Verify syntax correctness
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always; correctly quotes the value, uses semicolons, includes all directives, and uses 'always;'.
Final Answer:
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always; -> Option C