Skip to content

M14: True End-to-End VERITY_OFFLINE & Air-Gapped Cold-Start Baseline Support

  • Task ID: M14
  • Priority: P2 (Master Rank #3, Track A — Product & Customer Value)
  • Status: Done
  • Dependencies: M7, M8, M11
  • Target Repository: /Users/ivan/Project/3t.tools.intellij/verityredteam-free (verity-redteam-core)
  • GitHub Project #5: Verity RedTeam Free Task Board

1. Context & Problem Statement

When a user runs verity scan --offline (which sets VERITY_OFFLINE=1 inside src/verity/cli.py), only VulnerabilityIndex.load_auto() (src/verity/lookup/index.py) currently honors VERITY_OFFLINE: - src/verity/data_fetcher.py::fetch_remote_snapshot() never checks VERITY_OFFLINE and still attempts outbound HTTP fetches with timeout=15.0. - src/verity/fingerprint/matcher.py::FingerprintMatcher.load_auto() calls fetch_passports_snapshot() and load_from_directory() calls get_passports_path(download_if_missing=True) unconditionally. - src/verity/lookup/index.py::VulnerabilityIndex.load_from_directory() still calls fetch_vulnerabilities_snapshot() when the directory is missing or empty. - On a cold air-gapped install (empty cache, zero internet egress), verity scan --offline can stall on outbound fetches and returns 0 OSV CVE advisories because no baseline snapshot is resolved locally.


2. Requirements & Target Files

  1. Centralize VERITY_OFFLINE Enforcement (src/verity/data_fetcher.py):
  2. Add a helper _is_offline() checking os.environ.get("VERITY_OFFLINE", "").lower() in ("1", "true", "yes").
  3. Inside fetch_remote_snapshot(), when _is_offline() is True: read the local disk cache if present (regardless of TTL expiration) and return immediately without opening any network connection.
  4. Offline-Safe Fingerprinting & Vulnerability Loading (src/verity/fingerprint/matcher.py, src/verity/lookup/index.py):
  5. Guard FingerprintMatcher.load_from_directory() (download_if_missing=not _is_offline()) and load_auto() so zero outbound network requests occur when VERITY_OFFLINE=1.
  6. Guard VulnerabilityIndex.load_from_directory() when _is_offline() is True to avoid triggering remote fetches.
  7. Cold-Start Local Baseline Resolution (pyproject.toml / data_fetcher.py / index.py / matcher.py):
  8. Resolve packaged baseline snapshots (from installed mcp_fingerprints / mcp_vulnerabilities package data if bundled, or a compact fallback snapshot / clear stderr notice when running offline on a cold cache with no local dataset) so air-gapped cold-start scans are fast, deterministic, and transparent.

3. Automated Tests to Verify

Unit & Integration Tests (tests/unit/test_offline_airgap.py)

  1. Zero-Socket Hard Assertion (VERITY_OFFLINE=1):
  2. Monkeypatch urllib.request.urlopen (and socket.create_connection) to raise AssertionError("Network call forbidden in offline mode").
  3. Construct ConsolidatedSecurityAuditor() and run verity.cli.main(["scan", "--config-file", ..., "--offline"]) with an empty VERITY_CACHE_DIR.
  4. Assert zero network calls are attempted across VulnerabilityIndex, FingerprintMatcher, and data_fetcher.py, and scan completes in <1s.
  5. Expired-Cache Offline Fallback:
  6. Pre-populate VERITY_CACHE_DIR with valid passports.json.gz and vulnerabilities.json.gz whose mtimes are older than DEFAULT_TTL_SECONDS (expired).
  7. Run verity scan --config-file ... --offline with network blocked; assert expired caches are loaded cleanly and VULN-CVE-2025-6514 is still detected for mcp-remote@0.1.15.
  8. Direct load_from_directory() Offline Safety:
  9. Call FingerprintMatcher().load_from_directory(empty_dir) and VulnerabilityIndex().load_from_directory(empty_dir) with VERITY_OFFLINE=1 and network blocked; assert zero network calls and clean return.
  10. Online Default Preserved:
  11. Verify that when VERITY_OFFLINE is unset, normal online/conditional-ETag behavior in fetch_remote_snapshot() is unchanged.

4. Acceptance Scenario with a Real Air-Gapped Container & Local MCP Server

Verify true zero-network air-gapped execution inside a Docker container with --network none (kernel-level zero internet egress):

  1. Air-Gapped Container Test (tests/e2e_containers/verify_all_scenarios.sh or dedicated --network none step in run_e2e.sh):
  2. Launch the already-built customer-pip image with docker run --rm --network none (completely severed from the internet and host network) and an empty VERITY_CACHE_DIR=/tmp/cold_cache.
  3. Run against a local realistic workstation config (~/.cursor/mcp.json with plaintext secrets, bash -c, and mcp-remote@0.1.15) AND a real local stdio MCP server:
    # 1. Cold-cache air-gapped scan -> must complete in <3s with zero network errors
    VERITY_CACHE_DIR=/tmp/cold_cache verity scan --config-file /tmp/airgap_mcp.json --offline --fail-on-findings
    
    # 2. Local stdio probe in --network none container -> must catch poisoned tools & exit 1
    verity test --command "python3 /opt/fixtures/vuln_stdio_mcp.py"
    
  4. Acceptance Assertions:
  5. Command 1 completes in <3s (proving no 15-second HTTP timeout stall), exits 1, detects SEC-STATIC-SECRET-IN-CONFIG + SEC-STATIC-UNSAFE-SHELL-WRAPPER (plus VULN-CVE-2025-6514 when baseline/cache is present), and emits zero unhandled network tracebacks.
  6. Command 2 exits 1 and detects all 4 VERITY-STATIC-* rules against the local MCP server with --network none.

5. Verification Commands

cd /Users/ivan/Project/3t.tools.intellij/verityredteam-free
uv run ruff check src tests
uv run pytest tests/unit/test_offline_airgap.py -v
uv run pytest tests/
INSTALL_SOURCE=wheel ./tests/e2e_containers/run_e2e.sh

6. Acceptance Criteria

  • [ ] VERITY_OFFLINE=1 / verity scan --offline makes zero outbound network calls across data_fetcher.py, FingerprintMatcher, and VulnerabilityIndex.
  • [ ] Expired local caches are served cleanly in offline mode without attempting HTTP revalidation.
  • [ ] tests/unit/test_offline_airgap.py, full pytest tests/, and ruff check src tests pass cleanly.
  • [ ] Real air-gapped container acceptance scenario (docker run --network none) completes in <3s with zero network errors and passes inside tests/e2e_containers/run_e2e.sh.