What is the purpose of security headers in HTTP responses?
Security headers help protect web applications by instructing browsers how to handle content securely, reducing risks like cross-site scripting and clickjacking.
Click to reveal answer
beginner
Name three common security headers you should validate in API testing.
Common security headers include Content-Security-Policy, X-Frame-Options, and Strict-Transport-Security.
Click to reveal answer
intermediate
How can you validate security headers using Postman tests?
In Postman, you write test scripts that check if the response headers contain expected security headers with correct values using pm.response.headers.get().
Click to reveal answer
beginner
What does the Strict-Transport-Security header do?
It tells browsers to only connect to the site using HTTPS for a specified time, preventing insecure HTTP connections.
Click to reveal answer
intermediate
Why is it important to check the X-Content-Type-Options header?
This header prevents browsers from MIME-sniffing a response away from the declared content-type, reducing the risk of executing malicious files.
Click to reveal answer
Which security header prevents your site from being embedded in iframes on other sites?
AX-Frame-Options
BContent-Security-Policy
CStrict-Transport-Security
DX-Content-Type-Options
✗ Incorrect
X-Frame-Options controls whether your site can be displayed in frames or iframes, protecting against clickjacking.
In Postman, which method retrieves a response header value for validation?
Apm.response.body.get()
Bpm.response.headers.get()
Cpm.request.headers.get()
Dpm.test.headers.get()
✗ Incorrect
pm.response.headers.get() fetches the value of a specific header from the response.
What does the Content-Security-Policy header help prevent?
A. Not checking if header exists before calling get()
B. Using to.include instead of to.have.string
C. Incorrect header name casing
D. Missing semicolon after pm.test
Solution
Step 1: Understand get() behavior when header missing
If header is missing, get() returns null, causing error on to.include.
Step 2: Identify missing existence check
Test should first check header exists before checking content.
Final Answer:
Not checking if header exists before calling get() -> Option A
Quick Check:
Check header presence before content check [OK]
Hint: Always verify header exists before content assertions [OK]
Common Mistakes:
Assuming get() never returns null
Ignoring null causing test errors
Focusing on casing or semicolons instead
5. You want to write a Postman test to ensure the Content-Security-Policy header disallows inline scripts by including script-src 'self'. Which test script correctly validates this?