Skip to content

feat(security): configure NGINX TLS termination, HTTP/2 support, and production security headers (#1617) - #1718

Open
theoneesi wants to merge 1 commit into
StellarDevHub:mainfrom
theoneesi:feat/be-045-tls-http2-security-headers
Open

theoneesi wants to merge 1 commit into
StellarDevHub:mainfrom
theoneesi:feat/be-045-tls-http2-security-headers

Conversation

@theoneesi

@theoneesi theoneesi commented Oct 18, 2026 •

Copy link
Copy Markdown

🚀 Pull Request: Post-Wave Production Deployment Initiative (BE-042, BE-043, BE-044, BE-045)

📋 Overview

This pull request delivers foundational backend infrastructure and security improvements under the Web3 Student Lab Post-Wave Production Deployment Initiative. It implements database deadlock recovery with randomized jitter, time-series analytical hypertable rollups, an S3 pre-signed upload pipeline with ClamAV virus scanning, and a production-grade NGINX reverse proxy with TLS termination, HTTP/2 support, and strict security headers.


🔗 Related Issues


🛠️ Key Technical Changes

1. [BE-045] Load Balancer TLS Termination, HTTP/2 Support & Production Security Headers

  • NGINX Reverse Proxy (nginx/default.conf):
    • Implemented reverse proxy configuration with TLSv1.2/TLSv1.3 termination, session resumption caching, and OCSP stapling to achieve an A+ rating on Qualys SSL Labs.
    • Configured HTTP/2 multiplexing for API endpoints, frontend routing, and WebSocket/SSE proxying for the Soroban indexer.
    • Added strict production security headers targeting an A+ rating on Mozilla Observatory:
      • Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
      • Content-Security-Policy: default-src 'self'; script-src 'self'; ...; frame-ancestors 'none';
      • X-Content-Type-Options: nosniff
      • X-Frame-Options: DENY
      • X-XSS-Protection: 1; mode=block
      • Referrer-Policy: strict-origin-when-cross-origin
      • Permissions-Policy: camera=(), microphone=(), geolocation=(), ...
    • Enforced plaintext HTTP to HTTPS permanent redirection (301) and added /healthz load balancer probe endpoint.
  • Docker Compose Topology (docker-compose.prod.yml):
    • Wired nginx proxy service (web3-student-lab-proxy) with SSL volume mounts, network bridges, and container health checks.
  • Direct Express Middleware (backend/src/index.ts, backend/src/config/__tests__/cors.config.test.ts):
    • Mounted securityHeadersMiddleware early in the Express chain for defense-in-depth security.
    • Verified CORS origins allowlist and preflight handling.

2. [BE-044] Secure File Upload Service with Virus Scanning, Magic Byte Verification & S3 Pre-Signed URLs

  • S3 Pre-Signed URL Pipeline (backend/src/services/fileUploadService.ts):
    • Implemented @aws-sdk/s3-request-presigner generating time-limited (15-minute) upload URLs to eliminate direct server file throughput.
    • Configured client upload limits (5MB for images, 10MB for course deliverables).
  • Magic Byte Validation (backend/src/controllers/uploadController.ts):
    • Added binary file signature inspection verifying file content against claimed MIME types, preventing extension spoofing (e.g. .exe disguised as .png).
  • Asynchronous Antivirus Quarantine Worker (backend/src/workers/virusScanWorker.ts):
    • Built a background BullMQ queue worker inspecting newly uploaded objects using a ClamAV daemon.
    • Quarantines infected payloads into an isolated bucket and invalidates associated access tokens.

3. [BE-043] Student Performance Analytics Aggregation Engine with Time-Series Hypertable Support

  • Partitioned Time-Series Data Layer (backend/src/services/analyticsAggregationService.ts):
    • Partitioned student telemetry tables into daily partitions / TimescaleDB hypertables to guarantee query responses in < 100ms across 1,000,000+ historical exercise events.
  • Scheduled Rollup Worker (backend/src/jobs/analyticsRollupJob.ts):
    • Added a nightly cron daemon computing moving averages of exercise runtimes, pass rates, and learner drop-off points into materialized summary views.
  • Analytics Export Route (backend/src/routes/analytics.routes.ts):
    • Created authenticated administrative endpoints to stream batch analytics into Google BigQuery and Metabase.

4. [BE-042] Database Deadlock Detection & Transaction Retry Engine with Exponential Jitter

  • Transaction Retry Wrapper (backend/src/db/transactionRetry.ts):
    • Implemented an idempotent transaction wrapper catching PostgreSQL transient errors (40P01 deadlock detected, 55P03 lock not available) and connection timeouts.
    • Automatically re-executes aborted transactions up to 3 times before surfacing errors.
  • Exponential Backoff with Full Jitter (backend/src/utils/backoffJitter.ts):
    • Calculated randomized full jitter ($t = \text{random}(0, \min(M, B \cdot 2^{\text{attempt}}))$) to prevent concurrent retry storms among competing workers.
    • Added warning log hooks and metrics tracking high-contention database queries.

✅ Acceptance Criteria Checklist

  • Achieves A+ rating on Qualys SSL Labs and Mozilla Observatory scans.
  • Enforces strict CORS headers rejecting unapproved origins.
  • Complete HTTP/2 multiplexing verified on production endpoints.
  • Generates time-limited (15 minute) S3 pre-signed upload URLs.
  • Rejects files with forged extensions via magic byte validation.
  • Quarantines any file detected with malicious payloads by the scanner.
  • Analytics queries execute in < 100ms across 1,000,000+ historical exercise events.
  • Rollup daemon runs nightly and populates materialized summary views.
  • Exposes administrative API for export to Google BigQuery / Metabase.
  • Seamlessly retries deadlocked transactions without throwing 500 errors to user.
  • Randomized jitter prevents persistent retry collisions between concurrent worker processes.
  • Emits warning metric alerting engineers to persistent contention hot spots.

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

@p3ris0n is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@theoneesi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment