Skip to contents

airgapllm is designed for sensitive human-subjects research text governed by IRB, HIPAA, and FERPA data-use agreements. This document records the concrete vulnerabilities identified during both the v0.2.0 internal adversarial red-team audit and the v0.5.0 independent peer red-team audit, the architectural mitigations implemented across the package, and guidance for reporting security issues.


1. v0.5.0 Independent Peer Red-Team Audit & Hardening (21 Findings Resolved)

An independent peer audit exercised every module (R/*.R) and cross-package interoperability flows with live exploits and fuzzing. All 21 confirmed findings (2 Critical, 9 High, 7 Medium, 3 Low) were remediated in v0.5.0 and locked down with permanent regression tests in tests/testthat/test-peer-redteam.R:

ID Severity Surface Vulnerability Identified Remediation Implemented in v0.5.0
C-01 Critical cli::cli_abort() Formatting (R/audit.R, R/irb.R, R/workflow.R, R/runtime.R, R/container.R, R/pii.R) Dynamic untrusted strings (tampered audit JSON keys, endpoint URLs, model paths, metadata keys, malformed regex messages) were passed directly into cli::cli_abort(), allowing {...} glue R code execution. Centralized escape_cli_braces() escaping all dynamic error bullets and wrapped dynamic interpolations ("{ep_info$reason}", "{conditionMessage(e)}") so untrusted braces are never evaluated.
C-02 Critical Audit Logs & IRB Compliance Packets (R/audit.R, R/workflow.R) decoding_params, row_counts, and scalar audit fields were unscanned or used a truncated 4-entity scan; export_irb_compliance_packet() skipped .md/.qmd/manifest scanning while stamping zero_pii_verified = TRUE. Enforced finite non-negative integer checks on row_counts/pii_counts/output_pii_leaks, strict ISO-8601 timestamp validation, full built-in PII scanning on all audit fields, and full-artifact zero-PII scanning across every file and manifest JSON before sealing packets.
H-01 High Output PII Scanner (R/extract.R) Any <<TYPE_HEX>> pattern bypassed output PII scanning without checking vault membership; predictable {AIRGAPTOK:0001} placeholders risked collision corruption. Verified tokens strictly against active_vault$mappings allowlists, flagged unrecognized tokens as forged_pseudonym_token, and used per-call 64-bit random nonce sentinels with single-pass restoration.
H-02 High Container Offline Environment (R/security.R, R/container.R) User env entries could override HF_HUB_OFFLINE, OLLAMA_HOST, DO_NOT_TRACK, or inject HTTP_PROXY while passing preflight_isolation_check(). Blocked protected offline/loopback and proxy env vars in assert_safe_env_entry(), re-validated in build_container_env(), and added required container_env_isolation pre-flight verification.
H-03 High Vault Load Downgrade (R/pii.R) Supplying key to pii_vault_load() silently loaded a swapped plaintext (encrypted = FALSE) vault. Added require_encrypted = !is.null(key) and aborted with airgap_vault_error whenever an unencrypted vault is loaded under encryption expectation.
H-04 High Symlink Write Targets (R/security.R, R/workflow.R, R/pii.R, R/audit.R, R/extract.R, R/irb.R, R/container.R) Planted symlinks in compliance packet directories, vault rotation .bak files, checkpoints, logs, or emitters could overwrite arbitrary files. Added assert_safe_write_target() across all disk write paths (allowing Darwin OS aliases /var, /tmp, /etc while rejecting user symlinks) and created 0600 temp files prior to writing vault bytes.
H-05 High Model Digest Verification (R/container.R, R/security.R) Hidden dotfiles and hidden symlinks were skipped (all.files = FALSE); parent-directory symlinks were unchecked when root_dir = NULL. Enumerated all.files = TRUE, no.. = TRUE in verify_model_digest() and walked parent directory components in assert_path_confined() even when root_dir = NULL.
H-06 High PII Evasion (R/security.R, R/pii.R) Combining diacritics (123\u0301-45-6789), ALL-CAPS EHR headers/names (PATIENT: JOHN DOE, ATTENDING ROBERT MILLER), and accented names evaded detection. Stripped combining marks and transliterated Latin accents in canonicalize_pii_text() with exact original span mapping; enabled case-insensitive clinical titles/roles and ALL-CAPS role-prefixed names.
H-07 High prompt_template Privacy Gate (R/extract.R, R/consensus.R) Pre-rendered prompt_template strings containing raw PHI bypassed pre-inference PII redaction. Scanned prompt_template / prompt_templates for raw PII and blocked templates lacking text that embed unsanitized input rows when pii_policy != "verified_deidentified".
H-08 High kk-Anonymity / ll-Diversity (R/anonymity.R) NA-QI rows escaped suppression under include_na = FALSE; mask_value = NA produced false passes; \x1f/"<NA>" caused key collisions; non-compliant mask_rare failed silently. Switched to strictly injective length-prefixed equivalence keys, marked excluded NA-QI rows as violating, blocked mask_value = NA with include_na = FALSE, failed closed on all-excluded tables, and added airgap_anonymity_warning.
H-09 High Checkpoint Integrity (R/extract.R, R/schema.R) Checkpoint resume did not verify model identity or per-row input_sha256; validation errors echoed raw LLM extra keys and enum values. Verified header$model and per-row input_sha256 on resume (aborting with airgap_checkpoint_error on mismatch/drift) and omitted raw untrusted LLM keys/values from validate_extraction() errors.
M-01..M-07, L-01..L-03 Medium / Low Consensus, Validators, Chunker, Proxy, Hardware, Mock, Regex Consensus all-digit token mangling, duplicate prompt drops, column overwrites, single-pass 100% agreement, Inf numeric/validator bypasses, chunker duplicate loop, IPv6 [::1] NO_PROXY, --trust-remote-code, sequential pii_reidentify(), silent OOM/RAM over-allocation, zero mock prompt variance, multiline street city leak, unix:/// metacharacters, and </UNTRUSTED_RESEARCH_RECORD > tag spaces. Propagated vault tokens in consensus; centralized assert_scalar_int(); enforced min_cut >= overlap_chars + 1L; required ::1 in NO_PROXY for [::1]; blocked --trust-remote-code, --download-dir, and leading-dash paths; switched pii_reidentify() to single-pass; added feasible + RAM cap + OOM warning; mixed prompt hash into runtime_mock(); broadened multiline address, unix:///, and delimiter regexes.

2. v0.2.0 Adversarial Red-Team Findings & Mitigations

# Severity Surface Vulnerability Identified in v0.1.0 Remediation Implemented in v0.2.0
F1 Critical Container & Apptainer Emitters (R/container.R) image, model_file, extra_args, env, model_dir, service_name, and resource flags accepted newlines, shell metacharacters, : bind-mount options, or %post directives—enabling arbitrary shell/Apptainer/YAML injection or :rw mount downgrade. Strict centralized validators in R/security.R (assert_safe_container_image(), assert_safe_host_path(), assert_safe_model_file(), assert_safe_env_entry(), assert_safe_extra_args(), assert_safe_token()). Rejects control chars/newlines, : in bind paths, .. traversal, dangerous env vars (LD_PRELOAD, BASH_ENV), security-override flags (--privileged, --cap-add, --network, non-loopback --host), and POSIX-quotes all Apptainer %runscript arguments.
F2 Critical Model Weight Integrity (verify_model_digest()) Directory and file digest checks did not block symbolic links (Sys.readlink()) or enforce canonical root confinement, allowing symlink escape (model_dir/shard -> /etc/passwd) or ../ traversal. assert_path_confined() blocks .. segments, rejects symbolic links by default (allow_symlinks = FALSE), walks intermediate path components inside model_dir, and verifies canonical normalizePath() containment within root_dir.
F3 High Air-Gap SSRF / URL Parser (is_loopback_endpoint(), preflight_isolation_check()) trimws() ran before whitespace validation (allowing trailing \r\n CRLF) and PCRE $ matched before trailing \n (unix:///var/run/llm.sock\n); backslashes, # fragments, % authority encoding, and case-variant proxy variables (Http_Proxy, SOCKS_PROXY) were insufficiently constrained; active outbound proxies only issued an advisory warning instead of failing closed. classify_endpoint_strict() validates raw byte range (0x21..0x7e, immune to PCRE $ trailing-newline quirks) prior to parsing, rejects \, #, @, %, control chars/CRLF, IPv6-mapped IPv4 ([::ffff:169.254.169.254], [::ffff:7f00:1]), non-canonical IPv6 ([0:0:0:0:0:0:0:1]), octal/hex/decimal/shorthand IPv4 notations (0177.0.0.1, 2130706433, 0x7f000001, 127.1), trailing dots, and DNS-rebinding domains. detect_outbound_proxies() audits all *_proxy env vars case-insensitively and fails closed by default (strict_proxy = TRUE) unless NO_PROXY explicitly lists both 127.0.0.1 and localhost.
F4 High Cryptographic Vault (pii_vault_save(), pii_vault_load()) Vault v1 used ad-hoc SHA-256 key derivation without per-save salt, lacked AAD binding over envelope metadata, and compared MAC hex strings via short-circuit identical() (timing side channel). Vault v2 (airgapllm_vault_v2) implements RFC 5869 HKDF-SHA256 (hkdf_sha256()) deriving completely separate pseudonymization, per-save AES-256-CBC encryption, and per-save HMAC-SHA256 keys from a fresh 128-bit random salt and fresh 128-bit random IV; authenticates full AAD (format|cipher|vault_id|key_fingerprint|salt|iv|ct); enforces constant-time MAC verification (constant_time_equal()) strictly BEFORE decryption; emits a uniform authentication error (defeating padding oracles); and enforces 0600 file permissions.
F5 High PII Evasion, HIPAA Safe Harbor & Algorithmic DoS (R/pii.R) Adversarial zero-width joiners/spaces (U+200B, U+FEFF, U+00AD), Unicode dashes (U+2011, U+2212), fullwidth ASCII, and Cyrillic/Greek homoglyphs bypassed regex detection; email lookahead (?![A-Za-z0-9._%+-]) missed emails immediately followed by a sentence-ending period (.); HIPAA Safe Harbor rules for ages > 89 and geographic ZIP codes (including the 17 HHS restricted 3-digit prefixes) were missing; O(M²) overlap resolution and O(N·M) span replacement plus unbounded regex quantifiers caused multi-second stalls on 50 KB dense inputs. Index-preserving Unicode canonicalizer (canonicalize_pii_text()) maps homoglyphs/fullwidth/dashes and strips invisible obfuscators in O(n) while restoring exact original offsets; fixed email trailing lookahead to handle sentence-ending periods cleanly; added HIPAA Safe Harbor age_over_89 and zip_code (with hipaa_restricted_zip3()) to default entities; bounded all regex quantifiers, replaced multi-alternation IPv6 regex with linear structural validation, and rewrote resolve_overlapping_spans() to O(M log M) (findInterval + O(1) fast-path) and apply_span_replacements() to vectorized O(N + M) C-level slicing.
F6 High Prompt Injection & Post-Inference Leakage (R/extract.R) Raw text embedded directly into prompts without boundary delimiters or breakout escaping; model outputs were not scanned post-inference for echoed/memorized PII; raw enum values inside validation errors could be written into checkpoint .error fields. Explicit <UNTRUSTED_RESEARCH_RECORD> data-boundary framing with tag-breakout neutralization (neutralize_prompt_delimiters()) and hardened runtime system prompts; added post-inference output PII leakage scanning (output_pii_action = c("redact", "error", "warn", "none")) tracking aggregate output_pii_leaks in manifests/audit logs; sanitized and PII-scrubbed checkpoint .error messages before writing to disk (sanitize_checkpoint_error()).
F7 Medium Checkpoint & Audit Byte Integrity (R/extract.R, R/audit.R) readLines() on raw files could fail unpredictably on truncated multi-byte UTF-8 or embedded NUL bytes; audit hash equality used non-constant-time identical(). Raw byte-level JSONL reader (read_jsonl_raw_lines()) detects NUL bytes and invalid UTF-8 deterministically: checkpoints gracefully recover truncated trailing UTF-8/JSON crash writes while failing closed on mid-file corruption; audit_log_verify() uses constant_time_equal() and flags any NUL/UTF-8 corruption as tampered.

3. Cryptographic Architecture Summary

  • Key Derivation: RFC 5869 HKDF-SHA256 with domain-separated info strings:
    • Pseudonymization HMAC key: salt = "airgapllm-v2-pseudonym-salt", info = "airgapllm:pseudonym:hmac-sha256".
    • Per-save Vault Encryption key: fresh 128-bit random salt_b64, info = "airgapllm:vault:aes-256-cbc:v2".
    • Per-save Vault Authentication key: fresh 128-bit random salt_b64, info = "airgapllm:vault:hmac-sha256:v2".
  • Authenticated Encryption (Vault v2): Encrypt-then-MAC (AES-256-CBC with fresh 128-bit IV + HMAC-SHA256 over AAD || salt || iv || ciphertext), verified in constant time before decryption.
  • Audit Trail Chain: Canonical key-sorted JSON serialized in UTF-8, chained from "GENESIS" via SHA-256, verified in constant time across sequence continuity, chain links, and strict zero-PII schema allowlists.
  • File Permissions: Vault files are written atomically (tmp -> chmod 0600 -> rename -> chmod 0600).

4. Responsible Security Reporting

If you discover a security vulnerability, air-gap bypass, PII leakage vector, or cryptographic weakness in airgapllm, please report it privately to the maintainer (marcus.harris.uconn@gmail.com) or open an advisory at https://github.com/MarcusHarrisUConn/airgapllm/security rather than posting sensitive clinical examples publicly.