DEV Community

GoDedi
GoDedi

Posted on

Automating Bulk Website Security Headers, HTTPS, and DNS (SPF/DMARC) Audits in JavaScript published: true

When monitoring production websites or auditing client domains, checking whether an SSL certificate is valid is only half the story. Two of the most common blind spots in web security posture are missing HTTP security headers and misconfigured email DNS records (SPF/DMARC).

Checking domains manually with browser extensions or single-URL web tools works once—but it breaks down fast when you need to audit 20, 200, or 2,000 domains inside a CI/CD pipeline, agency reporting tool, or AI agent workflow.

In this guide, we will look at what a complete automated domain security audit should inspect and how to run bulk checks programmatically using JavaScript.

What an Automated Security Posture Audit Should Check

A reliable domain audit pipeline should evaluate four layers in a single pass:

  1. Core HTTP Security Headers (0–100 Score & A+ to F Grade):
    • Strict-Transport-Security (HSTS) — enforces HTTPS and prevents downgrade attacks.
    • Content-Security-Policy (CSP) — mitigates XSS and unauthorized script injection.
    • X-Content-Type-Options (nosniff) — stops MIME-type sniffing.
    • X-Frame-Options — defends against clickjacking.
    • Referrer-Policy & Permissions-Policy — limits referrer leakage and unnecessary browser API access.
  2. Server Fingerprinting Exposure:
    • Detects leaked headers such as Server, X-Powered-By, or X-AspNet-Version that expose backend stack details.
  3. HTTPS Enforcement & Redirect Chains:
    • Traces HTTP redirect hops safely (with SSRF protection blocking private/local IPs), verifies that the final destination enforces https://, and measures response latency.
  4. Live DNS & Email Authentication:
    • Resolves A, AAAA, CNAME, MX, TXT, and NS records via DNS-over-HTTPS (DoH), plus checks whether valid SPF and DMARC policies exist to prevent domain spoofing.

Running a Single Domain Audit via cURL

Instead of maintaining your own redirect tracer, header scorer, and DNS-over-HTTPS parser, you can query the Bulk Website Security Headers, SSL & DNS Audit API directly:

curl -X GET "https://<rapidapi-host>/v1/audit?domain=github.com&headers=true&dns=true" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: <rapidapi-host>"
Enter fullscreen mode Exit fullscreen mode

Example JSON Response

{
  "audited_at": "2026-11-28T02:15:10.373Z",
  "result": {
    "input": "github.com",
    "valid": true,
    "reachable": true,
    "final_url": "[https://github.com/](https://github.com/)",
    "http_status": 200,
    "https_enforced": true,
    "redirect_count": 0,
    "latency_ms": 31,
    "headers_audit": {
      "security_score": 85,
      "grade": "A",
      "missing": ["permissions-policy"],
      "exposed_server_headers": {
        "server": "GitHub.com"
      },
      "recommendations": [
        "Restrict unnecessary browser features (camera, microphone, geolocation) via Permissions-Policy"
      ]
    },
    "dns": {
      "domain": "github.com",
      "email_security": {
        "has_spf": true,
        "has_dmarc": true
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Bulk Auditing Multiple Domains in Node.js

For monitoring dashboards or scheduled DevOps checks, you can audit up to 20 domains per request using POST /v1/bulk-audit and flag any domain scoring below a B or missing DMARC:

const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;
const RAPIDAPI_HOST = "<rapidapi-host>";

async function runBulkSecurityAudit(domains) {
  const response = await fetch(`https://${RAPIDAPI_HOST}/v1/bulk-audit`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-RapidAPI-Key": RAPIDAPI_KEY,
      "X-RapidAPI-Host": RAPIDAPI_HOST
    },
    body: JSON.stringify({
      domains,
      headers: true,
      dns: true
    })
  });

  if (!response.ok) {
    throw new Error(`Audit failed with status ${response.status}`);
  }

  const data = await response.json();

  for (const item of data.results) {
    const grade = item.headers_audit?.grade ?? "N/A";
    const score = item.headers_audit?.security_score ?? 0;
    const dmarc = item.dns?.email_security?.has_dmarc ? "OK" : "MISSING";

    console.log(
      `${item.final_domain} | Grade: ${grade} (${score}/100) | HTTPS: ${item.https_enforced} | DMARC: ${dmarc}`
    );

    if (score < 70 || !item.dns?.email_security?.has_dmarc) {
      console.warn("  -> Action needed:", item.headers_audit?.recommendations);
    }
  }
}

runBulkSecurityAudit(["github.com", "stripe.com", "cloudflare.com"]);
Enter fullscreen mode Exit fullscreen mode

Scaling to Hundreds or Thousands of Domains (CSV/Excel/JSON)

If you need to audit large lists of domains on a schedule—or export clean spreadsheets for client security reports without writing any backend code—you can run the standalone Actor on Apify with configurable concurrency and pay-per-result pricing.

Try It Yourself

Automating these checks weekly catches missing HSTS/CSP headers and broken SPF/DMARC records before they become security incidents or email deliverability drops.

Top comments (0)