# CarePulse IoT — Security controls and VAPT scope

Level 1 → **System health → Security self-check** runs the automated part of this list. A third-party VAPT (CERT-In empanelled
auditor recommended for hospital and government buyers) is still required before production.

## 1. Controls in place
| Area | Control |
|---|---|
| Tenant isolation | Separate database per hospital; central DB holds no patient data; tenant chosen by domain / session and API token prefix; DB passwords per client encrypted with `app_key` |
| Authentication | bcrypt passwords, account lockout (5 wrong → 15 min), per-IP login rate limit, TOTP 2-step mandatory for Level 1 and hospital admins (optional for all), 30-min idle timeout, session ID regenerated at login |
| Patient portal | OTP by WhatsApp / SMS, rate-limited per number and per IP, no passwords |
| API | Bearer tokens `cpg_<CLIENT>_<prefix><secret>` stored as SHA-256; revocable per gateway; 600 req/min per token; patient-app tokens limited to that patient |
| Web | CSRF token on every form; prepared SQL statements; output escaping; uploads type-checked (SVG scripts rejected) and stored outside the web root, served through access-checked controllers |
| Headers | Content-Security-Policy (`default-src 'self'`, `frame-ancestors 'self'`, `object-src 'none'`), X-Frame-Options, nosniff, Referrer-Policy, Permissions-Policy, HSTS on HTTPS, no X-Powered-By |
| Audit | Every login, view of sensitive pages, change, export, AI summary, support access → hospital audit log; Level 1 actions → platform audit |
| Privacy (DPDP 2023) | Consent captured with text and version; withdrawal stops monitoring and revokes app access; role-based access (biomed cannot see records); retention setting; AI summary sends de-identified facts only; AI dataset export is pseudonymous |
| Backups | Nightly encrypted (AES-256, PBKDF2) dumps + files, SHA-256 manifest, owner-only file permissions, off-site copy, weekly automated restore test |
| Monitoring | Worker heartbeat, disk, DB, queues, backups, error rate; e-mail / WhatsApp on failure and recovery; public `/api/v1/health` for uptime monitors (details only with a key) |
| Webhooks out | Escalation voice, ABDM bridge, door lockdown, own AI model: HTTPS + bearer keys set by the hospital |
| Mobile apps | HTTPS only (cleartext disabled), token in Android EncryptedSharedPreferences / iOS Keychain (this device only), no backup of app data, no ads / analytics SDKs |

## 2. Accepted risks (document in the VAPT report)
* CSP allows `'unsafe-inline'` scripts and styles (server-rendered pages with inline handlers). Mitigated by escaping all output and no third-party scripts. Plan: move to nonces.
* `frame-src https:` — needed for teleconsult providers chosen per hospital (CareMeet / Jitsi / link).
* Device Adapter API keys are long-lived; rotate per hospital annually or on staff change.

## 3. VAPT scope to give the auditor
1. Web: `https://app…/platform/*` (Level 1), hospital app (all roles — provide one login per role on the DEMO hospital), patient portal `/my/*`.
2. API: `/api/v1/*` — readings, waveforms, alarms, documents, doses, RTLS sightings, nurse calls, ADT, voice callbacks, lead form. Provide an API key and a patient-app token.
3. Multi-tenant tests: hospital A user / token must not read or write hospital B data (IDs, tokens, domains, session switching).
4. Mobile: Android AAB / APK and iOS TestFlight build — storage, transport, pairing flow.
5. Edge gateway (optional, on-site): Linux host, MLLP port 2575 and RTLS port exposure on the hospital LAN.
6. Infrastructure: server ports, TLS configuration, SSH.
Out of scope: third-party providers (SES, WhatsApp BSP, Exotel, ABDM gateway).

## 4. Before the auditor starts
- [ ] Self-check all green except items explained above
- [ ] `env = production`, real `app_key`, HTTPS, PHP ≥ 8.2, `display_errors` off
- [ ] Test data only on the VAPT server (DEMO hospital) — never real patients
- [ ] Rate limits left on (auditors may ask to raise them for scans — do it on the VAPT server only)

## 5. Incident response
1. Contain: revoke affected API keys / gateways, disable users, suspend the client (Level 1) if needed.
2. Preserve: copy `storage/logs`, audit tables and web server logs.
3. Notify: the hospital (data fiduciary) without delay; they notify the Data Protection Board and affected people as required under DPDP; CERT-In within 6 hours for reportable incidents.
4. Fix, test, and record the post-incident review.
