Bird
Raised Fist0
Nginxdevops~20 mins

HSTS header in Nginx - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
HSTS Header Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the effect of this nginx HSTS header configuration?
Given this nginx configuration snippet, what will be the exact HTTP response header sent to clients?
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
Nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
AStrict-Transport-Security: max-age=0
BStrict-Transport-Security: max-age=31536000
CStrict-Transport-Security: max-age=31536000; includeSubDomains
DStrict-Transport-Security: max-age=31536000; preload
Attempts:
2 left
💡 Hint
Look carefully at the exact string inside the quotes in the add_header directive.
❓ Configuration
intermediate
2:00remaining
Which nginx config disables HSTS completely?
You want to disable HSTS on your nginx server. Which configuration line will remove the Strict-Transport-Security header from responses?
Aadd_header Strict-Transport-Security "max-age=0" always;
Badd_header Strict-Transport-Security "" always;
Cadd_header Strict-Transport-Security "max-age=31536000" always;
Dremove_header Strict-Transport-Security;
Attempts:
2 left
💡 Hint
Setting max-age to zero tells browsers to stop enforcing HSTS.
❓ Troubleshoot
advanced
2:00remaining
Why is HSTS header missing despite nginx config?
You configured nginx with:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

But the header is missing in HTTP responses. What is the most likely cause?
AThe server firewall blocks the Strict-Transport-Security header.
BThe add_header directive syntax is incorrect and causes nginx to ignore it.
CThe browser is caching old responses without the header.
DThe site is accessed over HTTP, not HTTPS, so HSTS header is not sent.
Attempts:
2 left
💡 Hint
HSTS only applies to secure HTTPS connections.
✅ Best Practice
advanced
2:00remaining
What is the recommended minimum max-age value for HSTS in production?
For strong security, what is the recommended minimum max-age value (in seconds) to set in the Strict-Transport-Security header?
A86400 (1 day)
B31536000 (1 year)
C2592000 (30 days)
D0 (disable HSTS)
Attempts:
2 left
💡 Hint
Longer max-age values enforce HSTS for longer periods.
🧠 Conceptual
expert
2:00remaining
What risk does missing 'includeSubDomains' in HSTS header pose?
If your nginx HSTS header is:
Strict-Transport-Security: max-age=31536000

but does NOT include 'includeSubDomains', what is the main security risk?
ASubdomains can still be accessed over HTTP, allowing man-in-the-middle attacks.
BBrowsers will ignore the HSTS header completely.
CThe max-age value will be treated as zero by browsers.
DThe server will reject HTTPS connections on subdomains.
Attempts:
2 left
💡 Hint
Consider how HSTS applies to subdomains when 'includeSubDomains' is missing.

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

  1. Step 1: Understand HSTS header purpose

    The HSTS header tells browsers to only use HTTPS for the site, improving security.
  2. 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.
  3. Final Answer:

    To force browsers to use HTTPS instead of HTTP for the site -> Option A
  4. 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

  1. 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.
  2. 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'.
  3. Final Answer:

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; -> Option B
  4. Quick Check:

    Quotes + semicolon + always = add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; [OK]
Hint: Use quotes and semicolons inside add_header value [OK]
Common Mistakes:
  • Missing quotes around header value
  • Forgetting semicolon between directives
  • Placing 'always' inside quotes
3. Given this nginx config snippet:
add_header Strict-Transport-Security "max-age=86400; includeSubDomains" always;

What is the effect on browsers visiting the site?
medium
A. Browsers will enforce HTTPS for 1 day on the site and all subdomains
B. Browsers will enforce HTTPS for 1 year on the site only
C. Browsers will ignore the header because max-age is too low
D. Browsers will enforce HTTPS for 1 day on the site only

Solution

  1. Step 1: Interpret max-age and includeSubDomains

    max-age=86400 means 86400 seconds = 1 day. includeSubDomains applies to all subdomains.
  2. Step 2: Understand browser behavior

    Browsers will enforce HTTPS for 1 day on the site and all its subdomains as per header.
  3. Final Answer:

    Browsers will enforce HTTPS for 1 day on the site and all subdomains -> Option A
  4. Quick Check:

    86400 seconds = 1 day + includeSubDomains = Browsers will enforce HTTPS for 1 day on the site and all subdomains [OK]
Hint: max-age in seconds; 86400 = 1 day [OK]
Common Mistakes:
  • Confusing seconds with days
  • Ignoring includeSubDomains effect
  • Assuming max-age too low disables HSTS
4. You added this line in nginx:
add_header Strict-Transport-Security max-age=31536000 includeSubDomains always;

Why is the HSTS header not sent to clients?
medium
A. includeSubDomains is not a valid directive
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

  1. Step 1: Check syntax for add_header directive

    The header value must be enclosed in quotes. Missing quotes cause nginx to ignore the header.
  2. Step 2: Validate other parts

    'always' must be outside quotes, max-age=31536000 is valid, includeSubDomains is valid directive.
  3. Final Answer:

    The header value is missing quotes, causing syntax error -> Option D
  4. 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

  1. Step 1: Calculate max-age for 6 months

    6 months ≈ 15768000 seconds (6 * 30 * 24 * 3600).
  2. Step 2: Include required directives for preload

    Preload requires max-age, includeSubDomains, and preload directive all present.
  3. 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;'.
  4. Final Answer:

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always; -> Option C
  5. Quick Check:

    Preload + includeSubDomains + 6 months = add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always; [OK]
Hint: Preload needs max-age, includeSubDomains, preload keywords [OK]
Common Mistakes:
  • Using wrong max-age for 6 months
  • Omitting preload directive
  • Not quoting header value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard