Security Headers Questions with Answers

13 practice questions on Security Headers (Modern Web (Next.js, PWA, Performance)) with answers and step-by-step solutions. Try 10 samples below, then practise all 13 free in the AptiNest app.

Sample questions

Question 1Easy

What is Content-Security-Policy (CSP) mainly used to defend against?

  1. Brute-force password guessing
  2. Cross-site scripting (XSS)
  3. DNS spoofing attacks
  4. SQL injection on the server

Answer: B. Cross-site scripting (XSS)

Explanation

CSP restricts where scripts and other resources may load from, so injected scripts are blocked.

Step-by-step solution

  1. CSP is a response header that limits where resources load from.
  2. Blocking untrusted scripts stops injected code from running.
  3. Injected scripts are the main form of cross-site scripting.
  4. So the correct answer is cross-site scripting (XSS).

Why the other options are wrong

  • A. Password guessing is handled by rate limits, not CSP.
  • C. DNS spoofing is not stopped by CSP.
  • D. SQL injection is a server-side problem.

Tip: CSP is mainly an XSS defence.

Question 2Easy

What does X-Content-Type-Options: nosniff do?

  1. Hides the server software version
  2. Prevents cookies from being read
  3. Stops MIME-type guessing
  4. Forbids the page from being framed

Answer: C. Stops MIME-type guessing

Explanation

nosniff forces the browser to respect the declared Content-Type, blocking MIME-confusion attacks.

Step-by-step solution

  1. Browsers sometimes sniff a response to guess its type.
  2. nosniff tells them to trust the declared Content-Type.
  3. This prevents certain script-injection attacks.

Why the other options are wrong

  • A. That is about the Server header.
  • B. Cookie protection uses HttpOnly.
  • D. Framing is controlled by X-Frame-Options or CSP.

Tip: nosniff = no MIME guessing.

Question 3Easy

What does Strict-Transport-Security (HSTS) tell the browser?

  1. Use only HTTPS here for a set time
  2. Send no Referer header to other sites
  3. Never cache any page from this site
  4. Block all scripts from other origins

Answer: A. Use only HTTPS here for a set time

Explanation

After seeing HSTS, the browser upgrades future requests to HTTPS and refuses insecure connections for max-age seconds.

Step-by-step solution

  1. HSTS is a response header.
  2. It tells the browser to use HTTPS only for the site.
  3. It does this for the max-age period.
  4. So the correct answer is to use only HTTPS here for a set time.

Why the other options are wrong

  • B. That describes Referrer-Policy, not HSTS.
  • C. HSTS does not stop caching.
  • D. HSTS does not block scripts; CSP does that.

Tip: HSTS = HTTPS only for max-age seconds.

Question 4Easy

Which attack do X-Frame-Options and CSP frame-ancestors protect against?

  1. SQL injection
  2. Phishing emails
  3. Packet sniffing
  4. Clickjacking

Answer: D. Clickjacking

Explanation

They control whether other sites may embed the page in a frame, preventing invisible overlay tricks.

Step-by-step solution

  1. Clickjacking hides a page in a frame to trick the user into clicking.
  2. X-Frame-Options and frame-ancestors control whether the page can be framed.
  3. Blocking framing stops the overlay trick.
  4. So the correct answer is clickjacking.

Why the other options are wrong

  • A. SQL injection is a database attack.
  • B. Phishing is an email or social tactic.
  • C. Packet sniffing is stopped by HTTPS.

Tip: X-Frame-Options and frame-ancestors defend against clickjacking.

Question 5Medium

What is the Permissions-Policy header used for?

  1. Choosing which browser features the page may use
  2. Granting users admin permissions on the server
  3. Listing which origins may call the API
  4. Setting file permissions for uploaded files

Answer: A. Choosing which browser features the page may use

Explanation

It can disable features such as camera, microphone or geolocation for the page and its iframes.

Step-by-step solution

  1. Permissions-Policy is an HTTP response header.
  2. It lists which browser features (camera, microphone, geolocation and so on) the page may use.
  3. It can also turn those features off for the page and its iframes.
  4. So the correct answer is choosing which browser features the page may use.

Why the other options are wrong

  • B. Server admin rights are not handled by this header.
  • C. API origins are controlled by CORS, not Permissions-Policy.
  • D. File permissions are set on the server or file system, not by this header.

Tip: Permissions-Policy controls browser features; CORS controls cross-origin reads.

Question 6Medium

What does Referrer-Policy: strict-origin-when-cross-origin send to another site?

  1. The full URL including the query string
  2. Nothing at all in the Referer header
  3. The full URL, but only over HTTP
  4. Only the origin, and nothing on an HTTPS-to-HTTP downgrade

Answer: D. Only the origin, and nothing on an HTTPS-to-HTTP downgrade

Explanation

Cross-origin requests get just the origin, and nothing is sent on an HTTPS-to-HTTP downgrade; same-origin requests get the full URL.

Step-by-step solution

  1. Strict-origin-when-cross-origin sends the full URL for same-origin requests.
  2. For cross-origin requests it sends only the origin, with no path or query.
  3. On an HTTPS to HTTP downgrade it sends nothing.
  4. So the answer is only the origin, and nothing on a downgrade.

Why the other options are wrong

  • A. The full URL with query is only sent for same-origin requests, not cross-site.
  • B. Cross-origin requests still get the origin, so sending nothing is wrong here.
  • C. The full URL is never sent cross-site, and HTTP is not the case here.

Tip: Strict-origin-when-cross-origin: full URL same-site, origin only cross-site, nothing on downgrade.

Question 7Medium

How can a strict CSP still allow a specific inline script?

  1. Wrap the code in an immediately invoked function
  2. Give it a nonce matching one in the policy
  3. Add the defer attribute to the script tag
  4. Put the script at the end of the body

Answer: B. Give it a nonce matching one in the policy

Explanation

A per-response random nonce (or a hash of the script) marks trusted inline scripts while injected ones are blocked.

Step-by-step solution

  1. A strict CSP blocks inline scripts by default.
  2. A nonce is a random value sent in the policy and on the trusted script tag.
  3. A script whose nonce matches is allowed to run.
  4. So the correct answer is giving it a nonce matching one in the policy.

Why the other options are wrong

  • A. Wrapping in a function does not make an inline script trusted.
  • C. Defer only changes load timing, not inline script permission.
  • D. Position in the body does not bypass a strict CSP.

Tip: Use a per-response nonce or a hash for trusted inline scripts.

Question 8Medium

What does the CSP directive script-src 'self' allow?

  1. Scripts from the page's own origin only
  2. Scripts from the same domain and all subdomains
  3. Scripts from any HTTPS origin
  4. Inline scripts and eval only

Answer: A. Scripts from the page's own origin only

Explanation

'self' matches the same origin; inline scripts are blocked unless allowed by nonce, hash or 'unsafe-inline'.

Step-by-step solution

  1. 'self' in a CSP means the same origin as the page.
  2. Script-src 'self' lets scripts load from that origin.
  3. Other origins, including subdomains, are not included.
  4. So the correct answer is scripts from the page's own origin only.

Why the other options are wrong

  • B. Subdomains are not included; 'self' means the exact origin.
  • C. Any HTTPS origin is not allowed by 'self'.
  • D. 'self' does not allow inline scripts or eval.

Tip: 'self' means the exact same origin, not the whole domain.

Question 9Hard

A CSP contains script-src 'self' 'unsafe-inline'. Why is this weak against XSS?

  1. Injected inline scripts are still allowed
  2. It allows eval but blocks inline scripts
  3. It disables HTTPS for script files
  4. External scripts from any CDN are allowed

Answer: A. Injected inline scripts are still allowed

Explanation

'unsafe-inline' permits inline <script> and event-handler attributes, which is how most injected payloads run.

Step-by-step solution

  1. 'unsafe-inline' tells the browser to run inline script and event-handler code.
  2. An injected script is inline code, so the policy still runs it.
  3. That removes the main protection a CSP gives against XSS.
  4. So the correct answer is that injected inline scripts are still allowed.

Why the other options are wrong

  • B. The directive allows inline scripts rather than blocking them, so this option is backwards.
  • C. HTTPS is not affected by this directive.
  • D. A CDN is not the same origin as self, so it is not allowed by this source alone.

Tip: Avoid 'unsafe-inline' in script-src; use nonces or hashes instead.

Question 10Hard

What does the HSTS "preload" list solve?

  1. Mixed content inside HTTPS pages
  2. Expired TLS certificates on the server
  3. The first visit, before any HSTS header
  4. Slow TLS handshakes on mobile networks

Answer: C. The first visit, before any HSTS header

Explanation

Without preload, the first request may still go over HTTP; preloaded domains are HTTPS-only from the start.

Step-by-step solution

  1. A browser only learns about HSTS after the first HTTPS response carries the header.
  2. So the very first visit may still go over plain HTTP.
  3. The preload list builds HTTPS-only access into the browser from the start.
  4. So the correct answer is the first visit, before any HSTS header.

Why the other options are wrong

  • A. Mixed content is a separate issue and is not what preload fixes.
  • B. Expired certificates are a server problem, not solved by the preload list.
  • D. Handshake speed is not the purpose of HSTS preload.

Tip: HSTS preload protects the first visit; the header alone does not.

Practise all 13 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Modern Web (Next.js, PWA, Performance) topics · All topics