# @suaveplan/security-codes - Detect and sanitise sensitive security-code leakage in strings: API keys, JWTs, credit cards, GitHub tokens, Stripe keys, SSH keys, PEM blocks, AWS access keys, and more ## Summary Detect and sanitise sensitive security-code leakage in strings. Handles API keys, JWTs, credit cards, GitHub tokens, Stripe keys, SSH keys, PEM blocks, AWS access keys, OpenAI keys, Google API keys, and high-entropy heuristics. ## Documentation tree - [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_ - [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_ - [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_ - [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_ - [errors](./src/errors/security-codes-error.md) — _(no submodules)_ - [security-codes-error](./src/errors/security-codes-error.md) — _(no submodules)_ - [aws](./src/patterns/aws.md) — Detects AWS Access Key IDs within arbitrary string input. AWS Access Key IDs are 20-character alphanumeric identifiers… - [credit-card](./src/patterns/credit-card.md) — Detects credit card numbers embedded in arbitrary strings using a combination of regex matching and the Luhn checksum a… - [entropy](./src/patterns/entropy.md) — Detects high-entropy strings that are likely secret tokens, API keys, or passwords using Shannon entropy analysis. This… - [github](./src/patterns/github.md) — Detects GitHub Personal Access Tokens (PATs) — both classic tokens (`ghp_…`) and the newer fine-grained tokens (`github… - [google](./src/patterns/google.md) — Detects Google API keys embedded in arbitrary strings. Google API keys begin with the well-known prefix `AIza` and are… - [jwt](./src/patterns/jwt.md) — Detects JSON Web Tokens (JWTs) embedded in arbitrary strings. JWTs are bearer tokens with a well-defined three-part bas… - [openai](./src/patterns/openai.md) — Detects OpenAI API keys in arbitrary strings. OpenAI API keys follow the format `sk-<48 chars>` for standard keys and `… - [pem](./src/patterns/pem.md) — Detects PEM-encoded blocks in arbitrary strings. PEM (Privacy Enhanced Mail) is the standard encoding for TLS certifica… - [ssh](./src/patterns/ssh.md) — Detects SSH private keys and public keys embedded in arbitrary strings. SSH private keys grant direct shell access to a… - [stripe](./src/patterns/stripe.md) — Detects Stripe API keys — both secret keys (`sk_live_` / `sk_test_`) and publishable keys (`pk_live_` / `pk_test_`) — e… - [types](./src/types/security-codes.md) — _(no submodules)_ - [security-codes](./src/types/security-codes.md) — _(no submodules)_ - [utils](./src/utils/luhn.md) — _(no submodules)_ - [luhn](./src/utils/luhn.md) — _(no submodules)_ - [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [errors](./src/errors/security-codes-error.md) — _(no submodules)_- [security-codes-error](./src/errors/security-codes-error.md) — _(no submodules)_- [aws](./src/patterns/aws.md) — Detects AWS Access Key IDs within arbitrary string input. AWS Access Key IDs are 20-character alphanumeric identifiers… - [credit-card](./src/patterns/credit-card.md) — Detects credit card numbers embedded in arbitrary strings using a combination of regex matching and the Luhn checksum a… - [entropy](./src/patterns/entropy.md) — Detects high-entropy strings that are likely secret tokens, API keys, or passwords using Shannon entropy analysis. This… - [github](./src/patterns/github.md) — Detects GitHub Personal Access Tokens (PATs) — both classic tokens (`ghp_…`) and the newer fine-grained tokens (`github… - [google](./src/patterns/google.md) — Detects Google API keys embedded in arbitrary strings. Google API keys begin with the well-known prefix `AIza` and are… - [jwt](./src/patterns/jwt.md) — Detects JSON Web Tokens (JWTs) embedded in arbitrary strings. JWTs are bearer tokens with a well-defined three-part bas… - [openai](./src/patterns/openai.md) — Detects OpenAI API keys in arbitrary strings. OpenAI API keys follow the format `sk-<48 chars>` for standard keys and `… - [pem](./src/patterns/pem.md) — Detects PEM-encoded blocks in arbitrary strings. PEM (Privacy Enhanced Mail) is the standard encoding for TLS certifica… - [ssh](./src/patterns/ssh.md) — Detects SSH private keys and public keys embedded in arbitrary strings. SSH private keys grant direct shell access to a… - [stripe](./src/patterns/stripe.md) — Detects Stripe API keys — both secret keys (`sk_live_` / `sk_test_`) and publishable keys (`pk_live_` / `pk_test_`) — e… - [types](./src/types/security-codes.md) — _(no submodules)_- [security-codes](./src/types/security-codes.md) — _(no submodules)_- [utils](./src/utils/luhn.md) — _(no submodules)_- [luhn](./src/utils/luhn.md) — _(no submodules)_- [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [errors](./src/errors/security-codes-error.md) — _(no submodules)_- [security-codes-error](./src/errors/security-codes-error.md) — _(no submodules)_- [aws](./src/patterns/aws.md) — Detects AWS Access Key IDs within arbitrary string input. AWS Access Key IDs are 20-character alphanumeric identifiers… - [credit-card](./src/patterns/credit-card.md) — Detects credit card numbers embedded in arbitrary strings using a combination of regex matching and the Luhn checksum a… - [entropy](./src/patterns/entropy.md) — Detects high-entropy strings that are likely secret tokens, API keys, or passwords using Shannon entropy analysis. This… - [github](./src/patterns/github.md) — Detects GitHub Personal Access Tokens (PATs) — both classic tokens (`ghp_…`) and the newer fine-grained tokens (`github… - [google](./src/patterns/google.md) — Detects Google API keys embedded in arbitrary strings. Google API keys begin with the well-known prefix `AIza` and are… - [jwt](./src/patterns/jwt.md) — Detects JSON Web Tokens (JWTs) embedded in arbitrary strings. JWTs are bearer tokens with a well-defined three-part bas… - [openai](./src/patterns/openai.md) — Detects OpenAI API keys in arbitrary strings. OpenAI API keys follow the format `sk-<48 chars>` for standard keys and `… - [pem](./src/patterns/pem.md) — Detects PEM-encoded blocks in arbitrary strings. PEM (Privacy Enhanced Mail) is the standard encoding for TLS certifica… - [ssh](./src/patterns/ssh.md) — Detects SSH private keys and public keys embedded in arbitrary strings. SSH private keys grant direct shell access to a… - [stripe](./src/patterns/stripe.md) — Detects Stripe API keys — both secret keys (`sk_live_` / `sk_test_`) and publishable keys (`pk_live_` / `pk_test_`) — e… - [types](./src/types/security-codes.md) — _(no submodules)_- [security-codes](./src/types/security-codes.md) — _(no submodules)_- [utils](./src/utils/luhn.md) — _(no submodules)_- [luhn](./src/utils/luhn.md) — _(no submodules)_- [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [errors](./src/errors/security-codes-error.md) — _(no submodules)_- [security-codes-error](./src/errors/security-codes-error.md) — _(no submodules)_- [aws](./src/patterns/aws.md) — Detects AWS Access Key IDs within arbitrary string input. AWS Access Key IDs are 20-character alphanumeric identifiers… - [credit-card](./src/patterns/credit-card.md) — Detects credit card numbers embedded in arbitrary strings using a combination of regex matching and the Luhn checksum a… - [entropy](./src/patterns/entropy.md) — Detects high-entropy strings that are likely secret tokens, API keys, or passwords using Shannon entropy analysis. This… - [github](./src/patterns/github.md) — Detects GitHub Personal Access Tokens (PATs) — both classic tokens (`ghp_…`) and the newer fine-grained tokens (`github… - [google](./src/patterns/google.md) — Detects Google API keys embedded in arbitrary strings. Google API keys begin with the well-known prefix `AIza` and are… - [jwt](./src/patterns/jwt.md) — Detects JSON Web Tokens (JWTs) embedded in arbitrary strings. JWTs are bearer tokens with a well-defined three-part bas… - [openai](./src/patterns/openai.md) — Detects OpenAI API keys in arbitrary strings. OpenAI API keys follow the format `sk-<48 chars>` for standard keys and `… - [pem](./src/patterns/pem.md) — Detects PEM-encoded blocks in arbitrary strings. PEM (Privacy Enhanced Mail) is the standard encoding for TLS certifica… - [ssh](./src/patterns/ssh.md) — Detects SSH private keys and public keys embedded in arbitrary strings. SSH private keys grant direct shell access to a… - [stripe](./src/patterns/stripe.md) — Detects Stripe API keys — both secret keys (`sk_live_` / `sk_test_`) and publishable keys (`pk_live_` / `pk_test_`) — e… - [types](./src/types/security-codes.md) — _(no submodules)_- [security-codes](./src/types/security-codes.md) — _(no submodules)_- [utils](./src/utils/luhn.md) — _(no submodules)_- [luhn](./src/utils/luhn.md) — _(no submodules)_- [code-detector](./src/core/code-detector/code-detector.md) — _(no submodules)_- [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_ - [code-sanitizer](./src/core/code-sanitizer/code-sanitizer.md) — _(no submodules)_- [errors](./src/errors/security-codes-error.md) — _(no submodules)_ - [security-codes-error](./src/errors/security-codes-error.md) — _(no submodules)_- [aws](./src/patterns/aws.md) — Detects AWS Access Key IDs within arbitrary string input. AWS Access Key IDs are 20-character alphanumeric identifiers… - [credit-card](./src/patterns/credit-card.md) — Detects credit card numbers embedded in arbitrary strings using a combination of regex matching and the Luhn checksum a… - [entropy](./src/patterns/entropy.md) — Detects high-entropy strings that are likely secret tokens, API keys, or passwords using Shannon entropy analysis. This… - [github](./src/patterns/github.md) — Detects GitHub Personal Access Tokens (PATs) — both classic tokens (`ghp_…`) and the newer fine-grained tokens (`github… - [google](./src/patterns/google.md) — Detects Google API keys embedded in arbitrary strings. Google API keys begin with the well-known prefix `AIza` and are… - [jwt](./src/patterns/jwt.md) — Detects JSON Web Tokens (JWTs) embedded in arbitrary strings. JWTs are bearer tokens with a well-defined three-part bas… - [openai](./src/patterns/openai.md) — Detects OpenAI API keys in arbitrary strings. OpenAI API keys follow the format `sk-<48 chars>` for standard keys and `… - [pem](./src/patterns/pem.md) — Detects PEM-encoded blocks in arbitrary strings. PEM (Privacy Enhanced Mail) is the standard encoding for TLS certifica… - [ssh](./src/patterns/ssh.md) — Detects SSH private keys and public keys embedded in arbitrary strings. SSH private keys grant direct shell access to a… - [stripe](./src/patterns/stripe.md) — Detects Stripe API keys — both secret keys (`sk_live_` / `sk_test_`) and publishable keys (`pk_live_` / `pk_test_`) — e… - [types](./src/types/security-codes.md) — _(no submodules)_ - [security-codes](./src/types/security-codes.md) — _(no submodules)_- [utils](./src/utils/luhn.md) — _(no submodules)_ - [luhn](./src/utils/luhn.md) — _(no submodules)_ ## Features - **10 built-in pattern detectors** covering the most common secret types - **Pluggable detector API** — register custom patterns at runtime - **4 masking strategies** — full-redact, partial, hash, tokenize - **Overlap deduplication** — higher-confidence matches win - **OTel metrics** — `security_codes.detect.total` and `security_codes.detect.duration_ms` - __Zero @suaveplan/_ runtime dependencies_* — leaf package, no circular risk ## Install ```bash bun add @suaveplan/security-codes ``` ## Quick Start ```ts import { SecurityCodeDetector, SecurityCodeSanitizer } from '@suaveplan/security-codes'; const detector = new SecurityCodeDetector(); const matches = detector.detect('aws_key=AKIAIOSFODNN7EXAMPLE'); const sanitizer = new SecurityCodeSanitizer(); const { output } = sanitizer.sanitize('aws_key=AKIAIOSFODNN7EXAMPLE'); // output === 'aws_key=[REDACTED]' ``` ## Module Docs - [Types](src/types/security-codes.md) - [Luhn utility](src/utils/luhn.md) - [AWS pattern](src/patterns/aws.md) - [JWT pattern](src/patterns/jwt.md) - [Stripe pattern](src/patterns/stripe.md) - [GitHub pattern](src/patterns/github.md) - [Google pattern](src/patterns/google.md) - [OpenAI pattern](src/patterns/openai.md) - [Credit Card pattern](src/patterns/credit-card.md) - [PEM pattern](src/patterns/pem.md) - [SSH pattern](src/patterns/ssh.md) - [Entropy pattern](src/patterns/entropy.md) - [SecurityCodeDetector](src/core/code-detector/code-detector.md) - [SecurityCodeSanitizer](src/core/code-sanitizer/code-sanitizer.md)