#!/usr/bin/env node /** * Passive audit of www.cynbit.in: closes the "To verify" gaps in REPORT.md. * * What it does: one ordinary GET per public URL below, sequentially, with a pause between * requests and an honest User-Agent. That is less traffic than one person * browsing the site. * What it never does: submit forms, send POST/PUT/DELETE, guess paths, fuzz parameters, * follow links it discovers, or retry aggressively. * * Usage: node scripts/passive-audit.mjs (Node 18.17+, no dependencies) * Output: evidence/passive-audit.json and evidence/passive-audit.md */ import { mkdir, writeFile } from "node:fs/promises"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const ROOT = join(dirname(fileURLToPath(import.meta.url)), ".."); const UA = "cynbit-assessment-passive-audit/1.0 (backend intern candidate; read-only, low-rate)"; const DELAY_MS = 1500; const MAX_HOPS = 5; // Pages a normal visitor would load, plus three files crawlers fetch by convention. const TARGETS = [ { url: "http://cynbit.in/", note: "HTTP to HTTPS and apex to www redirect chain" }, { url: "https://cynbit.in/", note: "Apex host behaviour" }, { url: "https://www.cynbit.in/", note: "Homepage" }, { url: "https://www.cynbit.in/careers", note: "Careers index" }, { url: "https://www.cynbit.in/careers/backend-developer-intern", note: "Dynamic job route + application form" }, { url: "https://www.cynbit.in/contact", note: "Contact form" }, { url: "https://www.cynbit.in/products", note: "Demo request form" }, { url: "https://www.cynbit.in/diaries", note: "User-generated content listing" }, { url: "https://www.cynbit.in/blog", note: "Blog index" }, { url: "https://www.cynbit.in/blog?category=SaaS%20Development", note: "Query-string filter caching (P-05)" }, { url: "https://www.cynbit.in/blog/future-saas-development", note: "Blog post" }, { url: "https://www.cynbit.in/robots.txt", note: "Crawler policy" }, { url: "https://www.cynbit.in/sitemap.xml", note: "Sitemap" }, { url: "https://www.cynbit.in/.well-known/security.txt", note: "Vulnerability disclosure (S-10)" }, ]; const SECURITY_HEADERS = [ "content-security-policy", "content-security-policy-report-only", "strict-transport-security", "x-content-type-options", "referrer-policy", "permissions-policy", "x-frame-options", "cross-origin-opener-policy", ]; const INFO_HEADERS = ["server", "x-powered-by", "cache-control", "age", "x-vercel-cache", "x-nextjs-cache", "x-nextjs-prerender", "cf-cache-status", "x-cache", "vary", "content-type", "content-encoding"]; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); async function get(url) { const chain = []; let current = url; for (let hop = 0; hop <= MAX_HOPS; hop++) { const started = performance.now(); const res = await fetch(current, { method: "GET", redirect: "manual", headers: { "User-Agent": UA, Accept: "text/html,application/xhtml+xml,*/*;q=0.8", "Accept-Encoding": "gzip, br" }, signal: AbortSignal.timeout(15_000), }); const ms = Math.round(performance.now() - started); const headers = Object.fromEntries(res.headers); const location = res.headers.get("location"); if (res.status >= 300 && res.status < 400 && location) { chain.push({ url: current, status: res.status, ms, location }); current = new URL(location, current).href; await sleep(DELAY_MS); continue; } const body = await res.text(); chain.push({ url: current, status: res.status, ms }); return { chain, final: { url: current, status: res.status, ms, headers, setCookie: res.headers.getSetCookie?.() ?? [], body } }; } return { chain, final: null }; } function meta(html, attr, name) { const re = new RegExp(`]+${attr}=["']${name}["'][^>]*>`, "i"); const tag = html.match(re)?.[0]; return tag?.match(/content=["']([^"']*)["']/i)?.[1] ?? null; } function inspectHtml(html) { const titleInHead = html.match(/
]*>([\s\S]*?)<\/title>[\s\S]*?<\/head>/i)?.[1]?.trim() ?? null; const anyTitle = html.match(/