4. Code review findings
The authentication and session basics are well built; the gaps are in accountability, data-subject tooling and secret handling. Controls found in the code:
| Area | What the code does | Source |
|---|---|---|
| Password storage | scrypt (N=16384, r=8, p=1), 16-byte random salt, constant-time compare; unknown users cost the same time as known ones | lib/auth.js |
| Brute force | Account locks for 5 minutes after 5 failures; 20 login requests a minute per client address | lib/auth.js, server.js |
| Sessions | 32-byte random token, only its SHA-256 stored; 12-hour expiry extended on use; deleted on logout, on password change and when a user is deactivated | lib/auth.js |
| Cookie | HttpOnly, SameSite=Strict, Secure when served over HTTPS or when COOKIE_SECURE=1 | server.js |
| Cross-site requests | Sec-Fetch-Site and Origin checks reject cross-site writes | server.js |
| Authorisation | Per data source, per application feature and per FHIR® resource type; every Viewer and genome call checks it | lib/access.js, lib/genomics.js |
| Stored documents | Served with nosniff and a sandbox policy so uploaded HTML or SVG cannot run scripts | lib/documents.js |
| Responses | Cache-Control: no-store on API calls; no third-party scripts or CDNs in the pages | server.js |
| Genome lookups | Server-side only; send gene symbols, accessions and HGVS text, never patient data or sequences; 24-hour cache; admin switch | lib/genomeinfo.js |
| Sample data | Synthetic patients; genome variants are published biology, not real people | sample-data/ |
What is missing or weak (details and ratings in section 8):
Accountability. The only logging is
console.logandconsole.errorfor start-up, factory reset and failures. Reads of patient records, exports, login successes and failures, permission changes and user deletions leave no durable record (G1, G17).Sign-in. One factor only; the minimum password is 8 characters with no complexity or breach check; a default
admin/passwordaccount is created on first start and only a warning is shown (G2). scrypt cost is below current OWASP guidance (G10).Secrets. Data-source connection strings, including passwords, are stored as plain text in
auth.vault(G5).Rights and retention. No function finds all data for one person, exports it, corrects it or hard-deletes it; the vault stores history with
load_end_dtsandis_deletedflags (G3). There is no retention schedule (G4).Sessions. The 12-hour window slides on every use, so a workstation left open never times out (G7).
Granularity. Access stops at the resource type; there is no per-patient restriction, field masking or emergency-access ("break-glass") path (G8).
Throttle. The limiter keys on the socket address, so behind a reverse proxy every user shares one bucket, and its map is never pruned (G9).
Transport and headers. The server speaks plain HTTP and has no HSTS or Content-Security-Policy on its own pages (G6, G11).
Outbound lookups. Genome lookups are on by default and contact US and EU hosts (G12).