Skip to content

Security: HarshkumarG007/LeadGuard

Security

docs/security.md

Security Architecture & Threat Model — LeadGuard 2.0

Status: APPROVED / IN GOVERNANCE
Version: 2.0
Threat Model Scope: Hostile Maintainer, Data Contamination, Dispatch Escalation, Algorithmic Bias


1. Security Objectives

  1. Physical Operational Safety: Prevent unauthorized, automated, or inadvertent dispatch of excavation crews based on unverified model outputs.
  2. Mathematical & Causal Integrity: Protect the causal evaluation barrier against label leakage, temporal contamination, and p-hacking.
  3. Protected-Class Data Privacy: Structurally isolate demographic indicators (race, income) from the predictive model to prevent discriminatory redlining.
  4. Cryptographic Provenance: Guarantee that all historical decisions, preflight evaluations, and audit logs are tamper-evident and signed.

2. Threat Model & Attack Vectors

2.1 The Hostile Maintainer Threat Model

A core assumption of LeadGuard 2.0 is that a compromised developer, model maintainer, or automated agent may attempt to manipulate metrics, inject future labels, or fabricate attestation signatures to artificially claim high utility.

Threat ID Threat Scenario Architectural Defense
THREAT-01 Label Leakage (Future to Past)
Injecting future excavation results into training features.
build_features requires explicit reference_df. Tested via metamorphic pathology test (test_leakage_detector_sensitivity.py).
THREAT-02 Dispatch Escalation
Autonomous system generating physical work orders.
Hard-coded environment gate in /v1/decisions/issue requiring LEADGUARD_PRODUCTION_MODE=true.
THREAT-03 Retrospective Ledger Tampering
Modifying historical decision records to hide bad predictions.
Append-only JSONL ledger with SHA-256 parent hashing forming an auditable merkle chain.
THREAT-04 Demographic Redlining
Predicting low lead risk in low-income areas to cut utility costs.
Runtime column filter strictly prohibiting protected demographic columns from entering the feature matrix.
THREAT-05 Attestation Forgery
Faking human auditor approval to unlock Phase S1.
Cryptographic key ceremony requiring an offline RSA/HMAC signature using keys/human_offline_key.pem.

3. Trust Boundaries & Attack Surfaces

+-------------------------------------------------------------------+
| UNTRUSTED EXTERNAL SURFACE                                        |
| Public Ingestion Feeds (Water Inventory CSV, Assessor Open Data) |
+---------------------------------+---------------------------------+
                                  | (Input Validation via Pandera)
                                  v
+-------------------------------------------------------------------+
| TRUSTED ANALYTICAL ZONE                                           |
| Feature Store, XGBoost Engine, Conformal Quantifier               |
+---------------------------------+---------------------------------+
                                  | (Physical Column Boundary)
                                  v
+-------------------------------------------------------------------+
| PROTECTED GOVERNANCE ZONE                                         |
| Census Reference (Fairness), Decision Ledger, Cryptographic Keys |
+---------------------------------+---------------------------------+
                                  | (Production Mode Gate: 403 Forbidden)
                                  v
+-------------------------------------------------------------------+
| RESTRICTED FIELD OPERATIONS                                       |
| Physical Excavation Dispatch (Human Authorization Required)       |
+-------------------------------------------------------------------+

4. Input Validation & Defense in Depth

  • Pandera Schema Validation: All dataframes entering cleaning, feature extraction, and inference must satisfy strict Pandera schemas defining types, allowed categories, and valid ranges (e.g., coordinates within Cook County bounding box: lat $[41.6, 42.1]$, lon $[-87.9, -87.5]$).
  • Pydantic HTTP Request Validation: FastAPI endpoints parse JSON payloads into strongly-typed Pydantic schemas, rejecting unexpected attributes and preventing parameter injection.
  • Fail-Closed Verification Scripts: The S0 verification script (scripts/run_s0_adversarial.py) immediately aborts if any network request is attempted or if artifact hashes differ from the frozen register.

5. Secrets Management & Key Ceremony

  • No Hardcoded Secrets: No API keys, credentials, or private keys are stored in source code.
  • Offline Key Ceremony: The private key keys/human_offline_key.pem is strictly ignored by Git (.gitignore). It is used exclusively in local ceremonies by authorized human auditors to sign contracts/S1_ATTESTATION_RECORD.md.
  • Pre-commit Hooks: Enforced via .pre-commit-config.yaml to detect accidental inclusion of private keys, certificates, or credentials.

6. Security Review Checklist

Before any release candidate or S1 consideration:

  • Are all demographic columns completely excluded from src/leadguard/data/features.py?
  • Does /v1/decisions/issue return HTTP 403 when LEADGUARD_PRODUCTION_MODE is unset?
  • Does test_leakage_detector_sensitivity.py successfully detect deliberate label leakage?
  • Is keys/human_offline_key.pem excluded from version control?
  • Are all dependencies checked against known CVEs via safety/pip-audit?
  • Has the decision ledger maintained continuous hash chain integrity?

There aren't any published security advisories