Hard-coded Cryptographic Key
Summary
This is CWE-321, the signing- and encryption-key-specific instance of the hard-coded-credentials family: a private key, a TLS certificate's private half, an SSH key, or a symmetric signing secret used for something like JWT tokens, is embedded directly in shipped code rather than generated uniquely per deployment. The impact scales differently than a hard-coded password: a shared signing key doesn't just grant access to one account, it lets anyone who extracts it forge cryptographically valid tokens, certificates, or signatures for every single deployment of that codebase. A particularly common real-world instance is a JWT signing secret copied verbatim from a library's documentation or example code and never changed. Because JWT verification only checks that a signature matches the configured secret, and doesn't inherently know or care whether that secret is unique, a documentation example secret used unchanged in production is functionally identical to publishing the signing key outright.
Top Affected Components / Targets
- JWT-based authentication using a signing secret copied from documentation or example code
- Mobile app binaries and JS bundles containing an embedded TLS or API-signing private key
- Public source repositories with a committed PEM-format private key file
Common Attack Vectors
- Scan JS bundles, mobile binaries, and public repositories for PEM-format key headers and well-known example signing secrets from popular libraries' documentation
- Where a JWT signing secret is suspected of being a common example value, attempt to forge a token signed with that known value and test whether the application accepts it
Common Payloads
-----BEGIN RSA PRIVATE KEY-----,-----BEGIN EC PRIVATE KEY-----,-----BEGIN OPENSSH PRIVATE KEY-----as pattern markers to search for in exposed files and bundles- A JWT re-signed with a well-known example or documentation-default signing secret, tested against the application's own token verification
Detection Strategy
Scan JS bundles, source maps, mobile binaries, and public repositories for PEM-format private key headers, treating any match as a high-severity finding regardless of context, since there's no legitimate reason a private key should ever ship in client-reachable code. Separately, for applications using JWT, test whether a token signed with a small set of well-known example signing secrets (ones that appear verbatim in popular library documentation) is accepted, since this is a surprisingly common real-world instance of this bug.
Tip: Testing tools that run these checks in parallel across every discovered endpoint can cut the time required substantially compared to fully manual testing, as long as they confirm findings with more than one signal to keep the false-positive rate down.
False-Positive Notes
A key found in a test fixture or example directory clearly marked as such, and not reachable in any production code path, carries different risk than the same key pattern found in a live, deployed bundle; confirm the key is genuinely reachable in production before treating it as a live credential exposure.
How to Test
Manual Testing Methodology
Here is a systematic approach to identifying Hard-coded Cryptographic Key vulnerabilities in a target application.
Before testing, map all input vectors that could be affected. Identify parameters, headers, cookies, and request bodies that interact with the vulnerable component. A proxy such as Burp Suite or OWASP ZAP, paired with normal browsing of the target, is usually enough to build this list.
Send a legitimate request and record the normal response: status code, content length, response time, and any identifying tokens. This baseline matters because it's what you'll compare later responses against once payloads are involved.
Inject test payloads into each identified input vector one at a time. Start with benign detection payloads before escalating to anything that could actually trigger the vulnerability. For Hard-coded Cryptographic Key specifically, search publicly reachable source (client-side JS bundles, mobile app binaries, public repositories, exposed .git directories) for API keys, connection strings, and hard-coded passwords, and separately try any vendor-published default credentials against the target's login and admin interfaces.
Compare the response against your baseline, looking specifically for a live credential or key found in source that successfully authenticates against the corresponding service, or a default credential pair that logs in without being changed.
Once a potential vulnerability is detected, confirm it with at least a few independent test cases to rule out coincidence. Document the exact request and response as proof. For Hard-coded Cryptographic Key, a confirmed finding typically means showing that attacker-controlled input changes the application's behavior in a way that matters for security, not just that a payload was reflected somewhere harmless.
Real-World Impact
Real-World Impact
Hard-coded and weakly-protected credentials give an attacker a direct path to whatever the credential guards — a database, an internal API, a cloud account, or the application itself — without needing to find or exploit a code-level bug at all. A secret committed to source control remains exploitable even after it's later removed, since it persists in git history indefinitely unless the repository is actively scrubbed and the credential rotated.
Default credentials left in place after deployment are a perennial finding for exactly the same reason: they require no discovery beyond checking the vendor's published defaults, and they're routinely still valid in production.
Weakly hashed or reversibly "encrypted" passwords compound the damage of any other breach — a database dump that would otherwise only expose hashes needing significant offline cracking effort instead hands over plaintext-equivalent credentials immediately, and because of password reuse, that damage extends well beyond the breached application itself.
Prevention & Remediation
Prevention and Secure Coding
Preventing Hard-coded Cryptographic Key takes a defense-in-depth approach — no single control below is sufficient alone, but together they close off both the primary path and the most common bypasses.
Secrets manager, not source control. Store credentials, API keys, and cryptographic keys in a dedicated secrets manager (Vault, cloud KMS, or equivalent) and inject them at runtime — never commit them to a repository, config file, or container image.
Rotate anything ever exposed. A credential that was ever committed, even briefly, should be treated as compromised and rotated — removing it from the latest commit does not remove it from history.
No shipped default credentials. Force a credential-setup step on first run rather than shipping a default username/password that some deployments will never change.
Modern password hashing, always. Hash passwords with bcrypt, scrypt, or Argon2 with a per-user salt — never store them in plaintext or with reversible encryption, and never with an unsalted or fast general-purpose hash like unsalted SHA-256.
Automated secret-scanning in CI. A pre-commit or CI secret-scanner catches an accidental credential commit before it reaches a shared branch, which is far cheaper than a post-hoc rotation.