Check your API's security headers with inherited assertions
Security headers are boring, which is why they regress. Someone adds a new service behind the gateway, or swaps a framework, and the Strict-Transport-Security header quietly disappears. Nobody notices until a pen test report lists it.
You can check them on every request your collection sends, without writing a script per request.
What an API needs (and what it doesn't)
Browser-focused headers such as Content-Security-Policy matter for HTML pages. A JSON API needs a shorter list:
| Header | Expected | Why |
|---|---|---|
Strict-Transport-Security | max-age=… (a year is common) | Browsers won't fall back to plain HTTP. |
X-Content-Type-Options | nosniff | A JSON error page can't be sniffed into HTML or script. |
Content-Type | set on every response with a body | Clients and browsers don't guess. |
Cache-Control | no-store or private on personal data | Shared caches and proxies don't keep it. |
X-Powered-By, detailed Server | absent or generic | No free hint about versions to attack. |
CORS headers belong on the list too, but only for APIs called from browsers, and they're a topic of their own: see testing CORS.
Add them once, for the whole collection
Open the collection, then its Tests tab, and add assertions:
| Source | Path | Operator | Expected |
|---|---|---|---|
| Header | Strict-Transport-Security | contains | max-age= |
| Header | X-Content-Type-Options | equals | nosniff |
| Header | X-Powered-By | does not exist | |
| Header | Content-Type | exists |
Save the collection. Every request inside it, including those in subfolders, now runs these checks after its own scripts, and lists them read-only on its own Tests tab with where they come from. Inherited checks show their result against the last response, so you see the gaps right away.
Personal data: no caching
Put this on the folder that holds endpoints returning user data (profile, orders, invoices), not on the whole collection, since public endpoints may cache on purpose:
| Source | Path | Operator | Expected |
|---|---|---|---|
| Header | Cache-Control | contains | no-store |
If some of those endpoints use private instead, a folder-level post-response script accepts either:
const cc = (pm.response.headers.get('Cache-Control') || '').toLowerCase();
pm.test('personal data is not cached by shared caches', () => {
pm.expect(cc).to.match(/no-store|private/);
pm.expect(cc).to.not.include('public');
});Don't leak versions
pm.test('Server header does not include a version', () => {
const server = pm.response.headers.get('Server') || '';
pm.expect(server).to.not.match(/\d+\.\d+/);
});nginx is fine. nginx/1.18.0 (Ubuntu) tells an attacker which CVEs to try.
Errors count too
Security headers are often set by the framework's normal response path and missing from error handlers. Run the checks against a 404 and a 401 as well: an unknown path and a request without a token. If the headers only appear on 200s, the error path is set up separately and needs the same middleware.
Run it everywhere
requestarium run-collection "Public API" --env Production --folder "Smoke" --junit headers.xmlA read-only smoke folder against production is fine for this: headers are set by your edge and gateway, and staging often has a different one.