PRODUCTION READY DOCKER COMPOSE POSTGRESQL 16 SSRF HARDENED JEST CI

health-api

Hardened HTTP/HTTPS telemetry engine built for reliable endpoint health probing, latency profiling, and historical state persistence with strict RFC 1918 private network isolation.

Interactive API Explorer

LIVE SIMULATION
HTTP/1.1 CLIENT
Status: 200 OK
Latency: 18ms
Server: health-api/1.0

            

System Architecture

CORE PILLARS
SSRF Mitigation Engine

Guards against internal network scanning by resolving hostnames pre-flight and rejecting RFC 1918 addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, loopback 127.0.0.1, and link-local 169.254.169.254).

PostgreSQL Persistence

Normalized relational schema with foreign key constraints, connection pooling, and B-tree indexing on timestamps for zero-lag historical latency aggregation and SLA compliance calculations.

Containerized Isolation

Multi-stage Docker builds running under dedicated unprivileged non-root users. Uses explicit health checks and internal bridge networks to prevent unauthorized host-level socket exposure.

Automated CI Test Suite

Comprehensive integration and unit testing powered by Jest and Supertest. Every route, database query, and SSRF boundary is validated in automated GitHub Actions pipelines before merging.

Defense-in-Depth Implementation

SECURITY

Traditional URL monitors are prime targets for Server-Side Request Forgery (SSRF). health-api inspects resolved IP addresses before any socket connection is initiated:

// SSRF Validation Middleware: Resolves and checks against private ranges function validateTargetAddress(ip) { const isPrivate = ip.startsWith('127.') || // Loopback ip.startsWith('10.') || // RFC 1918 Class A ip.startsWith('192.168.') || // RFC 1918 Class C ip.startsWith('169.254.') || // Link-local / Cloud Metadata /^172\.(1[6-9]|2[0-9]|3[0-1])\./.test(ip); // RFC 1918 Class B if (isPrivate) { throw new Error('BLOCKED_SSRF_PROHIBITED_IP_TARGET'); } }

API Reference

REST ENDPOINTS
Method Endpoint Description Response
GET /health Internal system and database health probe 200 OK
GET /api/targets List all registered monitoring targets 200 OK
POST /api/targets Register new URL (with pre-flight SSRF validation) 201 Created
GET /api/targets/:id/telemetry Retrieve latency stats, uptime percentage & logs 200 OK

Deployment & Quickstart

DOCKER COMPOSE

Clone the repository and spin up both the API service and PostgreSQL database in an isolated Docker network:

# 1. Clone the repository git clone https://github.com/alirezajafarlou/health-api.git cd health-api # 2. Launch production stack in background docker compose up -d --build # 3. Verify health status curl http://localhost:3000/health # Output: {"status":"healthy","database":"connected","timestamp":"2026-11-16T14:30:00.000Z"}