# Security Design

> **Status:** sections 1–5, 6 (validation for Phase 1 routes), 8 (login, forgot, setup and general limits), 10 (activity log, login history and deletion-audit writers), 11 (safeguard service, used for staff deletion), 13 and 14 are **IMPLEMENTED and tested in Phase 1**. Phase 2 added: uploads (§7: signature check, 5 MB, server-side storage, 503 without Cloudinary), the public inquiry rate limit (§8) and safeguarded deletion of inquiries, gallery images and trainer cards (§11). Phase 3 added member permissions enforced on the server (Admin-only notes, conversion, opt-out/consent, photo removal and deletion; Trainer archive/restore per C-38), field-name-only logging of member edits (D-62) and safeguarded member-photo removal and member deletion with the dependency block (§11, D-87). Phase 4 added the membership permissions on the server (Admin-only custom price with a mandatory logged reason, upcoming expiries and membership deletion; Admin and Trainer create and activate), the overpayment and future-date guards for the initial payment, and the dependency-blocked membership deletion. Phase 5 added the payment permissions on the server (Admin and Trainer record, verify, reject and correct entries; Admin-only ledger, total-due correction and deletions), mandatory reasons with the immutable correction log, version checks against duplicate or stale submissions, and receipt PDFs that fetch no external resources. Phase 6 added the exercise and workout-note permissions on the server: Trainers edit and soft-delete only their own notes (ownership checked in the service, `403 NOT_NOTE_AUTHOR`), Admins any; deleted notes are invisible to Trainers (`404`; the deleted filter needs `notes.viewDeleted`); notes on archived members are read-only; note text is never written to the activity log (D-62); and the Trainer-only dashboard returns counts without amounts. Phase 7 implemented WhatsApp (§9): template management Admin-only, sends template-only with server-resolved values, consent/opt-out/archive/mobile-number checks at queue and at send, Trainer history limited to their own messages, signed webhooks, credentials only in environment variables (tested with a fake provider and the simulated mode only). Phase 8 added the expense, report and export permissions on the server (all Admin-only; Trainers get 403 on every route, covered by the route-access test), the password re-entry for the full personal-data export (wrong password → 422, nothing exported), Activity Log entries for every report download and export without personal data (D-128), validated report filters, and safeguarded expense deletion. Phase 9 resolved X-21 by keeping protected history undeletable at the model level (D-131), added the Admin-only audit viewers and backup status with no restore route (D-132, D-133), `Cache-Control: no-store` on API responses, backup secrets in log redaction and a dependency audit with 0 known vulnerabilities (D-134). Phase 9 Revision 1 made a failed restore identifiable and safely resumable without deleting anything (§13.1, D-136). Phase 10 added the final audit (§17). Hosting (§15) is prepared but **not deployed**.
> Baseline: SRS §3.1, §11, §12, §15.1, §17 and Master Prompt §6 and §17. Decision IDs refer to `docs/DECISIONS.md`.

## 1. Principles

1. **Server-side enforcement only.** Every permission, validation and business rule is checked in the API. The UI only _hides_ what a role cannot do (Prompt §6).
2. **Deny by default.** Every route declares a permission key. Routes without one fail a startup check, except routes explicitly marked public.
3. **No silent overwrite of history.** Financial and consent history are append-only, and deletions are explicit and audited (SRS §1.1).
4. **Least data.** Logs and audits store no more personal data than they need (D-62).
5. **Secrets never in code.** Environment variables or a secret manager only (SRS §11.3).

## 2. Authentication

### 2.1 Accounts and identity

- Only Admin and Trainer accounts can log in. Members have no accounts (C-01).
- Unique username. Email is required for Admins and optional for Trainers. Login accepts either the username or the email (D-08).
- **First Admin** (C-30, D-11): the operator runs `node server/scripts/create-setup-token.js`, which prints a single-use token valid for 24 hours, and only its hash is stored. `POST /auth/setup` with the token creates the first Admin, using the identity and password that person chooses. Setup is then permanently disabled (the endpoint returns 410). There are no default credentials.

### 2.2 Passwords (C-28, X-01)

- At least **12 characters** and at most 128. Rejected if it is on the bundled common-password list, or if it contains the username, the email local part or the gym name (D-05).
- Hashed with **argon2id** using OWASP-recommended parameters (D-04). The hash is never returned by any endpoint.
- **Trainers cannot change their own password.** An Admin sets a new password for them (`POST /users/:id/reset-password`). That revokes all the Trainer's sessions and is logged.
- **An Admin changes their own password** by giving the current password (C-28, D-10). Their other sessions are revoked.
- **Email reset, Admin accounts only** (D-07): single-use token, 30-minute expiry, stored as a hash, always the same response so the existence of an account is never revealed. A successful reset revokes all sessions.

### 2.3 Failed-login protection (C-29, X-02, D-06)

- **Progressive delay**, per account and per IP. From the 3rd consecutive failure the server waits 1s, then 2s, 4s, 8s, 16s, capped at 30s, before replying. The count resets on success. **There is no permanent lockout.**
- A per-IP cap on `/auth/login` of about 30 requests per 15 minutes, answered with 429 and `Retry-After`. It is temporary.
- A generic error message in every case. The real reason is recorded in login history (D-12).
- **2FA is not part of the first release** (C-29, X-03).

## 3. Sessions (C-27, D-01, D-02)

| Property                       | Design                                                                                                                                               |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| Token                          | 256-bit random value. The cookie holds the raw token and the database holds only its SHA-256 hash                                                    |
| Cookie                         | `gms_session`; `HttpOnly`; `Secure` (staging and production); `SameSite=Lax`; `Path=/`; no `Domain` attribute (host-only)                            |
| Origin                         | Same origin through the Vercel `/api` rewrite, so the cookie is first-party on iOS Safari                                                            |
| Lifetime                       | Sliding: `expiresAt = lastSeenAt + 90 days`, with a TTL index removing expired sessions                                                              |
| Rotation                       | A new token every 24 hours. The previous hash stays valid for about 60 seconds to allow requests already in flight                                   |
| Multi-device                   | Allowed. Each device has its own session record                                                                                                      |
| Logout                         | Revokes the current session and clears the cookie                                                                                                    |
| Force logout (Admin → Trainer) | Revokes all of that Trainer's sessions. Takes effect on their next request                                                                           |
| Deactivation                   | Revokes all sessions **in the same transaction**. `authenticate` also checks `user.status === "active"` on every request, so access ends immediately |
| Password change or reset       | Revokes the other sessions, or all sessions after a reset                                                                                            |
| No session-management screen   | As in the SRS. Force logout is the only remote control                                                                                               |

## 4. Authorization

### 4.1 Mechanism

- `server/src/permissions/matrix.js` holds the **single source of truth**: a list of permission keys, each mapped to roles.
- `authorize(key)` middleware checks the role. **Ownership** checks, such as "own note" or "own notifications", are done in the service, because they need the record.
- The client receives the list of permissions from `GET /auth/me` and uses it only to show or hide UI.
- Integration tests call every Admin-only endpoint with a Trainer session and expect **403** (see `docs/TESTING.md`).

### 4.2 Permission matrix (SRS §3.1, applied with X- and D- entries)

| Permission key                                          | Admin | Trainer | Notes                                                                                          |
| ------------------------------------------------------- | :---: | :-----: | ---------------------------------------------------------------------------------------------- |
| `dashboard.admin`                                       |   ✓   |    —    | Includes the upcoming-expiry widget (C-20)                                                     |
| `dashboard.trainer`                                     |   —   |    ✓    | No upcoming-expiry widget and no money totals (D-44)                                           |
| `members.read`                                          |   ✓   |    ✓    | Archived members are listed only with the archived filter                                      |
| `members.create` / `members.update`                     |   ✓   |    ✓    | Personal details                                                                               |
| `members.adminNotes.edit`                               |   ✓   |    —    | Trainers can view the notes read-only (D-22)                                                   |
| `members.archive`                                       |   ✓   |    ✓    | Blocked while a membership is active (C-06)                                                    |
| `members.restore`                                       |   ✓   |    ✓    | Confirmed by the user (X-16 resolved, C-38; SRS §3.1 and §5.2)                                 |
| `members.photo.upload`                                  |   ✓   |    ✓    | Upload or replace (C-08)                                                                       |
| `members.photo.remove`                                  |   ✓   |    —    | Permanent removal, with safeguards                                                             |
| `members.consent.record`                                |   ✓   |    ✓    | At registration only (D-20)                                                                    |
| `members.consent.optOut` / `members.consent.restore`    |   ✓   |    —    | C-25, D-20                                                                                     |
| `members.delete`                                        |   ✓   |    —    | Safeguards + dependency block (C-33). X-21 resolved by D-131: the block stays, archive instead |
| `members.export.full`                                   |   ✓   |    —    | Password confirmation and logged (C-21)                                                        |
| `inquiries.manage`                                      |   ✓   |    —    | List, view, status, convert, delete (C-04)                                                     |
| `plans.read`                                            |   ✓   |    ✓    | Needed to choose a plan when renewing                                                          |
| `plans.manage`                                          |   ✓   |    —    | Create, edit, price, activate/deactivate (C-09)                                                |
| `memberships.create` / `memberships.activate`           |   ✓   |    ✓    | C-10, C-11                                                                                     |
| `memberships.customPrice`                               |   ✓   |    —    | Reason required and logged (C-09)                                                              |
| `memberships.upcomingExpiries`                          |   ✓   |    —    | C-20                                                                                           |
| `memberships.delete`                                    |   ✓   |    —    | Safeguards                                                                                     |
| `payments.read.member`                                  |   ✓   |    ✓    | Full payment history and balance of a member                                                   |
| `payments.read.all`                                     |   ✓   |    —    | The ledger-wide list                                                                           |
| `payments.record` / `payments.verify`                   |   ✓   |    ✓    | C-15                                                                                           |
| `payments.correct.entry`                                |   ✓   |    ✓    | Reason required (C-15)                                                                         |
| `payments.correct.total`                                |   ✓   |    —    | D-34                                                                                           |
| `payments.delete`                                       |   ✓   |    —    | Summary or entry, with safeguards (C-17)                                                       |
| `receipts.read` / `receipts.share`                      |   ✓   |    ✓    | Sharing depends on consent (C-16, X-06)                                                        |
| `receipts.delete`                                       |   ✓   |    —    | Safeguards                                                                                     |
| `exercises.read` / `.create` / `.update`                |   ✓   |    ✓    | C-18                                                                                           |
| `notes.read` / `notes.create`                           |   ✓   |    ✓    | C-19                                                                                           |
| `notes.update` / `notes.delete`                         | ✓ any |  ✓ own  | Soft delete. Ownership checked in the service                                                  |
| `notes.viewDeleted`                                     |   ✓   |    —    | D-40                                                                                           |
| `templates.read`                                        |   ✓   |    ✓    |                                                                                                |
| `templates.manage`                                      |   ✓   |    —    | Create, edit, delete (C-23, X-05)                                                              |
| `whatsapp.send`                                         |   ✓   |    ✓    | Approved templates only, with the consent guard                                                |
| `notifications.read.all`                                |   ✓   |    —    |                                                                                                |
| `notifications.read.own`                                |   —   |    ✓    | The filter `sentBy = me` is applied in the service (C-26)                                      |
| `notifications.followUp`                                |   ✓   |    —    | Mark followed up                                                                               |
| `expenses.manage`                                       |   ✓   |    —    | D-41                                                                                           |
| `reports.view`                                          |   ✓   |    —    | PDF reports (C-21)                                                                             |
| `users.manage`                                          |   ✓   |    —    | Create, edit, deactivate, reactivate, delete (D-09)                                            |
| `users.resetPassword` / `users.forceLogout`             |   ✓   |    —    | Trainer targets (C-27)                                                                         |
| `settings.manage` / `content.manage` / `gallery.manage` |   ✓   |    —    |                                                                                                |
| `audit.activity.read` / `audit.logins.read`             |   ✓   |    —    |                                                                                                |
| `backups.status.read`                                   |   ✓   |    —    | No restore over HTTP (C-35)                                                                    |
| `profile.self`                                          |   ✓   |    ✓    | Limited fields for Trainers (D-14)                                                             |
| `password.changeSelf`                                   |   ✓   |    —    | C-27                                                                                           |

## 5. CSRF, CORS and headers (D-03)

- Cookies are SameSite=Lax. **Every non-GET request** must carry an `Origin` (or `Referer`) header that matches the allowed app origin, otherwise it gets 403. The WhatsApp webhook is exempt, because it is verified by its signature instead.
- JSON bodies only (`Content-Type: application/json`), except `multipart/form-data` on upload routes.
- CORS: an explicit allow-list. In production it holds only the Vercel origin and, later, the custom domain. Credentials are allowed only for those origins.
- `helmet`: HSTS (production), `X-Content-Type-Options`, `Referrer-Policy: strict-origin-when-cross-origin` and `frame-ancestors 'none'`. The Content Security Policy is set on Vercel for the SPA (self, Cloudinary images and fonts).

## 6. Input validation and output handling

- **A Zod schema for every request** (body, params, query), validated in the server middleware. The client uses matching schemas only to give feedback in forms (C-34, Prompt §18).
- IDs are validated as ObjectIds or by their business-ID pattern. Unknown fields are rejected. Strings are trimmed and length-limited.
- Search input is regex-escaped. Mongo operator injection is prevented because Zod validates every value's type, and keys starting with `$` are stripped.
- Money values must be integers. Dates must be real `YYYY-MM-DD` dates. Future payment dates are rejected.
- React escapes output by default. There is no `dangerouslySetInnerHTML`; long admin-entered content is rendered as plain text with line breaks.
- PDFs are built from data, not HTML, so there is no injection surface.

## 7. File uploads

- `multer` memory storage, **5 MB** maximum, a single file. Allowed types are JPEG, PNG and WebP, checked against the file signature and not just the extension.
- Uploaded straight to Cloudinary under `gym/<env>/<kind>/` with server-generated public IDs. Clients never sign uploads.
- Old assets are removed only after the database commit. Failures go to `assetCleanups` (C-08).

## 8. Rate limiting

| Endpoint                     | Limit (initial values, configurable)                                                                                                                             |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `POST /public/inquiries`     | 5 per IP per hour (C-04)                                                                                                                                         |
| `POST /auth/login`           | Progressive delay + about 30 per IP per 15 minutes (D-06)                                                                                                        |
| `POST /auth/password/forgot` | 5 per IP per hour                                                                                                                                                |
| `POST /auth/setup`           | 10 per IP per hour                                                                                                                                               |
| Authenticated API            | 600 per IP per 15 minutes (safety net; keyed by IP in Phase 1). `API_RATE_LIMIT` can raise it (never below 600); only the automated browser suite sets it (D-93) |

Render sits behind a proxy, so Express `trust proxy` is set to the single hop for correct client IPs.

## 9. WhatsApp-specific controls

- Webhooks are verified with HMAC-SHA256 (`X-Hub-Signature-256`, app secret), and requests that fail are rejected. The GET verification handshake uses a configured verify token (D-50).
- Consent, opt-out and archive guards run at enqueue **and** at dispatch, so background jobs cannot bypass them (C-25, D-46).
- No free-text messages: the send API accepts only a template ID, and all variable values are taken from data on the server (C-23).
- The access token and app secret exist only in environment variables and are never logged (logger redaction) or returned (the status endpoint reports only whether each is set).
- **Implemented (Phase 7):** the signature is computed over the raw request bytes and compared in constant time; unsigned or wrongly signed webhooks get 401; without an app secret the webhook answers 503. The webhook is exempt from the browser Origin check (it is signed instead) and mounted before the general rate limit. Direct API calls cannot skip consent: manual sends and receipt sharing are refused with 409/422 for opted-out, non-consenting, archived or landline members, and the dispatcher checks again before every send (D-119). Trainers see only messages they sent (C-26). Notification history cannot be deleted.

## 10. Audit

### 10.1 Activity log (SRS §11.7, Prompt §17)

These actions are logged, each with the actor, target, a reason where required, the changed fields (D-62) and a request ID:

- Member create, update, archive, restore, photo upload/replace/remove, delete
- Inquiry status change, conversion, delete
- Plan create, update, price change, activate/deactivate
- Membership create, custom price, activate, renewal, delete. The automatic expire/promote steps are logged as the `system` actor
- Payment entry record, verify, reject, correct; total-due correction; payment, entry or receipt delete
- Receipt share (WhatsApp or manual)
- Template create, update, delete; WhatsApp manual send
- Consent recorded, opt-out, consent restored
- User create, update, deactivate, reactivate, password reset, force logout, delete; own password change
- Settings, content, gallery and public trainer changes
- Expense create, update, delete
- Report generation, member list export, **full personal-data export**
- First-Admin setup

### 10.2 Login history

Every attempt is recorded with its result and reason, IP hash and user agent. Kept 2 years. Admin-only view (C-32).

### 10.3 Deletion audit

A permanent minimal record of `actorId`, `at`, `recordType` and `reason`, with **no personal data** (C-32, C-33).

## 11. Permanent deletion safeguards (C-33, D-56)

Every permanent deletion, with no exceptions:

1. `GET …/dependencies` → the UI lists linked records and the consequences.
2. A second confirmation dialog naming the record type and what will happen.
3. **Admin password re-entry** (verified on the server).
4. **A mandatory reason** (5–500 characters).
5. Server-side dependency check inside the transaction. Any protected dependency → 409 and nothing is deleted.
6. A deletion-audit record and an activity-log entry, both without personal data.
7. **No cascades.** Linked records must be handled separately (see `docs/DATABASE.md` §7). X-21 is resolved by D-131: protected history is never deleted, so a member with history is archived instead; nothing is cascaded, anonymised or detached.

Workout notes are soft-deleted only. Restoring a database backup is not possible through the app (C-35).

## 12. Sensitive exports

- The full member personal-data export is PDF only and Admin only, needs password re-entry, and is logged with the filters used (C-21).
- The member list export (PDF) is Admin only and logged. Archived members are included only when the filter is selected.
- Exports are streamed, never stored on the server, and sent with `Cache-Control: no-store`.

## 13. Secrets and configuration

- `server/src/config/env.js` validates every variable at start-up with Zod. In staging or production, the server refuses to start if any secret is missing.
- Committed `.env.example` files hold variable names only. `.gitignore` excludes `.env*` except the examples.
- Never committed and never documented with values: MongoDB URIs, session or cookie secrets, the IP-hash salt, Cloudinary keys, the Meta access token, the app secret and verify token, SMTP credentials, backup storage keys, and the backup encryption key (Prompt §23).

### 13.1 Backups and restore (D-132, D-136)

- Backups are encrypted (AES-256-GCM, authenticated header); the key exists only in the server's secret environment and an offline copy. Restore has **no HTTP route**: only the operator script, with a typed confirmation equal to the target database name.
- The whole backup is validated before anything is written (checksum, decryption, manifest, every document, counts). `--check` validates without writing.
- A restore writes only into an empty database, marks it first (`restoreState`), and on failure leaves it **marked as partial**. The server and all operator scripts refuse a partial database before writing anything to it.
- Recovery never deletes: `--resume` continues only when every document already present is exactly the same backup's data; changed, extra or unknown data, another backup file, or a concurrent run is refused with nothing written. A database that no restore marked is never written to.

## 14. Logging

- `pino` with redaction of `req.headers.cookie`, `authorization`, `password*`, `token*` and `*.secret`, and phone numbers masked to the last 4 digits.
- In production, error responses carry only `code`, `message` and `requestId`. Stack traces stay in server logs.

## 15. Transport and hosting

- HTTPS everywhere outside local development. HSTS in production.
- The database user has the least privilege needed (`readWrite` on the app database only). Atlas IP access list: Render outbound IPs where the plan allows; otherwise strong credentials with TLS (to confirm at deployment).

## 16. Known security trade-offs (approved requirements)

- No 2FA in the first release (C-29).
- Weekly backups mean up to 7 days of data could be lost in a disaster (C-35). This is noted in `docs/BACKUP_RESTORE.md`.
- Behind Vercel and Render the client address depends on `TRUST_PROXY` (2 expected); a wrong value would group all visitors under one IP for rate limits and login records. It must be checked on staging (`docs/DEPLOYMENT.md` §8).

## 17. Final security audit (Phase 10, 20 Nov 2026)

Each item was checked by running code (tests or a production-mode start), not only by reading. "Not verifiable here" items need the real hosting or accounts.

| Area                           | Result  | Evidence                                                                                                                                                                                                                  |
| ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Authentication                 | ✅      | Generic login errors, progressive delay without lockout, argon2id, 12+ characters with common-password and username/email checks, setup token single-use and closed after the first Admin (re-checked in production mode) |
| Admin/Trainer separation       | ✅      | Every route declares a permission; the route-access test covers all 139 routes; Trainer 403 on all Admin routes; the final journey test repeats the key ones                                                              |
| Sessions                       | ✅      | Opaque token, only its hash stored; `HttpOnly; Secure; SameSite=Lax` cookie in production (observed); 90-day idle expiry, 24 h rotation; deactivation, force logout, reset and deletion end sessions on the next request  |
| Passwords                      | ✅      | Trainers cannot change their own; Admin change and email reset revoke other sessions; reset links single-use, 30 min, hashed                                                                                              |
| CSRF                           | ✅      | Origin check on every state-changing request (foreign origin → 403, observed in production mode), JSON-only bodies (`text/plain` → 415), SameSite cookie                                                                  |
| CORS                           | ✅      | Only `APP_ORIGIN` gets `Access-Control-Allow-Origin` with credentials; a foreign preflight gets none (observed)                                                                                                           |
| Rate limiting                  | ✅ / ⚠️ | Login, forgot-password, setup, public inquiry and general API limits tested; correct client IPs behind Vercel + Render depend on `TRUST_PROXY` (to verify on staging)                                                     |
| Input validation               | ✅      | Zod `strict` schemas on bodies and queries; Express 5 query parsing cannot build database operators; malformed JSON → 400                                                                                                 |
| Sensitive data exposure        | ✅      | No password hashes, token hashes, IP hashes or configured secrets in Admin responses (tested); `Cache-Control: no-store` on the API; personal values never in the Activity Log                                            |
| Secrets and configuration      | ✅      | Only in environment variables; the server refuses to start without required secrets or with unsafe modes (mock WhatsApp, local backups in production; observed); `.env.example` names only; ZIP scanned for keys          |
| MongoDB                        | ✅ / ⚠️ | Replica-set transactions for multi-record changes, unique and TTL indexes synced at start-up, protected history undeletable; Atlas user rights and network access are deployment steps (`docs/DEPLOYMENT.md` §4.1)        |
| File uploads                   | ✅      | JPEG/PNG/WebP checked by file signature, 5 MB limit, server-side signed upload; disabled without Cloudinary (real Cloudinary untested, P-05)                                                                              |
| WhatsApp webhooks              | ✅      | HMAC signature over the raw body with constant-time comparison; unsigned calls refused; verify token for subscription (tested with test-signed payloads; real Meta untested, P-06)                                        |
| Consent and opt-out            | ✅      | Checked when queued and again before sending; direct API requests refused; history never deleted                                                                                                                          |
| Audit logs                     | ✅      | Activity Log, Login History (2 years), permanent deletion audit; all immutable and undeletable at the model level                                                                                                         |
| Protected history              | ✅      | Consent, messages, notes, corrections and audit records cannot be deleted by any route or model; the 13 deletion routes are pinned by a test (D-131)                                                                      |
| Backup encryption              | ✅      | AES-256-GCM with an authenticated header; tampering and wrong keys detected; key only in the environment (real bucket untested, P-08)                                                                                     |
| Restore integrity and recovery | ✅      | Full validation before writing, typed confirmation, empty target only, marker, verified resume, start-up guard (D-136)                                                                                                    |
| Security headers               | ✅      | API: HSTS, nosniff, frame and referrer policies, no `x-powered-by` (observed). App: strict CSP from `vercel.json` with **no violations** on the built app (tested in a browser)                                           |
| Error handling                 | ✅      | Generic 500 messages with a request ID; no stack traces or internals (tested)                                                                                                                                             |
| Dependencies                   | ✅      | `npm audit`: 0 vulnerabilities; production-only install verified                                                                                                                                                          |
| Accessibility (related)        | ✅      | axe-core WCAG 2 A/AA: no serious or critical issues on 13 screens in both themes and 4 Urdu screens                                                                                                                       |

**Fixed during the audit:** the Zod library's speed probe (`new Function`) triggered a CSP violation on every page with a form under the production policy; it is now switched off (`client/src/lib/zodConfig.js`, D-137).

**Not verifiable in this environment:** real HTTPS/HSTS on Vercel and Render, Atlas network rules, real client IPs behind the proxies, and the real Cloudinary, SMTP, Meta and storage services.
