Extensions & Privacy

Prompt Masking & Privacy Protection

In-flight local secret redaction for API keys, database URIs, and private IPs before prompts leave your machine.

When utilizing modern AI coding assistants (such as Claude Code, Codex, or Gemini CLI), developers routinely provide entire repositories and extensive context to language models. However, source code repositories frequently contain sensitive secrets:

  • Cloud provider access keys, personal access tokens, or third-party credentials (sk-..., ghp_..., AWS secrets);
  • Production or staging database connection URIs (postgres://user:password@...);
  • Corporate internal domain names, private subnet IP addresses, and private microservice endpoints;
  • Core employee emails, private company infrastructure, or trade-secret proprietary algorithms.

Transmitting raw, unmasked code to remote overseas public cloud LLMs poses severe data leak and compliance risks.

Magpie AI features a high-performance In-Flight Prompt Masking & Sanitization Engine. All sensitive entities are detected, redacted, and replaced with safe placeholder tokens entirely inside local RAM before requests leave your workstation.


Architecture & How It Works

Unlike post-mortem log analyzers, Magpie AI's privacy engine operates at the front of the local gateway pipeline (127.0.0.1:3425):

text
[ Developer CLI (Claude Code) ]
           │
           ▼ (1. Raw prompt & context containing sensitive secrets)
[ Magpie AI Local Gateway (127.0.0.1:3425) ]
  ┌──────────────────────────────────────────────────┐
  │   In-Memory Privacy Sanitization Pipeline        │
  │   - Detects API Keys / Auth Tokens / Passwords   │
  │   - Matches private IP subnets & internal URLs   │
  │   - Replaces with safe tokens: [MASKED_TOKEN_1]  │
  │   - Stores ephemeral RAM lookup table            │
  └────────────────────────┬─────────────────────────┘
                           │
                           ▼ (2. Redacted, sanitized payload)
              [ Cloud LLM (DeepSeek / OpenAI) ]
                           │
                           ▼ (3. Generated code or analysis response)
[ Magpie AI Local Gateway (127.0.0.1:3425) ]
  ┌──────────────────────────────────────────────────┐
  │   Context Unmasking Engine                       │
  │   - Restores placeholders back to local values   │
  └────────────────────────┬─────────────────────────┘
                           │
                           ▼ (4. Developer receives ready-to-run code)
[ Developer CLI (Claude Code) ]

Core Privacy Guarantees

  1. Zero-Disk In-Memory Execution: Pattern scanning and token replacements occur entirely in Go process memory in sub-milliseconds. Cleartext secrets are never written to disk caches.
  2. Bidirectional Transparent Restoration: When the model returns code referencing placeholder tokens, Magpie AI transparently restores them in the live SSE response stream.
  3. Zero Remote Exposure: Upstream models and intermediary networks never encounter actual passwords or private endpoints.

Out-of-the-Box Masking Rules

Magpie AI comes pre-configured with industry-standard high-risk patterns:

Secret CategoryMatching PatternSanitized Replacement
API Keys & Tokenssk-[a-zA-Z0-9]{32,}, ghp_..., AWS Access Keys[REDACTED_API_KEY_1]
Database URIspostgres://, mysql://, mongodb+srv://[REDACTED_DB_URI]
Private Keys & CertsBEGIN PRIVATE KEY, BEGIN RSA PRIVATE KEY[REDACTED_PRIVATE_KEY]
Private Subnets10.x.x.x, 172.16-31.x.x, 192.168.x.x[INTERNAL_IP_1]
Credential VariablesCommon .env assignments with passwords[REDACTED_SECRET]

Customizing Privacy Rules

You can easily adapt rules to match your organization's specific naming conventions and compliance requirements.

1. Configuration File (~/.magpie/privacy.yaml)

Define custom patterns in your local privacy configuration:

yaml
# ~/.magpie/privacy.yaml
privacy:
  enabled: true
  
  # Custom regex rules
  rules:
    - name: "Internal Corporate Domains"
      pattern: 'https?://[a-zA-Z0-9.-]+\.internal\.corp\.net'
      replacement: "[INTERNAL_CORP_URL]"
      
    - name: "Customer SSN / ID Numbers"
      pattern: '\b\d{3}-\d{2}-\d{4}\b'
      replacement: "[REDACTED_ID]"
      
    - name: "Internal Project Keys"
      pattern: 'CORP_SECRET_[A-Za-z0-9_]+'
      replacement: "[PROJECT_SECRET]"

  # Whitelist (allowed public test domains or mock keys)
  whitelist:
    - "https://api.github.com"
    - "https://test.example.com"
    - "127.0.0.1"

2. Manage via CLI

bash
# Check privacy masking status and interception counters
magpie privacy status

# Enable or disable masking
magpie privacy on
magpie privacy off

# Test sanitization against a sample string
magpie privacy test "connect to postgres://admin:secret123@10.0.1.5:5432/db"

The test command prints an instant before-and-after diff:

text
Input:  connect to postgres://admin:secret123@10.0.1.5:5432/db
Output: connect to [REDACTED_DB_URI]
✓ Successfully sanitized 2 sensitive tokens

Benefits for Enterprise Workflows

  1. Enterprise Compliance: Securely leverage models like DeepSeek or OpenAI even in strict fintech, healthcare, and enterprise environments without violating confidentiality policies.
  2. Accidental Commit Prevention: Protects engineers who accidentally leave API keys in .env files while asking an AI agent to troubleshoot.
  3. Zero Impact on Reasoning Quality: LLMs comprehend semantic placeholders like [REDACTED_DB_URI] just as well as real credentials, maintaining optimal code generation quality.

Frequently Asked Questions

Q: Does prompt masking add perceptible latency?

A: Virtually zero. Magpie's Go core uses compiled Aho-Corasick automata and optimized regex pipelines. A typical 100KB prompt context is evaluated and sanitized in 1~3 milliseconds, which is negligible compared to network round-trips.

Q: Can I run code returned by the model without manual edits?

A: Yes! When streaming responses back to your active CLI tool (like Claude Code), Magpie unmasks the placeholders automatically so local files receive real variables.

Q: How do I exempt public mock keys or safe test endpoints from being redacted?

A: Add the exempt domain, string pattern, or IP address to the whitelist array inside ~/.magpie/privacy.yaml (such as https://api.github.com or 127.0.0.1). Whitelisted entities are automatically passed through untouched.