diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..b4666b1 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,20 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - run: npm ci + # tsc --noEmit runs first (see package.json), so a type error fails the + # build here before anything gets deployed. + - run: npm run build diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 461f71b..1e213b9 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -109,12 +109,14 @@ redeploy — the build copies neither automatically, so they must be placed alon ## Release checklist 1. `npm ci && npm run build` — the build fails on type errors, so it gates itself. -2. `node scripts/generate-sitemap.mjs https://www.blackdice.ai` if the static - sitemap needs refreshing (the server's live one needs nothing). -3. Deploy `dist/`, `server/`, `package.json`, and keep `content/` in place. -4. Check: `/`, `/mobile-sdk`, `/news`, one `/blog/` deep link, `/sitemap.xml`, + `build` also regenerates `public/sitemap.xml`/`robots.txt` from whatever is in + `content/site-content.json` (falling back to factory content) before `vite + build` copies `public/` into `dist/`, so the static sitemap can't go stale + relative to the last build. Set `SITE_URL` if it isn't `https://www.blackdice.ai`. +2. Deploy `dist/`, `server/`, `package.json`, and keep `content/` in place. +3. Check: `/`, `/mobile-sdk`, `/news`, one `/blog/` deep link, `/sitemap.xml`, `/admin` login. -5. In Search Console, submit `https://www.blackdice.ai/sitemap.xml` and request +4. In Search Console, submit `https://www.blackdice.ai/sitemap.xml` and request indexing for the product pages — they now have their own URLs to index. ## After the first deploy diff --git a/package.json b/package.json index 620de18..4b02bfe 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "node scripts/dev.mjs", "dev:web": "vite", "dev:api": "node server/index.mjs", - "build": "tsc --noEmit && vite build", + "build": "tsc --noEmit && node scripts/generate-sitemap.mjs && vite build", "start": "node server/index.mjs", "preview": "vite preview", "cms:ids": "node scripts/inject-cms-ids.mjs", diff --git a/public/content/posts/blackdice-gsma-open-gateway-channel-partnership.jpg b/public/content/posts/blackdice-gsma-open-gateway-channel-partnership.jpg new file mode 100644 index 0000000..3925998 Binary files /dev/null and b/public/content/posts/blackdice-gsma-open-gateway-channel-partnership.jpg differ diff --git a/public/content/posts/broadband-arpu-is-stalling-trust-might-be-the-fix.jpg b/public/content/posts/broadband-arpu-is-stalling-trust-might-be-the-fix.jpg new file mode 100644 index 0000000..b53b878 Binary files /dev/null and b/public/content/posts/broadband-arpu-is-stalling-trust-might-be-the-fix.jpg differ diff --git a/public/content/posts/connectivity-alone-isn-t-enough-value-and-trust-keeps-subscr.jpg b/public/content/posts/connectivity-alone-isn-t-enough-value-and-trust-keeps-subscr.jpg new file mode 100644 index 0000000..ae92ed5 Binary files /dev/null and b/public/content/posts/connectivity-alone-isn-t-enough-value-and-trust-keeps-subscr.jpg differ diff --git a/public/content/posts/cybersecurity-blackdice-partners-with-bluecloud.jpg b/public/content/posts/cybersecurity-blackdice-partners-with-bluecloud.jpg new file mode 100644 index 0000000..4ffcbf8 Binary files /dev/null and b/public/content/posts/cybersecurity-blackdice-partners-with-bluecloud.jpg differ diff --git a/public/content/posts/from-speed-to-online-safety-cybersecurity-is-the-new-foundat.jpg b/public/content/posts/from-speed-to-online-safety-cybersecurity-is-the-new-foundat.jpg new file mode 100644 index 0000000..610210d Binary files /dev/null and b/public/content/posts/from-speed-to-online-safety-cybersecurity-is-the-new-foundat.jpg differ diff --git a/public/content/posts/mobile-cybersecurity-breeds-loyalty.jpg b/public/content/posts/mobile-cybersecurity-breeds-loyalty.jpg new file mode 100644 index 0000000..757a2b7 Binary files /dev/null and b/public/content/posts/mobile-cybersecurity-breeds-loyalty.jpg differ diff --git a/public/content/posts/stopping-vietnam-s-scam-epidemic-viettel-partners-with-black.jpg b/public/content/posts/stopping-vietnam-s-scam-epidemic-viettel-partners-with-black.jpg new file mode 100644 index 0000000..eadb364 Binary files /dev/null and b/public/content/posts/stopping-vietnam-s-scam-epidemic-viettel-partners-with-black.jpg differ diff --git a/public/content/posts/subscriber-churn-is-a-symptom-here-s-the-cause.jpg b/public/content/posts/subscriber-churn-is-a-symptom-here-s-the-cause.jpg new file mode 100644 index 0000000..6c37d93 Binary files /dev/null and b/public/content/posts/subscriber-churn-is-a-symptom-here-s-the-cause.jpg differ diff --git a/public/content/posts/the-fccs-router-extension-creates-a-wider-exploit-window.jpg b/public/content/posts/the-fccs-router-extension-creates-a-wider-exploit-window.jpg new file mode 100644 index 0000000..6e67994 Binary files /dev/null and b/public/content/posts/the-fccs-router-extension-creates-a-wider-exploit-window.jpg differ diff --git a/public/content/posts/the-network-knows-first.jpg b/public/content/posts/the-network-knows-first.jpg new file mode 100644 index 0000000..9e6649d Binary files /dev/null and b/public/content/posts/the-network-knows-first.jpg differ diff --git a/public/content/posts/the-platform-layer-is-not-enough-why-online-safety-needs-the.jpg b/public/content/posts/the-platform-layer-is-not-enough-why-online-safety-needs-the.jpg new file mode 100644 index 0000000..db74a6e Binary files /dev/null and b/public/content/posts/the-platform-layer-is-not-enough-why-online-safety-needs-the.jpg differ diff --git a/public/content/posts/three-cybersecurity-pillars-for-latam-telecom-operators.jpg b/public/content/posts/three-cybersecurity-pillars-for-latam-telecom-operators.jpg new file mode 100644 index 0000000..bf82030 Binary files /dev/null and b/public/content/posts/three-cybersecurity-pillars-for-latam-telecom-operators.jpg differ diff --git a/public/content/posts/why-mvnos-can-t-afford-to-ignore-cybersecurity-as-a-growth-d.jpg b/public/content/posts/why-mvnos-can-t-afford-to-ignore-cybersecurity-as-a-growth-d.jpg new file mode 100644 index 0000000..b1aeafa Binary files /dev/null and b/public/content/posts/why-mvnos-can-t-afford-to-ignore-cybersecurity-as-a-growth-d.jpg differ diff --git a/public/sitemap.xml b/public/sitemap.xml index 1806951..aed3d7c 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -2,52 +2,52 @@ https://www.blackdice.ai/ - 2026-08-12 + 2026-08-13 1.0 https://www.blackdice.ai/mobile-sdk - 2026-08-12 + 2026-08-13 0.9 https://www.blackdice.ai/dns-protect - 2026-08-12 + 2026-08-13 0.9 https://www.blackdice.ai/halo-cpe - 2026-08-12 + 2026-08-13 0.9 https://www.blackdice.ai/for-operators - 2026-08-12 + 2026-08-13 0.8 https://www.blackdice.ai/financial-services - 2026-08-12 + 2026-08-13 0.8 https://www.blackdice.ai/why-blackdice - 2026-08-12 + 2026-08-13 0.7 https://www.blackdice.ai/news - 2026-08-12 + 2026-08-13 0.8 https://www.blackdice.ai/investors - 2026-08-12 + 2026-08-13 0.6 https://www.blackdice.ai/contact - 2026-08-12 + 2026-08-13 0.7 diff --git a/server/index.mjs b/server/index.mjs index be926fd..fba9520 100644 --- a/server/index.mjs +++ b/server/index.mjs @@ -8,13 +8,16 @@ * * node server/index.mjs * - * Environment + * Environment — read from the real process environment in production; for + * local dev, .env.local (falling back to .env) is loaded automatically below. * PORT listen port (default 8787) * ADMIN_PASSWORD password for /admin (required in production) * ADMIN_SECRET token signing secret (default: derived from password) * CONTENT_DIR where published content is kept (default ./content) * DIST_DIR built site to serve (default ./dist) * SITE_URL canonical origin for sitemap.xml (default https://www.blackdice.ai) + * TRUST_PROXY trust X-Forwarded-For's first hop for login rate limiting + * (only set this if a reverse proxy you control strips/sets it) */ import http from 'node:http' import fs from 'node:fs' @@ -24,6 +27,19 @@ import crypto from 'node:crypto' import { fileURLToPath } from 'node:url' const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') + +// Local dev convenience: load .env.local (or .env) into process.env if present. +// Production deploys set real environment variables and don't need this — +// missing files are silently ignored. +for (const name of ['.env.local', '.env']) { + try { + process.loadEnvFile(path.join(ROOT, name)) + break + } catch { + /* file doesn't exist — try the next one */ + } +} + const PORT = Number(process.env.PORT || 8787) const CONTENT_DIR = path.resolve(process.env.CONTENT_DIR || path.join(ROOT, 'content')) const DIST_DIR = path.resolve(process.env.DIST_DIR || path.join(ROOT, 'dist')) @@ -32,9 +48,15 @@ const VERSION_DIR = path.join(CONTENT_DIR, 'versions') const CONTENT_FILE = path.join(CONTENT_DIR, 'site-content.json') const LEADS_FILE = path.join(CONTENT_DIR, 'leads.jsonl') const SITE_URL = (process.env.SITE_URL || 'https://www.blackdice.ai').replace(/\/+$/, '') +const TRUST_PROXY = process.env.TRUST_PROXY === '1' || process.env.TRUST_PROXY === 'true' const DEV_PASSWORD = 'blackdice' const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || DEV_PASSWORD +if (process.env.NODE_ENV === 'production' && ADMIN_PASSWORD === DEV_PASSWORD) { + console.error('✗ ADMIN_PASSWORD is unset (or "blackdice") with NODE_ENV=production. Refusing to start.') + console.error(' Set a real ADMIN_PASSWORD — see .env.example / docs/DEPLOYMENT.md.') + process.exit(1) +} const SECRET = process.env.ADMIN_SECRET || crypto.createHash('sha256').update('bd:' + ADMIN_PASSWORD).digest('hex') const SESSION_MS = 12 * 60 * 60 * 1000 const MAX_BODY = 32 * 1024 * 1024 // uploads arrive as data URLs @@ -62,6 +84,16 @@ function validToken(token) { const bearer = (req) => (req.headers.authorization || '').replace(/^Bearer\s+/i, '') const isAuthed = (req) => validToken(bearer(req)) +// Only honour X-Forwarded-For when TRUST_PROXY is set — otherwise a client can +// spoof it to dodge (or trigger) the login throttle below. +function clientIp(req) { + if (TRUST_PROXY) { + const fwd = String(req.headers['x-forwarded-for'] || '').split(',')[0].trim() + if (fwd) return fwd + } + return req.socket.remoteAddress || 'unknown' +} + // Crude but effective throttle: 10 failures per IP per 15 minutes. const failures = new Map() function tooManyAttempts(ip) { @@ -80,11 +112,23 @@ function noteFailure(ip) { } // ── Helpers ──────────────────────────────────────────────────────────────────── +// Applied to every response. Kept narrow (no site-wide CSP): the legacy markup +// relies on inline onclick="" handlers and third-party embeds (HubSpot), so a +// script-src lockdown would need to be introduced carefully, with the real site +// exercised in a browser first, rather than blind here. +const SECURITY_HEADERS = { + 'X-Content-Type-Options': 'nosniff', + 'X-Frame-Options': 'SAMEORIGIN', + 'Referrer-Policy': 'strict-origin-when-cross-origin', + 'Permissions-Policy': 'geolocation=(), camera=(), microphone=()', +} + const send = (res, status, body, headers = {}) => { const payload = typeof body === 'string' || Buffer.isBuffer(body) ? body : JSON.stringify(body) res.writeHead(status, { 'Content-Type': typeof body === 'object' && !Buffer.isBuffer(body) ? 'application/json' : 'text/plain; charset=utf-8', 'Cache-Control': 'no-store', + ...SECURITY_HEADERS, ...headers, }) res.end(payload) @@ -154,6 +198,7 @@ async function serveFile(req, res, file, { immutable = false } = {}) { 'Accept-Ranges': 'bytes', 'Content-Length': end - start + 1, 'Cache-Control': cache, + ...SECURITY_HEADERS, }) fs.createReadStream(file, { start, end }).pipe(res) return true @@ -163,6 +208,7 @@ async function serveFile(req, res, file, { immutable = false } = {}) { 'Content-Length': stat.size, 'Accept-Ranges': 'bytes', 'Cache-Control': cache, + ...SECURITY_HEADERS, }) fs.createReadStream(file).pipe(res) return true @@ -177,14 +223,16 @@ function safeJoin(root, urlPath) { // ── API ──────────────────────────────────────────────────────────────────────── const DATA_URL = /^data:([a-z0-9.+/-]+);base64,([A-Za-z0-9+/=\s]+)$/i +// SVG deliberately excluded: it can carry