<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khôi Nguyễn</title>
    <description>The latest articles on DEV Community by Khôi Nguyễn (@khi_nguyn_8a255f882ca1f).</description>
    <link>https://dev.to/khi_nguyn_8a255f882ca1f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4212775%2Fcaa033de-e67c-4c3e-9ff2-64c10f0ad50f.png</url>
      <title>DEV Community: Khôi Nguyễn</title>
      <link>https://dev.to/khi_nguyn_8a255f882ca1f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khi_nguyn_8a255f882ca1f"/>
    <language>en</language>
    <item>
      <title>How to Block Prompt Injection, Base64 Jailbreaks &amp; API Key Leaks Locally in Node.js (Zero Dependencies)</title>
      <dc:creator>Khôi Nguyễn</dc:creator>
      <pubDate>Wed, 28 Oct 2026 10:16:08 +0000</pubDate>
      <link>https://dev.to/khi_nguyn_8a255f882ca1f/how-to-block-prompt-injection-base64-jailbreaks-api-key-leaks-locally-in-nodejs-zero-3o6</link>
      <guid>https://dev.to/khi_nguyn_8a255f882ca1f/how-to-block-prompt-injection-base64-jailbreaks-api-key-leaks-locally-in-nodejs-zero-3o6</guid>
      <description>&lt;p&gt;Every week, another AI wrapper or internal RAG tool accidentally leaks a production &lt;code&gt;sk-proj-...&lt;/code&gt; key, customer SSN, or database URI to a third-party LLM provider—or gets tricked by a &lt;code&gt;&amp;lt;|im_start|&amp;gt;system&lt;/code&gt; delimiter injection.&lt;/p&gt;

&lt;p&gt;Most teams either ignore the problem or add a heavy 300ms external guardrail API call on every request.&lt;/p&gt;

&lt;p&gt;To solve this locally in &lt;code&gt;&amp;lt;1ms&lt;/code&gt; with &lt;strong&gt;zero runtime dependencies&lt;/strong&gt;, I built &lt;strong&gt;PromptShield Pro&lt;/strong&gt;—a local-first LLM Security Firewall, Reversible PII Redactor, Multi-Model Cost Simulator, and 30-Template Production System Prompt Vault.&lt;/p&gt;

&lt;h3&gt;
  
  
  🛡️ What It Catches Locally
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;16+ Credential &amp;amp; PII Formats (with Reversible Redaction):&lt;/strong&gt;&lt;br&gt;
Scans for OpenAI (&lt;code&gt;sk-proj-...&lt;/code&gt;), Anthropic (&lt;code&gt;sk-ant-...&lt;/code&gt;), Gemini, AWS (&lt;code&gt;AKIA...&lt;/code&gt;), GitHub, Stripe, and Slack keys, PostgreSQL/MongoDB connection URIs, JWTs, Luhn-verified credit cards, SSNs, and emails—replacing them with &lt;code&gt;[REDACTED_...]&lt;/code&gt; tokens before calling the LLM and restoring them afterward via &lt;code&gt;restoreRedacted()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Layer Prompt Injection &amp;amp; Obfuscation Firewall:&lt;/strong&gt;&lt;br&gt;
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.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deterministic Prompt Compressor &amp;amp; Linter:&lt;/strong&gt;&lt;br&gt;
Strips conversational filler and lints missing JSON schemas or unisolated &lt;code&gt;{{variables}}&lt;/code&gt;, saving &lt;strong&gt;15%–35% on input tokens&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Model Cost &amp;amp; Prompt Caching Simulator:&lt;/strong&gt;&lt;br&gt;
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.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  💻 Quick Example (Zero Dependencies in Node.js &amp;gt;= 18)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;scanAndRedact&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inspectPromptSecurity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;compressPrompt&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Mask API keys, DB URIs, and PII before calling any LLM API&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;redactedText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vaultMap&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;scanAndRedact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;userPrompt&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Block Prompt Injections, Delimiter Escapes &amp;amp; Base64 Jailbreaks&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;security&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inspectPromptSecurity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;redactedText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;security&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blocked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Blocked adversarial prompt (&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;security&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;riskLevel&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 3. Strip token bloat &amp;amp; wrap in hardened XML data boundary&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;compressedText&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;compressPrompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;redactedText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🚀 Try the Free CLI Starter or Grab the Complete Toolkit
&lt;/h3&gt;

&lt;p&gt;I've released a &lt;strong&gt;Free Starter Edition (&lt;code&gt;$0+&lt;/code&gt;)&lt;/strong&gt; with the CLI scanner, 5 starter system prompts, and the 30-case Red-Team benchmark suite, alongside the &lt;strong&gt;PromptShield Pro Complete Toolkit (&lt;code&gt;$29&lt;/code&gt;)&lt;/strong&gt; which includes the &lt;strong&gt;Offline Interactive Web Studio (&lt;code&gt;studio/index.html&lt;/code&gt;)&lt;/strong&gt; and &lt;strong&gt;all 30 Schema-Enforced Production System Prompts&lt;/strong&gt; across 6 engineering categories:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://nkhoi.gumroad.com/l/promptshield-pro" rel="noopener noreferrer"&gt;Download PromptShield Lite (Free) or PromptShield Pro on Gumroad&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Would love any feedback from the community on additional secret formats or adversarial injection patterns you'd like to see added!&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
  </channel>
</rss>
