Fix security headers are not configured in Gatsby

The application does not set the baseline security response headers. Without them a browser will not enforce HTTPS, will guess content types, and will allow the page to be framed. Headers set by a CDN or ingress are invisible to static analysis, so this rule reports lower confidence when it finds no header configuration at all.

medium likely Gatsby CWE-693 / OWASP A05:2021

The vulnerable pattern in Gatsby

MEDIUM possible Security headers are not configured A05:2021 gatsby-config.js:2:1 1 │ // No security headers configured - security-headers-missing points here. 2 │ module.exports = { │ ~~~~~~~~~~~~~~~~~~ no security headers configured here 3 │ siteMetadata: { 4 │ title: 'fixture-gatsby-api',

This finding comes from the Gatsby fixture in the owlwarden test suite. Without these headers the browser enforces nothing: strict-transport-security forces HTTPS for future requests; content-security-policy limits which scripts and origins the page may load; x-content-type-options stops browsers guessing a response's content type; x-frame-options blocks clickjacking via framing; referrer-policy stops URLs leaking to third parties.

The corrected handler

Set the headers on the dev server, and via your host's static headers config (e.g. gatsby-plugin-netlify) in production.

// gatsby-node.js
exports.onCreateDevServer = ({ app }) => {
  app.use((req, res, next) => {
    res.setHeader('Strict-Transport-Security', 'max-age=63072000; includeSubDomains')
    res.setHeader('Content-Security-Policy', "default-src 'self'")
    res.setHeader('X-Content-Type-Options', 'nosniff')
    res.setHeader('X-Frame-Options', 'DENY')
    res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin')
    next()
  })
}

If you are not using Gatsby

Set these response headers at the edge or in the app: strict-transport-security, content-security-policy, x-content-type-options, x-frame-options, referrer-policy.

Check your own repository

npx owlwarden scan
npx owlwarden explain security-headers-missing

Runs on your machine. No account, no telemetry, no network unless you ask. In CI, SARIF uploads to code scanning and the exit code is the gate.

Other Gatsby checks

Rules with a tested Gatsby example.

security-headers-missing for every framework / All rules / owlwarden