PromptShield Pro 如何在 Node.js 中零依賴地本機阻擋提示詞注入、Base64 越獄及 API 金鑰洩漏
How to Block Prompt Injection, Base64 Jailbreaks & API Key Leaks Locally in Node.js (Zero Dependencies)
PromptShield Pro 是供 Node.js >= 18 使用、零執行期依賴的本機 LLM 安全防火牆,聲稱可在 <1ms 阻擋提示詞注入、Base64 指令及分隔符偽裝。它可掃描 16+ 種憑證與個人資料格式,在呼叫 LLM 前遮蓋資料,並透過 restoreRedacted() 還原;工具亦提供提示詞壓縮和安全檢查。免費入門版售價 $0+,完整工具包售價 $29。
Every week, another AI wrapper or internal RAG tool accidentally leaks a production sk-proj-... key, customer SSN, or database URI to a third-party LLM provider—or gets tricked by a <|im_start|>system delimiter injection.
Most teams either ignore the problem or add a heavy 300ms external guardrail API call on every request.
To solve this locally in <1ms with zero runtime dependencies, I built PromptShield Pro—a local-first LLM Security Firewall, Reversible PII Redactor, Multi-Model Cost Simulator, and 30-Template Production System Prompt Vault.
🛡️ What It Catches Locally
16+ Credential & PII Formats (with Reversible Redaction):
Scans for OpenAI (sk-proj-...), Anthropic (sk-ant-...), Gemini, AWS (AKIA...), GitHub, Stripe, and Slack keys, PostgreSQL/MongoDB connection URIs, JWTs, Luhn-verified credit cards, SSNs, and emails—replacing them with[REDACTED_...]tokens before calling the LLM and restoring them afterward viarestoreRedacted().Multi-Layer Prompt Injection & Obfuscation Firewall:
Detects direct instruction overrides, DAN/DevMode personas, system prompt extraction attempts, XML/ChatML delimiter spoofing, markdown image webhook exfiltration, Base64-encoded instructions, and invisible zero-width character steganography.Deterministic Prompt Compressor & Linter:
Strips conversational filler and lints missing JSON schemas or unisolated{{variables}}, saving 15%–35% on input tokens.Multi-Model Cost & Prompt Caching Simulator:
Compares monthly spend and prompt-caching savings across GPT-4o, o3-mini, Claude 3.7 Sonnet, Gemini 2.5 Pro/Flash, DeepSeek V3, and Llama 3.3 70B.
💻 Quick Example (Zero Dependencies in Node.js >= 18)
const { scanAndRedact, inspectPromptSecurity, compressPrompt } = require('./src/index');
// 1. Mask API keys, DB URIs, and PII before calling any LLM API
const { redactedText, vaultMap } = scanAndRedact(userPrompt);
// 2. Block Prompt Injections, Delimiter Escapes & Base64 Jailbreaks
const security = inspectPromptSecurity(redactedText);
if (security.blocked) {
throw new Error(`Blocked adversarial prompt (${security.riskLevel})`);
}
// 3. Strip token bloat & wrap in hardened XML data boundary
const { compressedText } = compressPrompt(redactedText);
🚀 Try the Free CLI Starter or Grab the Complete Toolkit
I've released a Free Starter Edition ($0+) with the CLI scanner, 5 starter system prompts, and the 30-case Red-Team benchmark suite, alongside the PromptShield Pro Complete Toolkit ($29) which includes the Offline Interactive Web Studio (studio/index.html) and all 30 Schema-Enforced Production System Prompts across 6 engineering categories:
👉 Download PromptShield Lite (Free) or PromptShield Pro on Gumroad
Would love any feedback from the community on additional secret formats or adversarial injection patterns you'd like to see added!
來源:DEV Community · dev.to