Skip to content
CyberHub AcademyDefensive learning lab

Trust & transparency

Security model, deployment checklist and limitations

This project is a same-origin learning platform built with Next.js, PostgreSQL and Drizzle ORM. The original brief described a FastAPI/SQLAlchemy deployment with Redis; this implementation delivers the same security properties using the runtime available here. The differences are listed openly rather than hidden.

Controls included in this codebase

Database-backed accounts

Users, sessions, progress, quiz attempts, lab results, dictionary terms, tutor transcripts and certificates live in PostgreSQL via Drizzle ORM.

Argon2id password hashing

Passwords are hashed with Argon2id (m=19456 KiB, t=2, p=1) using a unique 16-byte salt and verified with a constant-time comparison.

Opaque server-side sessions

A 256-bit random token is set in an HttpOnly cookie. The database stores only its SHA-256 hash, plus expiry and last-seen metadata, so a database leak cannot be replayed.

CSRF double-submit + origin checks

A non-HttpOnly CSRF cookie is seeded by middleware; every state-changing request must echo it in the x-csrf-token header and come from the same Origin/Host.

Durable rate limiting

Registration, login, progress, tutor and lab endpoints are limited using PostgreSQL-backed counters, shared across instances instead of per-process memory.

Security headers

Content-Security-Policy, X-Frame-Options DENY, nosniff, strict referrer policy, Permissions-Policy, COOP and no-store on API responses.

Server-only AI

Gemini is called from a server route only. The API key is read from the environment, never returned to the client, and requests have timeouts, safety settings and graceful fallback.

Per-account authorisation

Progress, quiz results, lab results and certificates are queried with the session user id. There is no client-supplied user identifier to tamper with.

Input and output discipline

Server-side validation of every write, allow-listed status values, length limits, HTML-escaped React rendering and parameterised SQL through the ORM.

Privacy-minded logging

Client IPs are hashed before use, tutor input is redacted for obvious secrets, and health checks return status only.

Public deployment checklist

Do not expose the development configuration directly to the internet.

Hosting and environment

  • Host on a provider that supports containerised Node.js/Next.js and a managed PostgreSQL database.
  • Set APP_ENV=production, a strong unique secret of 32+ random characters, COOKIE_SECURE=true and ALLOWED_HOSTS to your exact domain.
  • Set DATABASE_URL to a managed PostgreSQL instance with TLS and private networking.
  • Provide GEMINI_API_KEY as a server-side secret only. Never expose it with a NEXT_PUBLIC_ prefix.
  • Do not publish PostgreSQL or Redis ports to the internet.

Transport and edge

  • Terminate TLS at a trusted proxy and redirect all HTTP to HTTPS. Enable HSTS with a long max-age.
  • Trust forwarded headers only from your own proxy, or rate limiting can be spoofed.
  • Keep the CSP enforced; avoid adding 'unsafe-inline' or remote script origins to silence reports.
  • Add a WAF or edge rate limit as defence in depth, never as the only authorisation control.

Identity and account lifecycle

  • Add email verification before allowing full access, and store verification token hashes with expiry.
  • Add password reset using single-use, short-lived, hashed tokens delivered over email.
  • Add account deletion and data export, including tutor transcripts and progress rows.
  • Add breached-password checks and optional MFA with phishing-resistant authenticators.
  • Add abuse reporting, moderation and an administrator review path before public registration.

Operations

  • Configure automated daily database backups plus point-in-time recovery, and rehearse a restore.
  • Ship security-relevant logs off-host, set retention and alert on authentication anomalies.
  • Enable dependency and container scanning, plus a patch SLA (for example 72h for critical internet-facing flaws).
  • Add error monitoring that never captures passwords, session tokens, cookies or tutor secrets.
  • Publish a contact address for security reports and a coordinated disclosure policy.

AI provider

  • Check the provider's current pricing, age rules, quotas and terms before enabling the tutor for public visitors.
  • Decide whether transcripts are retained, for how long, and how a learner requests deletion.
  • Keep safety settings and rate limits enabled; keep a curriculum-grounded fallback answer when the provider is unavailable.
  • Warn learners never to submit personal information, credentials or private data.

Before opening registration publicly

  • Have a qualified adult or site administrator review privacy, child-safety, legal and hosting requirements.
  • Publish privacy, terms and retention policies, and a clear statement of what data is collected.
  • Test registration, login, logout, CSRF rejection, session expiry, rate limits, progress isolation, mobile layout, AI failure handling and backup restore.
  • Decide on age limits and guardian consent if the audience may include minors.

Environment variables

DATABASE_URL
Required. PostgreSQL connection string.
COOKIE_SECURE
Set to true in HTTPS production. Defaults off so plain-HTTP previews still work.
GEMINI_API_KEY
Optional. Server-only key for the AI tutor. Without it, the tutor returns a labelled curriculum fallback.
GEMINI_MODEL
Optional. Defaults to gemini-2.5-flash with a secondary fallback model.
APP_ENV / ALLOWED_HOSTS / APP_SECRET_KEY
Use in your hosting configuration and reverse proxy. This code does not print or expose them.

Security notes and limitations

  • This is a deployable starter, not a third-party security audit and not a guarantee of zero vulnerabilities.
  • Registration creates an account immediately. Email verification and password reset are not implemented yet — add them before a broad public launch.
  • Account deletion, self-service data export and moderation tooling are not included.
  • Rate limiting uses PostgreSQL in this implementation rather than Redis. It is durable across processes, but it adds a small write per request; use Redis if you need very high throughput.
  • The CSRF design is a double-submit cookie plus Origin/Host validation. That is appropriate for this same-origin app; cross-site API clients need a different, deliberate design.
  • Sessions are server-side and revocable, but there is no device management UI or per-session audit screen.
  • The tutor is a generative AI service and can make mistakes. It is deliberately restricted to defensive topics but must not be treated as an authority.
  • The certificate is an unaccredited platform completion record. It is not professional certification or evidence of competence.
  • Practice activities and labs are intentionally simulated. They do not teach live exploitation and must not be treated as authorisation to test any system.
  • CSP currently allows inline scripts and styles because of the framework's hydration requirements. Tighten it with nonces or hashes in a production hardening pass.

Test before inviting the public

Verified manually on this build unless stated otherwise. Repeat these checks in your own environment.

  1. 01Register a new account and sign in. Confirm the session cookie is HttpOnly and that the CSRF cookie rotates on login.
  2. 02Sign out and confirm the old session token no longer works (the session row is deleted).
  3. 03Reuse a page's CSRF cookie from another origin and confirm the write is rejected with 403.
  4. 04Exceed the login rate limit and confirm a 429 with Retry-After.
  5. 05Create two accounts and confirm account B cannot see account A's progress, quiz scores, labs or certificate.
  6. 06Set COOKIE_SECURE=true behind HTTPS and confirm cookies are marked Secure and not sent over HTTP.
  7. 07Disable GEMINI_API_KEY (or break it) and confirm the tutor returns the labelled curriculum fallback instead of an error.
  8. 08Resize to a small mobile viewport and verify navigation, lesson pages, quiz inputs and the lab terminal.
  9. 09Run npx next typegen, tsc --noEmit and npm run build, then check /api/health returns status ok.
  10. 10Restore a database backup into a staging database and verify login plus progress reads work.

Curriculum coverage

100 lessons across 10 modules: cybersecurity foundations, networking essentials, protocols and traffic analysis, Linux fundamentals, Linux administration and hardening, Python for security, defensive Python projects, web technologies, web security, and professional security operations. Every lesson includes objectives, key terms, a worked example, a safe activity and a knowledge check.

Authorised practice only

The cybersecurity skills in this curriculum are powerful. Use them only on systems you own, or where you have explicit written permission and a defined scope. Unauthorised access is a criminal offence in many jurisdictions and causes real harm. The platform's labs are simulated so that you can build judgement without touching someone else's infrastructure.

Have a qualified adult or site administrator review privacy, child-safety, legal and hosting requirements before opening registration to the public.