CWE-798: Hard-coded credentials | Causes and Fixes Skip to content

Security weakness

CWE-798 Hard-coded credentials

Passwords, API keys or secret keys are written directly into your code, where others can find and reuse them.

  • Senior security engineers
  • 540+ projects delivered
  • Reply within one business day

Quick answer

What is CWE-798?

Use of Hard-coded Credentials: The product contains hard-coded credentials, such as a password or cryptographic key.

Business impact

What CWE-798 could cost your business

MITRE documents what this weakness can do. Here is what that means for a website, store or app.

Confidentiality

Private data exposed

Customer records, credentials, orders or internal files can be read by people who should never see them.

  • Read Application Data
  • Gain Privileges or Assume Identity
  • Execute Unauthorized Code or Commands

Integrity

Data, pages or code changed

Prices, orders, content or the code your site runs can be altered without your approval.

  • Read Application Data
  • Gain Privileges or Assume Identity
  • Execute Unauthorized Code or Commands

Availability

Downtime and lost sales

Crashes, slowdowns or exhausted resources can take your site, store or app offline.

  • Read Application Data
  • Gain Privileges or Assume Identity
  • Execute Unauthorized Code or Commands

Access Control

Accounts and admin areas exposed

Logins and permission checks can be bypassed, putting admin and customer accounts at risk.

  • Bypass Protection Mechanism
  • Read Application Data
  • Gain Privileges or Assume Identity

In plain English

What Hard-coded credentials means for your business

  • 540+projects delivered
  • 9+years in business
  • 23+certified experts
Get a free security check

A senior engineer replies within one business day.

A hard-coded credential is a password, API key, token or encryption key typed straight into source code or a file shipped with the product. It is convenient during development, which is why it happens so often. The trouble is that code gets copied, shared, backed up and published. Anyone who can read the code, including a former contractor or a stranger browsing a public repository, can read the secret too.

For a business, a leaked key can mean someone else sending email as you, issuing refunds, reading your database or running up cloud charges on your account. Secrets inside mobile apps and browser JavaScript are especially exposed, because the code is delivered to every user. Hard-coded secrets are also difficult to change. Rotating one means editing and redeploying code, so compromised keys often stay in use longer than they should.

Where it shows up

  • Payment, email or shipping API keys pasted into theme files, plugin code or configuration files that are committed to a Git repository.
  • Secret keys embedded in front-end JavaScript or mobile app packages, where any user can extract them with freely available tools.
  • Database passwords and access keys stored in deployment scripts, container images, backups or shared documents instead of a protected secret store.
  • Default administrator accounts or built-in support passwords shipped with a plugin, theme, device or self-hosted application and never changed after installation.

Free security check

Is CWE-798 hiding in your site?

A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.

Official definition

How MITRE defines CWE-798

Use of Hard-coded Credentials

The product contains hard-coded credentials, such as a password or cryptographic key.

Weakness ID
CWE-798
Type
Base
Status
Draft
Likelihood of exploit
High
Applies to
Python, Mobile, ICS/OT
Introduced during
Architecture and Design

Fix it

How to fix Hard-coded credentials

Practical steps in priority order. Share them with your developer or agency.

  1. Move secrets out of code

    Load credentials at runtime from environment variables or a dedicated secrets manager. Keep configuration files that hold secrets out of version control and outside the web root, readable only by the application account.

  2. Rotate any secret already exposed

    Treat every credential that has appeared in code, a repository or a build as compromised. Issue a new one and revoke the old one. Deleting the line is not enough, because repository history keeps it.

  3. Scan for secrets automatically

    Add secret scanning to pre-commit hooks and your build pipeline so commits containing keys are blocked. Turn on your code host’s secret detection and push protection, and scan existing history once.

  4. Keep secrets off the client

    Never place secret keys in browser JavaScript or mobile apps. Route calls to third-party services through your own server, and use only publishable keys that the provider designs to be public on the client.

  5. Limit what each key can do

    Create separate credentials per environment and per service, each with the minimum permissions needed. Remove default accounts, force a password change at first setup, and restrict keys by IP address or domain where supported.

Signs you may be affected

  • Searching your codebase for words like password, secret or key returns real values.
  • The same key or password is used across development, staging and production.
  • A provider warns you about an exposed key, or you see unexplained API usage.

Questions to ask your developer

  • Where are our API keys and database passwords stored, and who can read them?
  • Has our code repository ever contained a real password, token or key?
  • How quickly could we rotate every secret if one leaked today?

Prevention

What MITRE recommends, phase by phase

Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.

  1. 01

    Architecture and Design

    • For outbound authentication: store passwords, keys, and other credentials outside of the code in a strongly-protected, encrypted configuration file or database that is protected from access by all outsiders, including other local users on the same system. Properly protect the key (CWE-320). If you cannot use encryption to protect the file, then make sure that the permissions.
    • For inbound authentication: Rather than hard-code a default username and password, key, or other authentication credentials for first time logins, utilize a "first login" mode that requires the user to enter a unique strong password or key.
    • If the product must contain hard-coded credentials or they cannot be removed, perform access control checks and limit which entities can access the feature that requires the hard-coded credentials. For example, a feature might only be enabled through the system console instead of through a network connection.
    Show 2 more recommendations
    • For inbound authentication using passwords: apply strong one-way hashes to passwords and store those hashes in a configuration file or database with appropriate access control. That way, theft of the file/database still requires the attacker to try to crack the password. When handling an incoming password during authentication, take the hash of the password and compare it to.
    • For front-end to back-end connections: Three solutions are possible, although none are complete. The first suggestion involves the use of generated passwords or keys that are changed automatically and must be entered at given time intervals by a system administrator. These passwords will be held in memory and only be valid for the time intervals. Next, the passwords or keys.

Detection and evidence

How CWE-798 is found, and where it has hit

The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.

How it is detected

  • Black BoxCredential storage in configuration files is findable using black box methods, but the use of hard-coded credentials for an incoming authentication routine typically involves an account that is not visible outside of the code.
  • Automated Static AnalysisAutomated white box techniques have been published for detecting hard-coded credentials for incoming authentication, but there is some expert disagreement regarding their effectiveness and applicability to a broad range of methods.
  • Manual Static AnalysisThis weakness may be detectable using manual code analysis. Unless authentication is decentralized and applied throughout the product, there can be sufficient time for the analyst to find incoming authentication routines and examine the program logic looking for usage of hard-coded credentials.
  • Manual Dynamic AnalysisFor hard-coded credentials in incoming authentication: use monitoring tools that examine the product’s process as it interacts with the operating system and the network. This technique is useful in cases when source code is unavailable, if the product was not developed by you, or if you want to.
  • Automated Static Analysis – Binary or BytecodeAccording to SOAR [REF-1479], the following detection techniques may be useful: Bytecode Weakness Analysis – including disassembler + source code weakness analysis Binary Weakness Analysis – including disassembler + source code weakness analysis

Real vulnerabilities it caused

  • CVE-2022-40263Software for biological cell analysis has hard-coded credentials, leading to leak of Protected Health Information (PHI)
  • CVE-2022-29953Condition Monitor firmware has a maintenance interface with hard-coded credentials
  • CVE-2022-29960Engineering Workstation uses hard-coded cryptographic keys that could allow for unauthorized filesystem access and privilege escalation
  • CVE-2022-29964Distributed Control System (DCS) has hard-coded passwords for local shell access
  • CVE-2022-30997Programmable Logic Controller (PLC) has a maintenance service that uses undocumented, hard-coded credentials
  • CVE-2022-30314Firmware for a Safety Instrumented System (SIS) has hard-coded credentials for access to boot configuration

How we fix it

From finding to fixed: how Codefreex closes CWE-798

  1. 01

    Scan and confirm

    We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.

  2. 02

    Fix at the source

    We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.

  3. 03

    Verify the fix

    We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.

  4. 04

    Keep it fixed

    Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.

FAQ

CWE-798: FAQs

Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.

How serious are hard-coded credentials?

The severity matches what the credential unlocks. A read-only key for a minor service is a small issue. A database password, payment secret or cloud access key can expose customer data or allow real financial damage. MITRE rates the likelihood of exploitation as high, since extracting a secret from code usually takes little effort.

How do I prevent secrets from ending up in code?

Give developers an easy, approved place to put them. Use environment variables or a secrets manager from the first day of a project, and provide example configuration files with blank values. Add automated secret scanning to commits and builds. Make rotation routine, so replacing a key is a quick task instead of a risky project.

Our repository is private. Is that safe enough?

No. A private repository reduces exposure but does not remove it. Every developer, contractor, build system and connected tool with access can read the secrets, and so can anyone who obtains a copy of the code or a backup. Repositories are also sometimes made public or shared by mistake. Keep credentials out of code regardless.

What is CWE-798?

CWE-798, “Use of Hard-coded Credentials”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. The product contains hard-coded credentials, such as a password or cryptographic key.

How serious is CWE-798?

MITRE rates the likelihood of exploit as High. It can affect access control, integrity, confidentiality, availability, with impacts such as bypass protection mechanism, read application data, gain privileges or assume identity. The real risk depends on where the weakness sits and what data or functions it exposes.

How do you prevent CWE-798?

For outbound authentication: store passwords, keys, and other credentials outside of the code in a strongly-protected, encrypted configuration file or database that is protected from access by all outsiders, including other local users on the same system. For inbound authentication: Rather than hard-code a default username and password, key, or other authentication credentials for first time logins, utilize a “first login” mode that requires the user.

Can Codefreex check my site for CWE-798?

Yes. A senior engineer reviews your site, store or app for CWE-798 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.

Free security check

Find out if CWE-798 affects your site

Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.

  • A senior strategist reviews your request, not a sales bot
  • Clear scope, timeline and estimate within one business day
  • Free 30-minute discovery call, no obligation
  • NDA available on request

Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.