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:

HeaderExpectedWhy
Strict-Transport-Securitymax-age=… (a year is common)Browsers won't fall back to plain HTTP.
X-Content-Type-OptionsnosniffA JSON error page can't be sniffed into HTML or script.
Content-Typeset on every response with a bodyClients and browsers don't guess.
Cache-Controlno-store or private on personal dataShared caches and proxies don't keep it.
X-Powered-By, detailed Serverabsent or genericNo 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:

SourcePathOperatorExpected
HeaderStrict-Transport-Securitycontainsmax-age=
HeaderX-Content-Type-Optionsequalsnosniff
HeaderX-Powered-Bydoes not exist
HeaderContent-Typeexists

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:

SourcePathOperatorExpected
HeaderCache-Controlcontainsno-store

If some of those endpoints use private instead, a folder-level post-response script accepts either:

JavaScript
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

JavaScript
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

Terminal
requestarium run-collection "Public API" --env Production --folder "Smoke" --junit headers.xml

A 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.