Security and data handling
Written for a security reviewer who has not read the source. Every claim names the function or constant that implements it, and tests/test_security_doc.py fails if any cited symbol stops existing.
Summary
| Question | Answer |
|---|---|
Does contextlift write to your warehouse? | No. Every SQL statement runs through read_only_violation before execution across all executors. |
| Can predicted SQL read local files off disk? | No. Filesystem reader functions are refused by name, and DuckDBExecutor enforces disabled_filesystems='LocalFileSystem' plus lock_configuration=true. |
| Does data leave your network? | Only to the warehouse and model endpoint you configure. There is zero telemetry, analytics, or phone-home. |
| Does the optional LLM judge send raw result rows? | No, not by default. judge.py sets allow_rows=False unless you opt in explicitly with --judge-allow-rows. |
| Where are artifacts stored? | Locally under --workspace (with 0o600 permissions on caches and ledgers, plus --hash-only-cache to keep raw rows off disk). |
| What is written into Knowledge Catalog? | Allowlisted hashes, timestamp, runner/model metadata, and gate outcomes only. No questions, SQL, or rows. |
Does serve-mcp open a network port? | No. CertifiedContextMCPServer communicates strictly over local stdio JSON-RPC 2.0. |
Three data channels
- Your warehouse (
executor.py).read_only_violationruns before every query inSQLiteExecutor,DuckDBExecutor,BigQueryExecutor,PostgresExecutor,SnowflakeExecutor, andDatabricksExecutor. It strips comments, masks string literals first (so semicolons inside quoted values do not false-trigger), and rejects anything other than a singleSELECTorWITHstatement, any write keyword (including inside data-changing CTEs likeWITH t AS (DELETE ...)), and external escape functions (EXTERNAL_QUERY,COPY,PUT,GET,CALL, and DuckDB filesystem functions such asread_text,read_csv,read_parquet,read_blob,read_json).DuckDBExecutoradditionally opensread_only=True, setsdisabled_filesystems='LocalFileSystem', and locks configuration. Pass--db-roleto enforce read-only role scoping (SET LOCAL ROLEon Postgres,role=on Snowflake, caller role metadata on Databricks and BigQuery). - Your model service (
runners/). Sends table/column descriptions, authored rules, terms, worked examples, joins, and question text (for Google Cloud Conversational Analytics, assembled bybuild_inline_contextinrunners/ca_api.py). - SSRF guard (_validate_base_urlinrunners/openai_compat.py): blocks cloud metadata (169.254.0.0/16,metadata.google.internal), IPv6 link-local (fe80::/10),0.0.0.0, and non-loopback RFC1918 private IPs by default while allowing loopback (localhost,127.0.0.1,::1) for local Ollama/vLLM. Pass--allow-private-endpointonly for trusted internal VPC proxies. - Command runners (backends.py):--backend command/--runner commandsplits argv withshlex.splitand invokessubprocess.run(..., shell=False)(nevershell=True). - LLM judge (judge.py): defaults toallow_rows=False(sending only SQL, row counts, and column types/names). Raw sample rows are sent only with--judge-allow-rows. - Explicit export (
contextlift share). Allowlist-first export inshare.pyfollowed by Unicode NFC case-folded leak scanning (find_leaks) that refuses the export if any customer identifier appears.
Spend controls and confirmation gates
- Forbidden projects:
CONTEXTLIFT_FORBIDDEN_PROJECTS(checked byrefuse_forbidden_projectinbackends.py) blocks billing against matching project prefixes before any call runs. - Interactive confirmation:
confirm_paidandconfirm_holdout_read(confirm.py) prompt viaask_tty, which opens/dev/ttydirectly (separateO_RDONLY/O_WRONLYdescriptors) so piped stdin (echo RUN | contextlift ...) and non-PTY shells cannot approve paid runs or second holdout reads. Zero, negative,NaN, and infinite--budgetvalues are refused; explicit$0.00offline replays run without prompts. - CI approval tokens: non-interactive pipelines can set
CONTEXTLIFT_APPROVAL_SECRET(HMAC-SHA256 bound topaid:<budget>orholdout:<workspace>) orCONTEXTLIFT_APPROVAL_EXPECTEDpaired withCONTEXTLIFT_APPROVAL_TOKEN. When configured,--yesalone cannot bypass verification, and tokens are never written to manifests. - Static report safety:
verdict.html(bundle.py) contains zero<script>tags and zero inline event handlers (onclick,javascript:,onerror,onload).
Knowledge Catalog provenance allowlist (provenance.py)
When running contextlift catalog-push, the provenance aspect is readable by any catalogViewer and by agents through MCP. Every field written by Provenance today:
arm_control_hash, arm_treatment_hash, gates, k_repeats, measured_at, model_alias, overview_hash, queries_hash, round_id, runner, served_state.
Three controls bound that payload:
ALLOWED_KEYSallows exactly19keys and drops anything else. It also permitstable_lift_pp,table_ci_low_pp,table_ci_high_pp,regressions,recall_misses,terms_hash,question_set_hash, andschema_hash(none of which are set byProvenancetoday, but the allowlist is the real future bound).MAX_STRINGis80characters to keep free-form prose, SQL, and questions out of catalog aspects.check_payloadrecursively inspects nested mappings/lists and refuses oversized values rather than truncating.
Workspace hygiene, PII redaction, and secret scanning
protect_runs_from_git(workspace.py) writes*toruns/.gitignore; fresh workspaces get a root.gitignore(WORKSPACE_GITIGNORE), andgit_exposure_warningwarns when an existing repo.gitignoreleavesindex.jsonorcontextlift.jsonexposed.- Sensitive caches (
cache/golds.json), checkpoints, and the atomicfcntl.flockholdout ledger (holdout_ledger.json) are created with POSIX0o600permissions. Pass--hash-only-cacheto store canonical result SHA-256 digests instead of raw query rows. ingest-failuresscrubs emails, SSNs, phone numbers, card numbers, and bearer tokens before writingreview.csv.- Spreadsheet CSV exports apply
csv_safe_cell(csv_safe.py) to neutralize Excel/Calc formula prefixes (=,+,-,@,\t,\r,\n). contextlift scan(secret_scan.py) scans staged diffs, commit ranges, full history, or all tracked files (via NUL-delimitedgit ls-files -zso paths with spaces or Unicode are never skipped).attestation.json(attest.py) provides deterministic hash chaining and symmetric HMAC-SHA256 integrity seals (with CIsignerandci_run_urlmetadata when run in GitHub Actions), not asymmetric PKI or hardware-backed signing.
Limits. What this does not do
- It does not sandbox the model service. Table names, column descriptions, rules, and questions reach the model endpoint you configure; evaluating an agent requires talking to it.
- It does not encrypt the workspace at rest. It applies
0o600permissions and offers--hash-only-cache, relying on your OS disk encryption beyond that. /dev/ttydoes not stop a local process that can allocate a PTY. It stops piped stdin and non-PTY subshells, but a local agent allowed to spawn a PTY can writeRUN. Enforce hard limits with--budget,CONTEXTLIFT_APPROVAL_SECRET, and cloud billing quotas.--yesis a real bypass. It requires a positive finite--budgetand is recorded aswaivedwith argv in the manifest, and it remains a bypass unlessCONTEXTLIFT_APPROVAL_SECRETis configured.- The read-only rail is a text check, not a database privilege. Pair
read_only_violationwith a least-privilege read-only--db-roleand database user. - Beta cloud connectors (
PostgresExecutor,SnowflakeExecutor,DatabricksExecutor). Verified offline with fail-closed SQL rails and mocked drivers; pair with a read-only database role in production. - No third-party audit. Nobody outside this project has completed an independent formal security audit.
IAM, per command (Google Cloud)
Derived from the client calls each command makes. Not yet verified against a live estate for every row: rows marked verified ran on a real project; rows marked derived come from code inspection. Run contextlift doctor --explain to decode live refusals (including VPC Service Controls perimeter blocks).
| Command | Required roles | Status |
|---|---|---|
demo, doctor | None | verified |
gate, score, round on bq:// | roles/bigquery.jobUser (billing), roles/bigquery.dataViewer (datasets) | verified |
log | roles/bigquery.resourceViewer | verified |
round (ca-api) | roles/geminidataanalytics.dataAgentUser + BigQuery roles above | verified |
catalog-pull, catalog-list | roles/dataplex.catalogViewer | verified |
catalog-push, catalog-rollback | roles/dataplex.catalogEditor, roles/dataplex.aspectTypeOwner (once) | derived |
sentinel | catalog-push + ca-api roles | derived |
eval-room | roles/bigquery.dataEditor on the evaluation project only | derived |