Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To stop an LLM from leaking API keys in generated code, do not give it real keys to read. Keep credentials out of prompts and assistant-accessible files, have code retrieve them from a controlled runtime secret source, and add scanning and review before changes are committed or merged. Treat any real exposure as a credential incident: revoke or rotate the key and investigate its use.

Why “default to secret” is the right rule

Assume a credential may be exposed if it enters a coding assistant’s readable files, prompt, terminal context, or workflow. The strongest safeguard is preventing access in the first place, rather than asking the model to keep a key confidential.

A prompt is not an authorization boundary or a secret store. OWASP says, “The system prompt should not be considered a secret, nor should it be used as a security control.” OWASP LLM07:2025, System Prompt Leakage recommends treating system prompts accordingly. Restrict access outside the model and do not give an agent credentials it does not need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep real credentials out of the assistant’s context

Do not paste live keys into chat, prompts, terminal sessions visible to the assistant, source files, tests, notebooks, examples, or other project files it can inspect. Use a placeholder such as API_KEY when describing the configuration the code should read.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Exclude sensitive files—such as .env files, private keys, and credential files—from the coding tool’s context using its exclusion controls. A .gitignore entry prevents Git from tracking a file; it does not prevent a filesystem-reading assistant from opening it. OWASP’s guidance on LLM prompt injection prevention addresses limiting exposure of sensitive information to AI tools.

Have generated code retrieve secrets at runtime

Ask the assistant to write code that reads a named configuration value at runtime rather than embedding a credential literal. Supply the value through a controlled environment variable or a secrets manager integrated with the deployment environment. OWASP’s Secrets Management Cheat Sheet covers secret storage, runtime provisioning, least privilege, rotation, and revocation.

Rank #2
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
  • Give each workload only the credentials and permissions it needs for its task.
  • Keep the secret value out of logs, exception messages, test output, and generated documentation.
  • Choose a runtime secret source based on its access controls, rotation and revocation support, audit visibility, deployment integration, and operational complexity.

Review the assistant’s changes before they land

Inspect the full diff, not just the main source file. Check tests, examples, notebooks, logs, and CI configuration for credential literals or accidental forwarding of secret values. For agents with tool or CI access, restrict permissions and require approval before they access sensitive resources or modify workflows.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A prompt can ask the model not to reveal secrets, but the actual boundary must be enforced through access controls, tool permissions, and workflow settings.

Rank #3
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

Scan locally and block secrets in repository workflows

Use secret detection before commit and as a pull request check, configured to fail when it finds a detection. Local feedback can catch a mistake while it is being made; a pull request gate provides another check before merge. Select checks based on whether they cover the credential types you use, how bypasses are handled and audited, and whether they are available in your repository workflow.

Where available, GitHub push protection can block supported secret patterns at push time. GitHub explains: “With push protection, secret scanning blocks contributors from pushing secrets to a repository and generates an alert whenever a contributor bypasses the block.” See GitHub’s leak-prevention documentation. Push protection and scanners are an additional layer, not a guarantee: they recognize supported patterns and may not detect every credential or exposure route.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Respond to an exposed key as a credential incident

  1. Revoke or rotate the exposed key. Removing the line from the current file does not make a credential that was exposed safe.
  2. Remove the secret from active code and configuration. Replace it with runtime retrieval from an approved secret source.
  3. Review repository alerts and available access logs. Look for unexpected use and investigate what the credential could access.
  4. Check related workflow and assistant access. Determine whether the key appeared in prompts, logs, build output, or other assistant-readable locations, and reduce access that was not needed.

OWASP’s secrets-management guidance describes revocation, rotation, and monitoring as parts of the secret lifecycle. The right response is not merely to erase a visible string, but to make the exposed credential unusable and check for signs it was used.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Build layered controls, not a single promise

There is no single prompt, secret manager, or scanner that eliminates every route by which a key can enter model context or generated output. Keep secrets inaccessible where possible, limit agent permissions, retrieve credentials only at runtime, and use review and scanning to catch mistakes. Official guidance supports this defense-in-depth approach; it does not guarantee that every leak can be prevented.

Best Value
FIDO2 U2F Security Key Passkey Two-Factor Authentication (2FA) USB Key PIN+Touch (Non-Biometric) USB-A Type TrustKey T110
  • Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T110. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
  • Certified with the new FIDO2 standard, T110 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
  • Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
  • Fits USB-A port : Insert the T110 security key into the USB-A port of each service and log in conveniently with one touch
  • For the driver download and user guide, please visit TrustKey Solutions Home support page.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.