This document outlines the comprehensive security measures, architectural boundaries, and best practices implemented across the ShegerHealth platform.
┌───────────────────────────────────────────────────────────────────────────┐
│ CLIENT / BROWSER │
│ (Secure HTTPS Transit / Vercel SSL / CORS Policy Enforced) │
└─────────────────────────────────────┬─────────────────────────────────────┘
│ Bearer JWT (24h Expiry)
▼
┌───────────────────────────────────────────────────────────────────────────┐
│ EXPRESS REST API SERVER │
│ │
│ ┌────────────────────────┐ ┌────────────────────────────┐ │
│ │ protect Middleware │────Valid───►│ authorize Middleware │ │
│ │ (Verifies JWT Secret) │ │ (Enforces RBAC Boundaries) │ │
│ └───────────┬────────────┘ └─────────────┬──────────────┘ │
│ │ Invalid │ Authorized │
│ ▼ ▼ │
│ [ 401 Unauthorized ] [ Controller Logic ] │
└────────────────────────────────────────────────────────┬──────────────────┘
│ Parameterized SQL
▼
┌───────────────────────────────────────────────────────────────────────────┐
│ SEQUELIZE ORM & MYSQL │
│ (Strict Data Typing / No Raw SQL / bcrypt Hashing) │
└───────────────────────────────────────────────────────────────────────────┘
ShegerHealth utilizes stateless, cryptographically signed JSON Web Tokens for user authentication.
- Tokens are generated upon successful login using
process.env.JWT_SECRET. - Each token encapsulates the user's
idandrole(Admin,Doctor,Patient). - Tokens are configured with a strict 24-hour expiration window to minimize the impact of token interception.
Every protected REST API endpoint passes through the protect asynchronous middleware:
- Extracts the token from the
Authorization: Bearer <token>header. - Cryptographically verifies the signature against the server's secret key.
- Retrieves the authenticated user from the database while explicitly stripping out sensitive credentials (
password_hash). - Rejects unauthorized requests immediately with a
401 Unauthorizedstatus code.
Granular route access is enforced via the authorize(...roles) middleware, establishing strict boundaries across the three user tiers:
- Admin Tier: Complete access to system logs, doctor onboarding, global patient management, and platform analytics.
- Doctor Tier: Access restricted to assigned appointments, patient medical histories, clinical messaging, and staff group chats.
- Patient Tier: Access restricted to personal appointment booking, AI triage consultation, and direct messaging with assigned physicians.
- Enforcement: Attempts to access higher-tier endpoints result in an immediate
403 Forbiddenresponse.
- Algorithm: Passwords are hashed using
bcryptjswith an industry-standard salt work factor. - Zero Plaintext Policy: Plaintext passwords are never stored in the database, logged to standard output, or exposed in debugging traces.
- Verification: Authentication relies entirely on constant-time hash comparison (
bcrypt.compare), mitigating timing attacks.
To prevent data leakage, all API responses returning user profiles or lists automatically sanitize the payload. Attributes such as password_hash, resetPasswordToken, and resetPasswordExpire are explicitly excluded at the ORM query level (attributes: { exclude: [...] }).
All client-server communications operate exclusively over HTTPS. Vercel (Frontend) and Render (Backend) provide automated SSL/TLS termination, ensuring all data in transit—including JWTs, patient medical records, and private chat messages—is fully encrypted.
All database operations are managed through the Sequelize Object-Relational Mapper (ORM).
- Parameterized Queries: Sequelize automatically uses parameterized queries and prepared statements for all
findAll,findOne,create,update, anddestroyoperations. - No Raw SQL: The application avoids raw SQL queries (
sequelize.query), completely neutralizing SQL injection (SQLi) vulnerabilities.
The MySQL database tables enforce rigorous validation rules at the engine level:
- Strict
VARCHARlength boundaries (e.g.,username: STRING(50)). allowNull: falseconstraints on critical fields to maintain data integrity.unique: trueindices onusernameandemailto prevent account duplication and race conditions.
The Express server enforces a strict CORS policy, permitting HTTP requests only from explicitly authorized origins:
https://sheger-health-connect.vercel.app(Live Production Frontend)http://localhost:5173/http://localhost:3000(Local Development Environments)- Protection: Prevents malicious websites from executing unauthorized cross-site requests (CSRF/XSS) against the backend API.
- Error Handling: Custom Express error middleware intercepts all asynchronous exceptions. In production mode, stack traces are suppressed, returning clean, generic error messages to prevent internal system layout leakage.
Real-time bi-directional messaging is isolated using Socket.io rooms:
- Users are assigned to private rooms corresponding to their unique user ID (
user_${id}) and appointment IDs (appointment_${id}). - Socket event listeners validate user identity before broadcasting messages, preventing cross-tenant chat leakage.
To maintain a high-trust clinical environment, public self-registration for Doctors and Administrators is disabled.
- New medical professionals can only be provisioned by an existing, fully authenticated Administrator via the protected
/api/admins/doctorsendpoint. - This prevents fraudulent practitioner accounts from entering the specialist directory.
- Time-Bound Tokens: Password reset requests generate a secure, randomized token (
resetPasswordToken) valid for a strictly limited duration (resetPasswordExpire). - Validation: Reset endpoints verify both token authenticity and expiration before allowing password mutation.
Client-side logout routines immediately purge the JWT from local storage. To protect against accidental session termination or tampering, the frontend incorporates a secure confirmation modal prior to executing the logout sequence.
ShegerHealth · Enterprise Security Architecture