Security and example data
The controls the repositories implement, the ones they do not, and the rules for examples in this handbook.
This page is for engineers writing code, docs, and fixtures. It is not a legal review of Uganda’s data-protection law or of school policy. If a control is not in the source cited here, this page does not claim it.
Data classes
The repositories do not define a formal classification scheme (no shared enum of public, internal, and pupil data was found). Treat the following as the working rule until one exists in code:
| Class | Examples | In docs, tickets, and local dumps |
|---|---|---|
| Public marketing copy | Text an editor published on the website | Fine to quote in a handbook if it is already public |
| Internal engineering | Routes, config key names, fictional fixtures | Fine |
| School operational data | Staff lists, grades, payments, medical notes, guardians, admission files | Never in git, chat logs, screenshots, or this handbook |
| Credentials | JWT secrets, API keys, database URLs, webhook secrets | Never. Placeholders only |
There is no retention period for pupil, guardian, or staff profile rows in the job this pass read. Do not invent one.
RecordsRetentionService.run deletes rows from audit_log and notification whose created_at is older than 365 days. It deletes in batches of 5,000 and stops a table after 20 batches in one run (100,000 rows). If it hits that cap it logs Records retention hit its per-run batch cap and returns. It does not touch student or user tables.
CronJob.RecordsRetention is the scheduler id records-retention. CRON_RECORDS_RETENTION defaults to 0 1 * * *. The schema comment says that is 04:00 in Africa/Kampala when the clock is UTC. REFRESH_TOKEN_RETENTION_DAYS defaults to 30 and is a different job (purge-expired-refresh-tokens).
TeamsMessagePurgeService sets RETENTION_DAYS to 90 and deletes from teams_message where sent_at is older than that. The cutoff is Date.now() minus 90 days, not a database created_at interval. Batches are 5,000 rows, and one run stops after 20 batches. The cron comment matches the constant. This job was not executed.
Controls that are implemented
Authentication and authorisation. Bearer JWTs, CASL permissions, user-type and system-role guards, feature flags, and school API keys. The behaviour, including 401 versus 403 versus 404, is on Authentication across the platforms.
Tenancy. tenantContextMiddleware starts each request with schoolId: null and bypass: false. The JWT guard or the API-key guard fills the school id. Platform admins bypass. @TenantScoped() marks entities that BaseRepository scopes. This is the isolation mechanism in source. It is not a separate database per school.
Transport cookies. The Hub session is not an HttpOnly cookie. Tokens live in localStorage. The clinic PKCE cookie ehr_pkce is HttpOnly and is not a session.
Payment credentials at rest. CredentialCipher in libs/shared/src/utils/credential-cipher.ts uses AES-256-GCM. The key is SHA-256 of the configured secret. CredentialCipherService uses PAYMENT_CREDENTIALS_ENC_KEY. MicrosoftTokenCipherService uses MICROSOFT_TOKEN_ENC_KEY for Microsoft refresh tokens. CredentialCipher throws if the secret is empty. .env.example leaves those two keys blank, and a blank string overrides the insecure local defaults in envSchema. A local boot that needs those ciphers must set non-empty development secrets that you do not reuse anywhere else.
API key storage. SHA-256 hash. The raw key is not stored.
Rate limits that exist. All windows are 60 seconds.
| Where | Limit | Counted in |
|---|---|---|
sharedThrottler modules: auth, device pairing, enquiry | 10 | Redis |
sharedThrottler: guardian card | 20 | Redis |
sharedThrottler: library | 120 | Redis |
sharedThrottler: short link | 600 | Redis |
OTP and magic-link lookup | 120 per IP (ClientIpThrottlerGuard) | Redis (the auth module's sharedThrottler) |
OTP and magic-link request | 5 per person (PersonThrottlerGuard) | Redis (the auth module's sharedThrottler) |
OTP and magic-link verify | 10 per person | Redis (the auth module's sharedThrottler) |
| Admission capture | 5 | Redis (the auth module's sharedThrottler) |
ApiKeyRateLimitGuard | 60 per key, plus 10 per IP for non-secret keys; 429 Too many requests | Redis sorted set |
Clinic ApiKeyRateLimitGuard | 60 per key | In memory, per copy |
sharedThrottler is registered per module, not as a global guard. A Redis error isn't caught, so the request fails. See Several copies.
Rate limits read at API staging 4ddd0568: the six sharedThrottler(...) registrations, otp-auth.controller.ts, magic-auth.controller.ts, admission-capture.controller.ts and api-key-rate-limit.guard.ts. No request was sent.
CORS. Listed on the system overview. Public AI and POST /api/v1/enquiry reflect any Origin.
Docs basic auth. Off only when NODE_ENV === 'development'.
Controls that are absent or weaker than a reader might assume
- Helmet is not a dependency.
main.tsdoes not use it. - A global Idempotency-Key middleware was not found in
apps/server/src/main.ts. Two specific writers dedupe: SchoolPay receipt insert uses.orIgnore(), and the clinic webhook uses headerx-naalya-event-idas a BullMQjobId. A GitHub code search on 11 November 2026 forIdempotency-Key,idempotencyKey, andidempotency-keyreturned no matches. - SchoolPay inbound signature failure still returns HTTP 200.
SchoolPayInboundWebhookControllerhandlesPOST /api/v1/transactions/school-pay/inbound/:campusId(operationIdschoolPayInboundWebhook).verifySignaturehashes the campus API password concatenated withschoolpayReceiptNumberusing SHA-256 and compares the hex digest withtimingSafeEqualafter the provided signature is lowercased. A mismatch, a missing field, or a missing campus password makesingestWebhookreturn'rejected'. The controller still responds200with{ message: 'Callback processed' }. The method comment says SchoolPay does not retry. An invalidcampusIdcan still 400 fromParseUUIDPipebefore that. The route is@Public(), so the class-level bursary feature flag does not run. Do not describe this callback as authenticated by status code. The inbox and the three-day pull are on SchoolPay inbound. - Feature flags do not run on
@Public()methods. See authentication. - Hub UI checks are not server enforcement.
- Website
VITE_variables are inlined into the client bundle, includingVITE_NAALYA_API_KEYwhen set; that key is publishable and bound to the site's origins. The form write token used byPOST /api/form-submissionisSANITY_WRITE_TOKENon the server (app/routes/api/form-submission.ts). - No committed data-processing register, encryption-at-rest guarantee for Postgres, or backup policy was found. Hosted Postgres may provide those. This repository does not state them. Status: unknown.
Microsoft OAuth puts Hub tokens on the redirect query string (AuthController.microsoftCallback). Clinic Microsoft login puts them on the URL fragment. Query strings leak via history, logs, and Referer. That is the implemented redirect, not a recommended design. Do not add a new flow that copies it without a review.
- The Teams bot route trusts an environment switch.
POST /api/v1/teams/messagesis protected by the@microsoft/teams.appstoken check. That SDK turns the check off when the process hasDANGEROUSLY_ALLOW_UNAUTHENTICATED_REQUESTSset, because the API does not pass the option itself. Nothing in the API sets it. Keep it unset on every deployed environment. Details are on Channels.
Example data
Use these in handbook snippets, fixtures, and screenshots:
- Hosts:
example.com,api.example.com,hub.example.com - People: Amal O., Dana A., Kai N.
- School: Example Secondary School
- Tokens:
YOUR_ACCESS_TOKEN,YOUR_API_TOKEN - Identifiers:
SCHOOL_ID,CAMPUS_ID
Do not use a real pupil name, admission number, phone number, photograph, address, or a real staff identity. Do not paste production logs. If a screenshot must show an admin screen, crop it to the control and cover leftover data with a solid block.
SUPERADMIN_EMAILS and similar identifiers are committed in .railway/environments.ts. This handbook does not repeat them.
Developer duties
- Do not commit
.env.localor a filled secrets file. - Do not point a local migration command at a database you do not intend to change.
task migration:runusesDATABASE_URL. - Do not disable a guard to “make the screen work” and leave the API open.
- When you add an environment variable, add it to
envSchema(orehrEnvSchema) and to.env.examplewith an empty or obviously fake value. The example file and the schema have already drifted. The schema wins at boot. See Config & Environment.
Related pages
Writing standard
How to keep new pages inside these rules.
Authentication
Tokens, guards, and status codes.
Operations
Boot failures and migrations, with the limits of this runbook.
Sources
Naalya-APIlibs/shared/src/utils/credential-cipher.tsCredentialCipher,libs/shared/src/config/env.config.tsenvSchema,apps/worker/src/cron/records-retention.service.tsRecordsRetentionService,apps/worker/src/cron/teams-message-purge.service.tsTeamsMessagePurgeService,libs/shared/src/cron/cron.constants.tsCronJob,apps/server/src/app/ledger/school-pay-inbound.service.tsverifySignature,apps/server/src/app/ledger/school-pay-inbound.controller.ts,apps/server/src/app/auth/auth.module.tsthrottles,package.json(nohelmet)Naalya-Websiteapp/routes/api/form-submission.ts,DockerfileARGlistEducation-Hubsrc/services/api/api.instance.tstokenKey