#!/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(/]*>([\s\S]*?)<\/title>/i)?.[1]?.trim() ?? null; return { htmlBytes: Buffer.byteLength(html), title: anyTitle, titleInHead: Boolean(titleInHead), titleRepeatsBrand: anyTitle ? (anyTitle.match(/Cynbit Technologies/g) ?? []).length > 1 : false, description: meta(html, "name", "description"), canonical: html.match(/]+rel=["']canonical["'][^>]*href=["']([^"']+)["']/i)?.[1] ?? null, ogUrl: meta(html, "property", "og:url"), ogImage: meta(html, "property", "og:image"), robots: meta(html, "name", "robots"), scriptTags: (html.match(//g)].reduce((n, m) => n + m[1].length, 0), botProtection: { turnstile: /challenges\.cloudflare\.com\/turnstile|cf-turnstile/i.test(html), recaptcha: /google\.com\/recaptcha|grecaptcha/i.test(html), hcaptcha: /hcaptcha\.com/i.test(html), }, forms: (html.match(/ html.includes(k)), }; } function analyseHeaders(h) { const present = Object.fromEntries(SECURITY_HEADERS.map((k) => [k, h[k] ?? null])); const hsts = h["strict-transport-security"]; const maxAge = Number(hsts?.match(/max-age=(\d+)/i)?.[1] ?? 0); const csp = h["content-security-policy"] ?? ""; return { present, info: Object.fromEntries(INFO_HEADERS.map((k) => [k, h[k] ?? null])), checks: { hstsAtLeast1Year: maxAge >= 31536000, hstsIncludeSubDomains: /includesubdomains/i.test(hsts ?? ""), cspEnforced: Boolean(h["content-security-policy"]), cspFrameAncestors: /frame-ancestors/i.test(csp), cspObjectSrcNone: /object-src\s+'none'/i.test(csp), clickjackingProtected: /frame-ancestors/i.test(csp) || Boolean(h["x-frame-options"]), nosniff: (h["x-content-type-options"] ?? "").toLowerCase() === "nosniff", poweredByHidden: !h["x-powered-by"], }, }; } function cookieFlags(setCookie) { return setCookie.map((c) => ({ name: c.split("=")[0], secure: /;\s*secure/i.test(c), httpOnly: /;\s*httponly/i.test(c), sameSite: c.match(/;\s*samesite=(\w+)/i)?.[1] ?? null, })); } const yes = (b) => (b ? "yes" : "**no**"); function toMarkdown(results) { const when = new Date().toISOString(); const lines = [`# Passive audit output`, ``, `Generated ${when} by \`scripts/passive-audit.mjs\`. One GET per URL, ${DELAY_MS} ms apart.`, ``]; lines.push(`## Redirects and status`, ``, `| URL | Chain | Final status | Time (ms) |`, `| --- | --- | --- | --- |`); for (const r of results) { const chain = r.chain.map((c) => `${c.status}${c.location ? ` → ${c.location}` : ""}`).join("
"); lines.push(`| ${r.url} | ${chain || "error"} | ${r.final?.status ?? r.error} | ${r.final?.ms ?? ""} |`); } const html = results.filter((r) => r.headers && r.final?.headers["content-type"]?.includes("text/html")); if (html.length) { const h0 = html.find((r) => r.url === "https://www.cynbit.in/") ?? html[0]; lines.push(``, `## Security headers (from ${h0.url})`, ``, `| Header | Value |`, `| --- | --- |`); for (const [k, v] of Object.entries(h0.headers.present)) lines.push(`| ${k} | ${v ? `\`${v.slice(0, 160)}${v.length > 160 ? "…" : ""}\`` : "**missing**"} |`); lines.push(``, `| Check | Result |`, `| --- | --- |`); for (const [k, v] of Object.entries(h0.headers.checks)) lines.push(`| ${k} | ${yes(v)} |`); lines.push(``, `## Platform and caching`, ``, `| URL | server | x-powered-by | cache-control | cache status |`, `| --- | --- | --- | --- | --- |`); for (const r of html) { const i = r.headers.info; const cacheStatus = i["x-vercel-cache"] ?? i["x-nextjs-cache"] ?? i["cf-cache-status"] ?? i["x-cache"] ?? ""; lines.push(`| ${r.url.replace("https://www.cynbit.in", "") || "/"} | ${i.server ?? ""} | ${i["x-powered-by"] ?? ""} | ${i["cache-control"] ?? ""} | ${cacheStatus} |`); } lines.push(``, `## Metadata (P-01, P-02, P-03)`, ``, `| Path | Title | Title in head | Brand repeated | Description | Canonical | og:url | og:image |`, `| --- | --- | --- | --- | --- | --- | --- | --- |`); for (const r of html) { const p = r.page; lines.push(`| ${r.url.replace("https://www.cynbit.in", "") || "/"} | ${p.title ?? "**none**"} | ${yes(p.titleInHead)} | ${p.titleRepeatsBrand ? "**yes**" : "no"} | ${p.description ? "yes" : "**none**"} | ${p.canonical ?? "**none**"} | ${p.ogUrl ?? "**none**"} | ${p.ogImage ?? "**none**"} |`); } lines.push(``, `## Payload and forms`, ``, `| Path | HTML KB | Scripts | RSC chunks | RSC KB | Forms | Bot protection | Icon font subset | Hints to review |`, `| --- | --- | --- | --- | --- | --- | --- | --- | --- |`); for (const r of html) { const p = r.page; const bots = Object.entries(p.botProtection).filter(([, v]) => v).map(([k]) => k).join(", ") || "none detected"; const icons = p.materialSymbolsFont ? (p.materialSymbolsSubset ? "subset" : "**full font**") : "n/a"; lines.push(`| ${r.url.replace("https://www.cynbit.in", "") || "/"} | ${(p.htmlBytes / 1024).toFixed(1)} | ${p.scriptTags} | ${p.rscPayloadChunks} | ${(p.rscPayloadBytes / 1024).toFixed(1)} | ${p.forms} | ${bots} | ${icons} | ${p.rscSensitiveHints.join(", ") || ""} |`); } const cookies = html.flatMap((r) => r.cookies.map((c) => ({ ...c, url: r.url }))); lines.push(``, `## Cookies set on page load`, ``); if (!cookies.length) lines.push(`None.`); else { lines.push(`| Page | Name | Secure | HttpOnly | SameSite |`, `| --- | --- | --- | --- | --- |`); for (const c of cookies) lines.push(`| ${c.url} | ${c.name} | ${yes(c.secure)} | ${yes(c.httpOnly)} | ${c.sameSite ?? "**unset**"} |`); } } lines.push(``, `## Well-known files`, ``); for (const r of results.filter((x) => /robots|sitemap|security\.txt/.test(x.url))) { lines.push(`- ${r.url}: ${r.final?.status ?? r.error}${r.final?.status === 200 ? ` (${r.final.body.length} bytes)` : ""}`); } lines.push(``, `"Hints to review" are plain substring matches in the HTML and RSC payload. Open view-source and check each one in context before reporting it.`); return lines.join("\n") + "\n"; } async function main() { const results = []; for (const [i, t] of TARGETS.entries()) { if (i) await sleep(DELAY_MS); process.stdout.write(`GET ${t.url} ... `); try { const { chain, final } = await get(t.url); const entry = { url: t.url, note: t.note, chain, final: final && { url: final.url, status: final.status, ms: final.ms, headers: final.headers, body: final.body } }; if (final) { entry.headers = analyseHeaders(final.headers); entry.cookies = cookieFlags(final.setCookie); if ((final.headers["content-type"] ?? "").includes("text/html")) entry.page = inspectHtml(final.body); } results.push(entry); console.log(final?.status ?? "too many redirects"); } catch (err) { results.push({ url: t.url, note: t.note, chain: [], error: String(err?.message ?? err) }); console.log(`error: ${err?.message ?? err}`); } } await mkdir(join(ROOT, "evidence"), { recursive: true }); const json = results.map(({ final, ...rest }) => ({ ...rest, final: final && { ...final, body: undefined, bodyBytes: final.body?.length } })); await writeFile(join(ROOT, "evidence", "passive-audit.json"), JSON.stringify({ generatedAt: new Date().toISOString(), userAgent: UA, results: json }, null, 2)); await writeFile(join(ROOT, "evidence", "passive-audit.md"), toMarkdown(results)); console.log(`\nWrote evidence/passive-audit.md and evidence/passive-audit.json`); } main().catch((e) => { console.error(e); process.exit(1); });