# Occupi: security and privacy fact sheet

For campus IT, the information officer and procurement. Last updated 2026-11-26. Every
statement here describes the current code. Gaps are listed as gaps.

## What it is

A web app that shows how full lecture rooms are, from Wi-Fi device counts per access point,
next to the timetable, and how many desks staff offices and meeting rooms really need. It also has a report form, with no sign-in, where students report room problems,
a page where staff book a free room for one-off use, and an optional "My day" sign-in where a student sees their own
timetable, with an emailed 6-digit code and a private calendar link.

## Where it runs

Two options, chosen in the operator agreement:

- **Hosted (the usual pilot).** MBK Consulting runs the campus's own Occupi site on Cloudflare (Workers and Durable
  Objects), with its own database kept in Cloudflare's nearest Durable Object region (Europe, for campuses in Africa),
  replicated, with 30 days of point-in-time recovery. Nothing is installed on campus and nobody needs access to the
  campus network: staff import Wi-Fi exports, which are read in their browser so only per-access-point counts are sent.
  Request logging is off for these sites. Cloudflare is a sub-operator under its Data Processing Addendum. Setup and
  design: `docs/deploy.md` §9, ADR 0014.
- **Campus server.** Everything runs on **one Linux VM on the campus network**, managed by campus IT: the collector,
  the web app and its SQLite database. Nothing personal leaves campus, and the Wi-Fi counts don't either.

Either way, the one outbound message is the sign-in code email, sent through the SMTP service the campus configures
(`OCCUPI_SMTP_URL`). The public demos on Cloudflare use made-up data only. Real data runs on Cloudflare only as a
hosted site that saves its database in its own Durable Object; it refuses to start on any other serverless host.

## Data

| Stored | Not stored |
|---|---|
| Per access point, per 15 minutes: a device count | MAC addresses, usernames, device IDs |
| Rooms, access-point-to-room mapping, weekly timetable (module codes) | Student names or plain student numbers or emails |
| Student key: a keyed HMAC hash of the student number or email, with the student's enrolments (`enrolments`) | The student number or email itself |
| One-time sign-in codes (`student_codes`): hash of the code, attempts, send count; gone after 10 minutes | The code in plain text |
| Calendar link (`student_feeds`): epoch and a hash of the link | The link itself |
| Counts from access points not yet placed in a room: held 35 days, then deleted | |
| Student reports: room, category, optional note (280 chars), time | Student IP addresses and user agents |
| Sign-in code limits (`student_code_clients`): student key, a SHA-256 hash of the network address, send and try counts; deleted at sign-in or within 15 minutes of the last code request | The network address itself |
| Staff accounts: username, display name, scrypt password hash, encrypted authenticator secret | Plaintext passwords or authenticator secrets |
| Bookings: room, time, booker's name, purpose | |
| Activity log: who signed in or changed what, when | |
| Room names staff matched (`room_aliases`) and rooms a timetable feed named that aren't on the campus yet (`room_queue`): the name as the file wrote it, the room it means, seats when the file gave a class size | |
| Problem reports (`problem_reports`): where something failed, the error message, a stack of Occupi's own code, times and counts; 30 days | Request bodies, paths with query strings, headers, cookies, tokens, passwords |

- Public seat counts are rounded to the nearest 5, and sorted on the rounded numbers only.
- Staff offices and meeting rooms are for space planning only. Students never see them (not on the
  seat finder, the report form or the public issue list), and lecturers can't open office use.
  An office with fewer than 8 desks is never shown on its own: small offices are added together per
  building, and only when there are at least 3 of them, 8 desks in all, and none holds more than half
  the desks. Otherwise they are left out of every figure. Those small offices aren't shown live on
  the map either. The figures are averages over 4 weeks and say how full an area is, never who was in.
- Student notes are checked by deterministic rules (no AI). They refuse teaching or lecturer
  complaints, names after a title or role ("Dr Naidoo", "Lecturer Naidoo"), and phone and ID
  numbers, including spaced-out or spelled-out ones. They also refuse emails (including "at …
  dot com"), social handles, links, swearing, and look-alike letters from other scripts.
- No filter is complete, so staff can delete any note in one click. The report still counts, and
  the deletion is logged.
- Retention is automatic: see the table in `docs/deploy.md` §7. Deleted rows are overwritten on disk.
- **Problem reports to the operator.** On a real campus, when a server error, a repeated
  scheduled-task failure or a feed that keeps failing occurs, Occupi sends one plain-text email per
  problem (at most once every 6 hours) to the operator's address, `OCCUPI_CONTACT_EMAIL`, through the
  same sender as outage alerts. It says what failed, the route template or task name, the campus,
  the time, the error message and a stack trace of Occupi's own code. It is built from a fixed
  list of fields, so it cannot carry a request body, a path or query, headers, cookies or sessions.
  Known secrets, emails, long numbers and addresses are masked and the message is shortened to
  160 characters before it is stored or sent; quoted text is dropped from errors raised by the
  platform or a library (a `SyntaxError` that echoes its input, a validation error). It may still
  contain a room or file name. It is off in the demo. The operator is the same party that already
  hosts the campus's data under the operator agreement. Admins see the same list under Staff → Setup → Check my setup.

## Student sign-in ("My day")

- A student types their student number or campus email. Occupi turns it into a keyed hash
  (HMAC, key derived from `OCCUPI_SECRET`) and looks it up in the campus's enrolment import. It never
  stores the number or email. Unknown identifiers get no code and no error that reveals who is enrolled.
- A 6-digit code is emailed to the student's campus address through the campus SMTP service. Only a
  hash of the code is stored. It expires after 10 minutes or 5 wrong tries, and sends are capped.
- Cookies: `__Host-occupi_student` (signed, holds the hash and an expiry; 14 days, or 30 days if the
  student ticks "keep me signed in", which is the default) and `__Host-occupi_student_pending` (10 minutes). Both are HttpOnly,
  SameSite=Lax and Secure in production. They are first-party and set only for the sign-in the student asks for.
  "Sign out everywhere" ends every copy; plain sign-out removes the browser copy. The full list of cookies and browser
  storage is in the privacy notice.
- The calendar link is an HMAC of the key and an epoch; only its hash is stored. "Reset link" kills the old one.
- The student key is never joined to Wi-Fi counts, which stay per room.
- The public demo uses fixed demo keys because its students are made up. Real mode requires `OCCUPI_SECRET`.
- Enrolment and timetable data per student can be an education record in some countries (for example
  FERPA in the US). The operator agreement covers this.

## Wi-Fi collector

- **Checkmk feed (no collector needed).** Where Checkmk already monitors the Wi-Fi controllers, `collector/checkmk/occupi-checkmk-push.py` runs on the Checkmk server as the site user (Python standard library only), reads the counting service's performance data through Livestatus on the same machine, and sends one count per zone every 15 minutes over outbound HTTPS. Nothing connects in, and nothing touches the controllers. It authenticates with a collector key; revoking the key on the Setup page stops it. Tested end to end on 2026-11-26 against the hosted pilot site, with a stand-in for Livestatus: readings arrived, and after revoking the key the next run was refused. **Not yet run on a real Checkmk server.**


- A small Node.js program on the campus VM, with no third-party packages. It uses a read-only
  (monitoring) controller account and makes outbound HTTPS to the Occupi web app only.
- MikroTik RouterOS:
  - The connection uses TLS with certificate fingerprint pinning.
  - Only the interface and SSID columns are requested, so MAC addresses never leave the router.
  - Tested against an official RouterOS 6.49.8 virtual router. **Not yet tested on physical hardware.**
- **Other controllers:** drivers exist in `collector/src/drivers` for Cisco 9800, Aruba OS 8, Aruba Central,
  Meraki, Mist, Ruckus SmartZone and UniFi, with unit tests against recorded responses. **None has been
  tested against a real or virtual controller.** The first live install is tuned during the pilot. Those
  APIs return per-client rows, which are counted in memory and discarded.
- **Fortinet FortiWLC (Meru):** the `fortiwlc` driver reads the controller over SNMP (v2c, or v3 with
  md5/sha and DES), read-only, from the collector VM only. It requests each station's MAC address and
  access point id, counts devices per access point in memory and discards them; IP addresses, user names
  and device fingerprints are never requested. The community string and SNMPv3 keys are never logged.
  Built to Fortinet's and Meru's published MIBs and tested against a simulator; **not yet run against a
  real controller.** v2c sends its community in clear text, so v3 is preferred, and the collector warns
  on a v2c host that is not a private address. Revoke by deleting the community or user on the controller.
- **Mist, phones only:** with `"count": "phones"` the collector asks Mist for counts grouped by
  operating system and by access point. It never requests the client list, so no MAC address,
  hostname or user name reaches it. Built to Mist's published API; not yet run on a live Mist site.
- Hardening:
  - Secrets come from files with checked permissions (or systemd credentials), never from the config file.
  - The collector refuses to run as root.
  - Size and time caps on everything the router or server sends back.
  - A crash-safe disk spool.
  - A systemd unit with `NoNewPrivileges`, `ProtectSystem=strict` and a dedicated user. A Dockerfile
    is included but has **not yet been built or run**.

## Access control

**Staff:**
- One account per person.
- Sign-in needs a password (generated, 20 characters, scrypt-hashed) and a 6-digit code from an
  authenticator app (TOTP, RFC 6238). Codes can't be replayed.
- Every failure gives the same message, and unknown, locked and real accounts all cost the same time.
- 5 wrong tries lock the account for 15 minutes. The attempt is claimed in the database before any password
  work, so a burst of parallel requests can't get past the lock. A lock that runs out starts a fresh count.
- A code's time step is claimed atomically, so one code can't sign in twice, even in parallel.
- Failed sign-ins for accounts that don't exist are summarised in the activity log (one line per 10 minutes),
  so they can't flood it. Without a trusted proxy, 300 failed sign-ins in 10 minutes pause sign-in briefly.
- Sessions:
  - The token is random (256-bit). The cookie is HttpOnly, Secure, SameSite=Strict and `__Host-` prefixed.
  - Only a hash is stored.
  - A session ends after 2 idle hours or 12 hours in total, at sign-out, or when the account is disabled or reset.
- Remember this device (optional; off by default, an admin turns it on per campus):
  - A person can tick "Remember this device for 14 days" at sign-in, after a correct code. That device then
    skips the 6-digit code, never the password, for 14 days. It is per device and per person.
  - The token is random (256-bit) in an HttpOnly, SameSite=Strict, Secure cookie scoped to `/staff`. Only a hash is
    stored, at most 10 devices per person.
  - The 5-try lock still applies. The code is never skipped for an authenticator not yet set up, with a
    temporary password, or for single sign-on.
  - Remembered devices are deleted when the person's password or authenticator is reset, the account is disabled
    or renamed, the setting is turned off, or after 14 days.
  - Resets and the whole-database download always need a fresh code, remembered device or not.
- Single sign-on connected on the People page: the provider's client secret is sealed (AES-256-GCM, key derived from
  the server's secret) before it is stored, never shown again (only its last 4 characters), and saving or removing it
  needs the admin's fresh authenticator code. An Okta issuer must be on Okta's own domains unless the admin names
  their custom Okta domain, and sign-in then only talks to that host. Server settings always take precedence.
- Deleted people and single sign-on: deleting an account that was linked to Microsoft or Okta writes a block (an
  HMAC, keyed with the server's secret, of the provider's permanent id, or of the saved address if the person never
  signed in that way), with their display name and who deleted them. A sign-in that would create an account checks
  it first and refuses. Admins can unblock on the People page; every block, refusal and unblock is in the Change log.
- Every staff page is checked twice: once at the route gate and again inside every server action.
- Hammering the staff URLs can't lock staff out, because the gate itself has no rate limit.
- Accounts can be made on the server with `npm run staff`, or on Staff → People. Admins reset a password or
  authenticator and unlock accounts there too: the new secret is shown once, never stored in the clear, and a
  reset needs the admin's own fresh authenticator code as well as their session. Nobody resets their own account.
  An admin can't rename, reset, change the role of or disable another admin (only the operator's command line
  can), so one admin's account can't be used to take over another's. Admins can rename non-admin accounts; the
  authenticator key is re-sealed under the new name and the person is signed out.
- Each account has one role: admin, facilities, lecturer or viewer (table in `docs/deploy.md` §4). Office and
  meeting-room use is open to admin, facilities and viewer accounts only. Every staff
  page and every server action checks the role on the server; the menu only hides what a role can't open.
  A section a role lacks returns the 403 page. Admins change roles and disable accounts on Staff → People,
  and the last admin who can sign in can't be demoted or disabled. Role changes apply on the next request
  and are in the activity log.
- Buildings and rooms are changed by admins only (Staff → Campus). Spreadsheet imports are planned on
  the server, shown in full, re-planned when applied, and run in one transaction; they never delete.
  Room names in downloaded spreadsheets are guarded against formula injection.
- Admins can download the whole database (Staff → Campus → Download), for a backup or when a hosted pilot
  ends. It holds password hashes and sealed authenticator keys, so it needs an admin's session plus a fresh
  authenticator code each time (a session cookie alone isn't enough), only this site's own page can ask for it,
  it's rate limited, never cached, never offered in the demo, and every download is in the activity log.
- Accounts on a hosted pilot: the first admin is made on the operator's machine with `npm run staff -- first-admin`
  and created only while the site has no accounts; everyone else is added on Staff → People.
- Authenticator secrets are encrypted with a key derived (HKDF) from OCCUPI_SECRET and bound to their account.
- Every staff page checks the session itself as well, not only the route gate.
- Staff sign-in through any OpenID Connect provider, with an Okta preset and group-to-role mapping (ADR 0019). Not yet run against a real Okta tenant.
- Microsoft Entra ID sign-in (OpenID Connect with PKCE, tenant-specific, ID token checked against the tenant's keys),
  see ADR 0015 and docs/deploy.md section 10. Accounts match on tenant-set names only, never the `email` claim; guests
  from other organisations are never given accounts automatically. Not yet run against a real tenant. SAML is not offered.

- First sign-in: accounts made on Staff → People, and accounts an admin resets, start on a temporary
  password. Until the person chooses their own, the session reaches only the "Choose your password" page
  (checked at the route gate, in every server action and in the page context). They must type the temporary
  password again, tries are rate limited (8 per 10 minutes per account), the temporary password then stops
  working and earlier sessions end.
- Campus posts (news, alerts, events for students) are admin-only. A post is plain text, with invisible and
  direction-changing characters stripped, and is never rendered as markup. A "more" link must be https on a
  host from the allowlist: the campus's own site plus the hosts in `OCCUPI_NEWS_LINK_HOSTS` (comma separated).
  Posts are limited per author and per campus, and only the author or an admin can change one.

**Collector to app:**
- A bearer token of at least 32 characters, compared in constant time. Failed attempts are rate limited.
- Collector keys made by an admin on Setup are 32 random bytes, shown once. Only their SHA-256 is stored
  (a random key of that size can't be brute-forced from its hash), they can be revoked at any time, and
  clients with too many failed attempts are turned away before any key or database work.
- Bodies are capped at 1 MB / 5,000 readings, and the schema is validated. Readings older than
  35 days or from the future are refused.

**Students:**
- No account for reading seat counts or filing a report. Signing in to My day is optional (see above).
- Reports are rate limited per IP behind a trusted proxy, or under a shared ceiling without one.
- A honeypot field catches bots.

## Web hardening

- **Security headers:** HTTPS with HSTS. A Content-Security-Policy: everything same-origin, no
  plugins, no framing, `base-uri` and `form-action` locked to self. `X-Frame-Options: DENY`,
  `nosniff`, `Cross-Origin-Opener-Policy: same-origin`, a strict referrer policy, and a
  permissions policy that blocks camera, microphone and location.
- **Script policy:** `script-src 'self' 'nonce-<random>' 'strict-dynamic'`, with no `'unsafe-inline'` and no
  `'unsafe-eval'`. `src/proxy.ts` makes a new nonce for every request and sets it in the policy header;
  Next.js puts it on its own script tags and the root layout puts it on the theme script. Because a nonce
  needs a page rendered per request, Cache Components and prerendered shells are off in every build. The
  edge copies of the public pages (`worker.ts`) get a new nonce each time they are served. Checked in a
  Chrome build of the demo on the Cloudflare Worker (local preview) and of a hosted-pilot build: the home,
  staff sign-in, staff map (3D), security, seats map, campus and pilot pages loaded with no policy
  violations and hydrated, and the theme toggle worked.
- **Known CSP gap:** `style-src` still allows `'unsafe-inline'`, because React sets `style` attributes
  (a nonce does not cover attributes). Styles can't run script, but a strict style policy is not done.
- **Injection:** SQL uses bound parameters only. React escapes all rendered text. The one use of
  `dangerouslySetInnerHTML` is the theme script in `src/app/layout.tsx`, a constant that contains no
  user input.
- **Dependencies:** `npm audit --omit=dev` showed 0 known vulnerabilities on 2026-11-09.

## Assurance

- **Automated checks:** 3,104 web app and 452 collector tests (last full run 2026-11-21), plus 43 tests for the Checkmk feed script and 51 Mist API emulator tests checked against Juniper's published OpenAPI spec, type checking and lint.
- **Dependencies (2026-11-26):** `npm audit --omit=dev` 0 known vulnerabilities (app and collector); OSV-Scanner found no known vulnerabilities across the 901 locked packages. The collector and the Checkmk feed script use no third-party packages. A CycloneDX software bill of materials is available on request.
- **Reviews:** security reviews of the web app and the collector were run by AI review agents on
  2026-11-09, then a second review of the new sign-in system. All critical, high and medium findings were fixed.
- **End-to-end test:** a real-mode server was checked on 2026-11-09. Sign-in with a real
  authenticator code worked, the wrong-code and replay refusals held, note deletion and the
  activity log worked, sign-out ended the session, the deleted note was gone from the database
  file and its write-ahead log, and no plaintext secrets were found on disk.
- **Not yet:** an independent penetration test, SOC 2 or ISO 27001, cyber insurance, or a bug bounty. Vulnerabilities can be reported to the address in `/.well-known/security.txt`
  (see `SECURITY.md`). The source code is private and can be shared with campus IT for review.

## Who runs it

Matt Klette (MBK Consulting, Gqeberha, South Africa). One person, so the campus holds the VM,
the data and the backups (see `docs/deploy.md` §8). A data processing (operator) agreement
template is in `docs/operator-agreement-template.md`.
