This is a full-stack application for managing, searching, and importing global sanctions lists (UN, EU, US OFAC, PEP). It consists of a Firebase Cloud Functions backend, a Firestore database, and a Vite + React frontend.
The production web app is deployed and accessible at: https://sanctions-app-dev-01.web.app
- Node.js (v18 or newer recommended)
- Firebase CLI (
npm install -g firebase-tools) - Git
This project follows a strict multi-agent and developer coordination workflow. Please read GEMINI.md or CLAUDE.md for testing policies, coordination via claim files, PR conventions, and secure coding practices before contributing.
git clone https://github.com/jaggeman/sanctions.git
cd sanctionsInstall backend dependencies:
npm installInstall frontend dependencies:
cd frontend
npm install
cd ..You need to be logged into your Firebase account that has access to the project:
firebase loginThe active Firebase project is set to sanctions-app-dev-01 in .firebaserc.
To run the application locally, you'll want to start both the Firebase Emulators (for the backend/database) and the Vite development server (for the frontend).
In the root directory (/sanctions), run:
firebase emulators:startThis will start the local Firestore emulator and the Cloud Functions emulator (if you have deployed them locally).
Open a new terminal window, navigate to the frontend directory, and start Vite:
cd frontend
npm run devThe frontend will be available at http://localhost:5173.
(Note: To connect the frontend directly to the local emulator backend, ensure your API endpoints are pointing to the emulator's port, usually http://localhost:5001/sanctions-app-dev-01/us-central1/api instead of relative paths, or configure a proxy in vite.config.ts).
This project also includes command-line tools and scripts to fetch and parse large XML/CSV files directly into the database.
npm run buildFor very large files (like the US OFAC or EU lists), it is recommended to place them in the local data/ folder (which is ignored by Git).
Then, run the importer script locally to push the records to your database:
npm run importnpm run cli -- --helpThe backend has three test layers (see CLAUDE.md §1 for the full policy): pure/offline unit tests, Firestore security rules tests, and integration tests against a real Firestore instance. The rules and integration layers require the Firebase Firestore Emulator, which in turn requires a Java runtime (JDK 11+) to be installed — the test scripts start and stop it automatically via firebase emulators:exec, so you don't need to run firebase emulators:start yourself first.
Install dependencies once (from the repo root):
npm installRun everything (recommended before opening a PR — this is the merge gate, since there's no CI configured yet):
npm testRun a single layer:
npm run test:unit # fast, offline — parsers, normalization, API handlers with mocked Firestore
npm run test:rules # firestore.rules against a real emulator
npm run test:integration # uploadRecords etc. against a real emulatorWatch mode while iterating on the offline unit layer:
npm run test:watchTest files live under tests/unit, tests/rules, and tests/integration, with shared XML/CSV fixtures in tests/fixtures. New code should follow the TDD policy in CLAUDE.md §1 — write the test first, watch it fail, then implement.
If another process on your machine already holds the Firestore emulator port, change emulators.firestore.port in firebase.json locally and leave the change uncommitted — the suite picks the port up from FIRESTORE_EMULATOR_HOST.
src/shared/logger.ts writes structured JSON lines that Cloud Functions forwards to GCP Cloud Logging automatically — but this repo does not configure a log sink/export or extended retention anywhere, so that output sits in GCP's default _Default log bucket (commonly ~30 days) and is only queryable via the GCP Console by someone with project access.
That's a deliberate decision (issue #114), not an oversight: Firestore audit collections are this project's sole durable record, not Cloud Logging. If you need to look something up later, it lives in sanctions/versions (issue #9), imports (issue #7), overrides (issue #35), or decisions (issue #22) — not in a log line. See the comment at the top of src/shared/logger.ts for the full reasoning.
A comma-separated allow-list of the email domains permitted to log in at all. Without it, POST /api/auth/request-otp would email a one-time login code to any syntactically valid address, and verify-otp would hand out a full session for it — since the entire API sits behind that one session check, that is a two-request path to a working session for anyone on the internet.
ALLOWED_EMAIL_DOMAINS=yourcompany.com
The guard fails closed: if ALLOWED_EMAIL_DOMAINS is unset in production, nobody can log in — not even the dev test account — and both request-otp and verify-otp reject every address. That is deliberate — the alternative failure mode is open login for the whole internet — but it does mean you must set this before deploying, or nobody (including you) will be able to sign in.
Outside production (NODE_ENV !== 'production'), an unset list falls back to the dev test account admin@sanctions.com so local work isn't blocked. Setting ALLOWED_EMAIL_DOMAINS supersedes that fallback entirely — once configured, even the dev test account needs its own domain on the list.
Membership is re-read on every request (not just at login), so removing a domain from the list revokes every session using it immediately, on that session's very next request — and rejects any API tokens owned by addresses on that domain on their very next request (issue #158) — with no separate step and no need to wait for sessions to expire. Both endpoints reject a disallowed address with the exact same response shape as an allowed one, so the login flow can't be used to probe which domains are permitted.
A comma-separated allow-list of the email addresses permitted to reach the administrative endpoints (/api/admin/*, currently API token creation, listing and revocation).
ADMIN_EMAILS=alice@yourcompany.com,bob@yourcompany.com
The guard fails closed: if ADMIN_EMAILS is unset in production, nobody is an administrator and every admin endpoint returns 403. That is deliberate — the alternative failure mode is an open admin API — but it does mean you must set this before deploying, or token management will be unreachable.
Outside production (NODE_ENV !== 'production'), an unset list falls back to the dev test account admin@sanctions.com so local work isn't blocked. Setting ADMIN_EMAILS supersedes that fallback entirely.
Membership is re-read on every request, so removing someone from the list revokes their admin access immediately rather than when their session expires.
Every ADMIN_EMAILS address's domain must also appear in ALLOWED_EMAIL_DOMAINS. The two lists are checked independently — ALLOWED_EMAIL_DOMAINS gates login before ADMIN_EMAILS is ever consulted, so an admin whose domain is missing from the login allow-list is locked out entirely, with no indication of why (it just looks like a normal login rejection). The server logs a warn-level entry at startup for any misconfigured admin address, but it is not fatal — double-check both lists together before deploying.
src/mcp/index.ts is a separate stdio process (run via npm run dev:mcp, or node dist/mcp/index.js after npm run build) that lets an AI agent search and manage sanctions data through the MCP protocol — it is not part of the Express app. It exposes read tools (search_sanctions, get_sanction_details, get_override, list_decisions_for_entity), a sanctions://statistics resource, and write tools (run_database_import, create_override, record_decision).
MCP_API_BASE_URL=http://localhost:3000
MCP_API_TOKEN=sanc_...
Required only for create_override/record_decision — the other tools work with neither set. Both write tools proxy through the real running REST API (PUT /api/overrides/:id, POST /api/decisions) using this bearer token rather than writing to Firestore directly, so the write is always attributed to the token's ownerEmail (minted via POST /api/admin/tokens with write scope), never to anything the calling agent supplies. Missing either variable, or a failed API call, is surfaced back to the calling agent as an error rather than silently no-op'd.
POST /api/auth/request-otp is protected two ways, both hardcoded constants in src/auth/otp.ts rather than env vars (no deploy-time configuration needed to get a sane default):
OTP_REQUEST_COOLDOWN_MS(60s) — one address can't be sent a second code until its previous one's cooldown expires (issue #16).OTP_GLOBAL_SEND_LIMIT/OTP_GLOBAL_SEND_WINDOW_MS(30 sends per 60s, org-wide) — caps total OTP sends regardless of which addresses they're for, so many distinct real addresses can't all be emailed a code at once (issue #62). The per-email cooldown alone doesn't stop that: it only blocks repeats against one address.OTP_IP_SEND_LIMIT/OTP_IP_SEND_WINDOW_MS(5 sends per 60s per IP) — per-IP rate limit configured withtrust proxy: 1to prevent a single IP from spamming OTP requests (issue #144).
If a deploy needs a different volume (a genuinely larger user base, or a stricter posture), edit these constants directly rather than looking for an env var — there isn't one, by design, for a limit that should always be active rather than something an unset config could silently disable.
Server-side CSV imports (POST /api/import and CLI importer) are strictly confined to the permitted data directory (defaults to ./data relative to project root) to prevent arbitrary file read and path traversal attacks (issue #157 / CLAUDE.md §6). Paths referencing files outside this root, absolute paths pointing elsewhere, null bytes, or directory traversal (../) are rejected before any filesystem access.
ALLOWED_CSV_DIR=/path/to/permitted/data
För att ladda upp dina ändringar så att de syns live på webben följer du dessa exakta steg.
Viktigt innan du börjar:
Se till att ditt Firebase-projekt (sanctions-app-dev-01) är på Blaze-planen (Pay-as-you-go) i Firebase Console. Utan detta kan Google inte ladda upp din backend-kod (Cloud Functions).
Först måste vi kompilera TypeScript-koden för vår backend.
# Ställ dig i huvudmappen (roten av projektet)
npm run buildSedan måste vi paketera vår React/Vite-app så att den är redo för webben.
# Gå in i frontend-mappen
cd frontend
# Kör byggskriptet
npm run build
# Gå tillbaka till huvudmappen när det är klart
cd ..Nu när all kod är bygd laddar vi upp databasreglerna, backend-API:et och frontend-filerna på en och samma gång med Firebase CLI.
# Ladda upp till projektet
firebase deploy --project sanctions-app-dev-01När terminalen är färdig (tar vanligtvis 1-2 minuter) kommer den spotta ut din Hosting URL. Appen är nu live! 🎉