header-sentinel

Sentinel · security scanner

header-sentinel

Fail CI when deployed URLs ship weak HTTP security headers.

npm i -D header-sentinel

What it checks

  • HSTS and HTTPS redirectsmax-age of at least a year, includeSubDomains, preload eligibility and HTTP → HTTPS redirect chains.
  • Content-Security-PolicyMissing policies, unsafe-inline and unsafe-eval, overly broad wildcards and missing directives.
  • Framing, sniffing and isolationX-Frame-Options or CSP frame-ancestors, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and Cross-Origin-Opener-Policy.
  • Information leaksServer and X-Powered-By headers that reveal your stack, and the deprecated X-XSS-Protection header.
  • Grades with fixesObservatory-style A+ to F score, with an example header plus Nginx, Express, Vercel and Netlify hints for each finding.
  • BaselinesRecord accepted findings once, then fail only on new issues in pull requests and nightly runs.

Quick usage

CLI

# Scan a URL
npx header-sentinel https://example.com

# Record a baseline, then fail only on new issues
npx header-sentinel https://example.com --baseline .header-baseline.json --update-baseline
npx header-sentinel https://example.com --baseline .header-baseline.json --fail-on error

# Scan every URL in a sitemap, output SARIF
npx header-sentinel --sitemap https://example.com/sitemap.xml --sarif report.sarif

API

import { scanAll, shouldFail } from 'header-sentinel';

const results = await scanAll(['https://example.com'], { timeout: 5000 });
console.log(results[0].grade);
if (shouldFail(results, 'error')) process.exit(1);

Every option is documented in the header-sentinel docs.

CI / GitHub Action

name: Security headers
on:
  deployment_status:
  schedule: [{ cron: '0 6 * * 1' }]
permissions: { contents: read, security-events: write }
jobs:
  headers:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: MrLouisWright/header-sentinel@v1
        with:
          urls: https://example.com https://example.com/login
          fail-on: error
          sarif: header-sentinel.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: header-sentinel.sarif }