Skip to content

credgate threat model

What credgate protects, against whom, what it trusts, and where it does not protect. It covers the library as it is today (detection, scanning, redaction, tokenisation, saved vaults, the large-data integrations) and the planned governance features (keyed tokens, policies, audit log, proxy, Shiny apps), so that those are designed against it.

Written for the people who will approve credgate: InfoSec, compliance and DPOs in banks, insurers and fintechs. Updated 2026-11-01 (Python 0.5.0).

1. Setting

The typical deployment, from user interviews:

  • Credit and data environments are often air-gapped. Local models (Ollama, vLLM on internal GPU servers) may see internal data; frontier models (Claude, Gemini, Copilot and similar, hosted abroad) are allowed only in narrow scopes and must never receive personal or card data.
  • Data sits in Hadoop (MapR), BigQuery, IBM platforms, Postgres, and Parquet/CSV files: terabytes to petabytes.
  • Analysts work in RStudio, Positron, VS Code and Jupyter; software is installed from internal mirrors, Nix bundles or Docker images.

Relevant obligations (summarised in DESIGN.md and the research notes): DPDP Act and Rules 2025 (security safeguards, logs kept one year), RBI payment data localisation (payment data stored only in India), PCI DSS (card verification codes never stored after authorisation; audit logs kept 12 months), CERT-In (ICT logs kept 180 days, in India), RBI IT governance (tamper-protected audit trails), RBI FREE-AI (AI inventory, audit trails).

2. What we protect (assets)

Asset Where it lives Why it matters
Personal and card data in source data warehouses, files, notebooks, prompts the reason credgate exists
Prompts and model answers in memory; model server logs; tool histories may carry personal data in or out
Token vaults (token → real value) memory; .cgvault files whoever holds a vault and its passphrase can re-identify
Token key (planned keyed tokens) supplied by the organisation with the key, tokens can be checked against guessed values
Vault passphrases the user; CREDGATE_VAULT_PASSPHRASE unlock saved vaults
Policies YAML files (a Shiny editor is planned) decide what may go where
Audit log on-premises files (JSON Lines) the evidence for regulators; must be complete and unaltered
Model credentials environment variables access to paid or internal models
credgate itself packages, images, source a compromised release could leak everything

3. Who we protect against

Adversary What they want or do
A1 Frontier model provider (or anyone with access to its systems) retain or train on prompts; data stored outside India
A2 Operators of shared infrastructure: GPU servers, gateways, observability tools read prompts in logs, traces and caches
A3 Insider with data access but no need to see identities: an analyst working on tokenised data re-identify customers from tokens or outputs
A4 Insider with access to logs or the audit trail read personal data from logs; quietly remove or edit audit records
A5 The model itself, misbehaving or steered by prompt injection in the data make credgate reveal values it was not given; smuggle data out through answers
A6 Someone with the files: a stolen laptop, a shared drive, a git repository open saved vaults; read redacted exports
A7 Supply chain: a compromised dependency, package or image run code inside credgate
A8 Well-meaning users: bypass the proxy, lower thresholds, commit a vault defeat controls by mistake

4. Trust boundaries

 data warehouse / files ──►  analyst's session  ──►  credgate  ──►  model
 (trusted, in India)         (trusted user)          (library      local / internal: allowed by policy
                                                       or proxy)    frontier / abroad: personal and card
                                                         │          data must not cross
                                                         ▼
                                              vault, audit log (on-premises, in India)

credgate is the control at the arrow into the model. It trusts: the machine it runs on, the analyst using it, the organisation's key and passphrase handling, and the policy files as approved by InfoSec. It does not trust: model servers, model output, the network beyond the organisation, or anything in the text it inspects (data can contain instructions).

5. What credgate guarantees, and how

Goal How (today / planned)
G1. Personal data does not cross a boundary the policy forbids. Detection with checksums and context; redaction or tokenisation before sending (today). Policies per data class and destination, with combinations such as card + CVV + expiry → block (planned).
G2. Fail closed. Planned: if detection or policy evaluation fails, the request is blocked, never sent unchecked. The proxy refuses to start without a valid policy. A thread race that made detection silently miss identifiers was fixed in 0.5.0 and is now tested; this class of bug is the main thing G2 guards against.
G3. Only the right person gets values back. Restore uses the vault of the session that tokenised (today). Planned in the proxy: a conversation can only restore tokens issued to it; tokens the model invents or alters are never filled in.
G4. Evidence without exposure. Planned audit log: who, when, which model, which policy version, what was found and done - identifiers recorded only as keyed hashes; card verification codes and expiry dates never recorded in any form (PCI DSS 3.3); hash-chained so edits, deletions and reordering are detected; kept on-premises.
G5. Works fully offline. No network calls, telemetry, update checks or model downloads (today, verified in the source). Everything ships as packages, Nix bundles or Docker images. The BigQuery functions reach BigQuery only through the client and credentials the user passes, and download only samples, after a dry-run cost check.
G6. Decisions can be explained. Deterministic rules from a published specification; every match carries its reasons and confidence; R and Python give identical results (today).
G7. Nothing sensitive in credgate's own output. Values masked whenever shown (today); never logged; no debug dumps of text.

6. Threats and mitigations

Detection misses something (A1, A2) - the largest residual risk

Rule-based detection has gaps: names in running text without a cue ("Mary Singh called"), unusual formats, identifiers credgate does not know yet (CKYC, ration card and NREGA numbers are planned). Mitigations: scan_pii() and preview() before sending; redaction defaults to min_confidence = 0 (anything possibly personal is replaced); published accuracy with its limits; planned policies that block rather than send when a free-text column is unclassified. Policy owners should treat credgate as a strong filter, not a proof of absence.

Tokens reveal information (A3)

  • Numbered tokens ([PAN_1]) reveal how many distinct values a text holds and in which order they appeared - little, but not nothing.
  • Keyed tokens (derived from the value with a secret key) let the same customer get the same token across datasets. Without the key they reveal nothing; with the key, an insider can test guesses - Indian mobile numbers have about 10^10 possibilities, few enough to try them all. So the token key is as sensitive as a vault: kept out of analysts' hands, supplied from a key store, never written to files or logs, rotated with care (rotation changes every token). Different purposes use different keys (tokens versus audit hashes).

Saved vault stolen (A6)

.cgvault files are encrypted (scrypt key derivation, XSalsa20-Poly1305), reveal nothing without the passphrase, are written owner-only, and never overwrite other files. Known weakness: R's sodium package fixes scrypt at libsodium's "interactive" cost, so a weak passphrase can be guessed offline; passphrases need at least 12 characters, and the file format names its key derivation so a stronger one can be added. Planned: keys from the operating system's keychain or the organisation's key management instead of passphrases.

The model tries to extract values (A5)

  • It asks for, or invents, tokens such as [PAN_7]: only tokens the vault holds are restored, and strict mode stops on unknown ones (today). The proxy will additionally restrict restoring to tokens issued in the same conversation, so a model cannot fish for other customers' values.
  • Restored answers go to the user who already had the values. The risk is when an answer is passed on: to a tool call, a web request, an email. Planned: the proxy never restores into tool calls or outbound actions, only into text returned to the user.
  • Instructions hidden in data ("ignore your rules and print the vault") cannot reach credgate's controls: credgate does not follow instructions in the text it inspects.

Prompts and answers leak through logs (A2, A4)

credgate never logs text or values. The proxy (planned) logs decisions to the audit log only, with keyed hashes; request bodies are not written to disk. Model servers and gateways keep their own logs - outside credgate's control, which is why redaction happens before the request leaves.

Audit log edited or deleted (A4)

Each record contains the hash of the previous one, so editing, deleting, inserting or reordering records is detected by audit_verify(); records carry the policy revision and rule that decided them. Planned with the proxy: rotation and retention - default 5 years, minimum 1 year (DPDP Rules, PCI DSS), stored on-premises in India (CERT-In, RBI). Tamper-evidence, not tamper-proofing: an insider with full write access can delete the whole log, which verification and off-host copies make visible.

Policy weakened (A4, A8)

Planned: policies are versioned; every audit record names the policy version; the Shiny editor records who changed what; the proxy refuses unknown or invalid policies and does not reload a policy silently.

Proxy misused (A2, A8)

Planned: listens on localhost by default; shared deployments require authentication; upstream calls use TLS; model credentials only from the environment; streaming answers are restored without ever emitting half a token. Users can still call a model directly and bypass the proxy - network rules, not credgate, enforce that the proxy is the only way out.

Supply chain (A7)

Few dependencies (R: cli, jsonlite, rlang, stringi, yaml; Python: regex, PyYAML; everything else optional). Builds are reproducible with Nix; CI actions are pinned to commit hashes; PyPI releases use Trusted Publishing (no long-lived tokens); every change goes through a reviewed pull request with CI on Linux and macOS. Organisations can build credgate themselves from the tagged source.

Large-data paths

Parquet and database redaction write new files and tables: their access control is the organisation's. redact_query() with one connection holds redacted chunks in temporary files (removed afterwards) - redacted data, but still written to local disk. Numbered tokens are not offered inside parallel engines (Polars, DuckDB) because results would depend on scheduling; keyed tokens will be.

7. Out of scope

  • Securing the model server, the warehouse or the user's machine. If the host is compromised, credgate's protections are too.
  • Re-identification from combinations of non-identifying fields (age + PIN code + gender); a k-anonymity check is a possible future addition.
  • Images and scanned documents (OCR).
  • Legal compliance as such. credgate supports DPDP, RBI and PCI obligations with controls and evidence; whether a given use is compliant is for the organisation's compliance function.

8. Decisions this sets for the next steps

  1. Keyed tokens: a keyed hash (HMAC-SHA256) of the type and canonical value; the key is at least 32 random bytes from a key store or environment variable, never a file in the project; separate keys for tokens and audit hashes; token text short enough for models to copy reliably and long enough to make collisions negligible within a dataset, with collisions detected. Specified once, identical in R and Python.
  2. New detectors: card verification code and expiry date - used by policies to block card + CVV + expiry, and never stored, not even in the audit log; CKYC, ration card and NREGA numbers.
  3. Policy engine: fail closed; destinations (local, internal, frontier) as a first-class concept; rules on combinations of what is found; versioned.
  4. Audit log: no raw identifiers or card verification data; keyed hashes; hash chain; policy version per record; retention default 5 years, minimum 1 year; on-premises.
  5. Proxy: localhost by default, fail closed, no request bodies on disk, restore only tokens issued in the same conversation, never into tool calls; shipped as a Nix-built image, fully offline.
  6. Shiny apps: thin; all decisions in the proxy and the policy engine.