<!--
SPDX-FileCopyrightText: 2026 Science Against Authoritarianism Contributors
SPDX-License-Identifier: CC-BY-SA-4.0
-->

# Operational Security (OPSEC), Visitor Privacy & Organizational Isolation

Pharos operates under one non-negotiable engineering covenant: **Watch Power, Not People** (see [THREAT_MODEL.md](../THREAT_MODEL.md)). Because comparative research on authoritarianism, corruption, and institutional capture can expose readers, journalists, students, and contributors to retaliation or harassment, privacy and separation are enforced mechanically in code — never left to good intentions.

---

## 1. Citizen & Visitor Protection (Zero Surveillance by Architecture)

Every public page and open API endpoint in the Pharos portal enforces:

- **Zero cookies, zero analytics, zero third-party subresources:** No external font CDNs, scripts, trackers, or beacons. `audit_security.py` fails the build if any HTML or CSS file references an external subresource.
- **Zero visitor IP / User-Agent / Cookie inspection at the edge:** The anonymous community and peer-review intake worker (`site/public/_worker.js`) never reads `cf-connecting-ip`, `x-forwarded-for`, `x-real-ip`, `true-client-ip`, `user-agent`, or `cookie`.
- **Hard Edge PII Firewall (`HTTP 422`):** Any submission containing an email address, phone number, IBAN, tax ID, API secret, or private key block is rejected before storage — nothing personal is ever written to KV.
- **Anti-leak HTTP Security Headers (`site/public/_headers`):**
  - `Referrer-Policy: no-referrer` (outbound DOI and newspaper links never see which Pharos country page you came from)
  - `X-DNS-Prefetch-Control: off` (prevents browsers from leaking hovered outbound domains to recursive DNS resolvers)
  - `Strict-Transport-Security: max-age=63072000; includeSubDomains; preload`
  - `Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; form-action 'none'; frame-ancestors 'none'`
  - `Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Resource-Policy: same-origin` & `Origin-Agent-Cluster: ?1` (process-isolates Pharos tabs)
  - Strict hardware/sensor lockdown via `Permissions-Policy` (`camera`, `microphone`, `geolocation`, `payment`, `usb`, `bluetooth`, `serial`, `hid`, `magnetometer`, `gyroscope`, `accelerometer`, `interest-cohort`, `browsing-topics` all disabled)
  - **Automated Client-Side Zero-Telemetry Audit:** `./pharos opsec` scans every frontend JS file in `site/src/` and `site/public/` to guarantee zero `document.cookie`, zero `navigator.sendBeacon()`, zero `WebSocket`, and zero third-party `fetch('https://...')` calls.
- **Full Offline Mode (`sw.js`):** Once visited once, Pharos works offline so readers in censored or metered networks do not need repeated round-trips.

---

## 2. Contributor & Employer / Company Isolation

Pharos is an independent, anonymous public-interest observatory. No individual contributor, employer, or private company should ever be linked to the public bundle, release archives, or hosted deployment.

### Automated Local & Build-Time Guards

1. **Salted SHA-256 Identity & Organization Scrubber:** Both `site/vite.config.js` (during `npm run build`) and `src/pharos/release_bundle.py` (during tarball generation) scan every text artifact using salted SHA-256 token digests — zero plaintext personal or corporate strings exist anywhere in the codebase, yet any accidental personal name, email, ORCID, repository handle, company identifier, or shared hosting account ID fails the build immediately.
2. **Workstation Path Leak Blocker:** Rejects macOS, Linux, and Windows home-directory paths as well as `.DS_Store`, `.env`, and transient `.cloudflare/` deploy caches.
3. **Anonymous, History-Free Release Tarballs:** `pharos-v0.4.0-source.tar.gz` and `pharos-blind-grader-pack.tar.gz` strip `.git/` completely and normalize every archive member to `uid=0`, `gid=0`, `uname=""`, `gname=""`, `mtime=0`.
4. **Repo-Local Git Author Pinning & Push Lockout:**
   ```bash
   git config --local user.name "Pharos Contributors"
   git config --local user.email "contributors@pharos-observatory.invalid"
   git config --local remote.origin.pushurl "DISABLED-NEVER-PUSH-PERSONAL-REMOTE"
   make hooks
   ```
   The `.githooks/pre-commit` hook verifies anonymous authorship and scans staged files via `./pharos opsec --staged` before every commit; `.githooks/pre-push` refuses any push targeting a remote URL that triggers the identity/company digest guard.

---

## 3. Infrastructure & Billing Separation Playbook (Full Account Isolation)

Static edge deployments on shared accounts do not expose sibling projects to public HTTP visitors, **but full operational isolation also separates billing, DNS, API tokens, and host accounts** from any personal or company infrastructure:

1. **Dedicated Alias & Standalone Hosting Account:** Register a standalone hosting account under a dedicated neutral email alias (separate payment method, separate 2FA hardware/TOTP key, zero shared commercial domains or team memberships).
2. **Neutral Public-Interest `.org` Domain with WHOIS Privacy:** Register an independent `.org` domain (e.g., via a privacy-by-default registrar with redacted RDAP/WHOIS) strictly inside that standalone account — never as a subdomain of a personal or company domain.
3. **One-Command Canonical Origin Cutover:** Pharos ships an anonymity-gated domain switcher (`./pharos domain`) that refuses any personal or company domain before updating canonical links, `CITATION.cff`, `REUSE.toml`, `sitemap.xml`, `feed.xml`, `robots.txt`, and `manifest.json`:
   ```bash
   ./pharos domain --set https://<your-neutral-domain>.org --dry-run
   ./pharos domain --set https://<your-neutral-domain>.org
   make interop && make site-verify && ./pharos opsec
   ```
4. **Post-Deploy Verification:** Always delete any transient local deploy cache (`rm -rf .cloudflare`), then verify live HTTPS headers and OPSEC posture:
   ```bash
   ./pharos domain --check https://<your-neutral-domain>.org
   ./pharos opsec
   ```

---

## 4. Machine-Verified Audit Commands

Run anytime — 100% offline, stdlib only:

```bash
./pharos opsec                              # Full 7-check OPSEC, telemetry, tarball, worker, header & git isolation audit
./pharos opsec --clean-mirror /tmp/pharos   # Export a brand-new, history-free, 0-error/0-warning anonymous Git repo
./pharos opsec --json                       # Machine-readable audit report
make security                               # Audit #11 (CSP, sinks, secrets, WCAG, CORS/CORP & OPSEC gates)
make site-verify                            # Build + verify site/dist/ + history-free tarballs + zero leaks
```
