CWE-798: Use of Hard-coded Credentials
The product contains hard-coded credentials, such as a password or cryptographic key.
Last updated
Overview
There are two main variations:
The product contains hard-coded credentials, such as a password or cryptographic key.
Last updated
There are two main variations:
Outbound: the product connects to another system or component, and it contains hard-coded credentials for connecting to that component. This variant applies to front-end systems that authenticate with a back-end service. The back-end service may require a fixed password that can be easily discovered. The programmer may simply hard-code those back-end credentials into the front-end product.
1,672 recorded CVEs are caused by CWE-798 (Use of Hard-coded Credentials), including 10 in CISA's KEV (Known Exploited Vulnerabilities) catalog. KEVs are shown first. 361 new CWE-798 CVEs have been recorded so far in 2026 (194 in 2025).
Dell RecoverPoint for Virtual Machines (RP4VMs) Use of Hard-coded Credentials Vulnerability
Gladinet CentreStack and TrioFox Hard Coded AES Keys
Cisco Expressway Series Remote Code Execution Vulnerability
SolarWinds Web Help Desk Hardcoded Credential Vulnerability
D-Link DNS-320L/DNS-325/DNS-327L/DNS-340L HTTP GET Request nas_sharing.cgi hard-coded credentials
Atlassian Questions For Confluence App Hard-coded Credentials Vulnerability
Acclaim Systems USAHERDS Use of Hard-Coded Credentials Vulnerability
EyesOfNetwork Use of Hard-Coded Credentials Vulnerability
Zoho ManageEngine ADSelfService Plus Remote Code Execution Vulnerability
Fortinet FortiOS Use of Hard-Coded Credentials Vulnerability
D-Link DSL-6740C FTP Daemon ftpd_conf.php hard-coded credentials
D-Link M60 emDaemon MQTT Broker mosquitto.conf system hard-coded credentials
Showing 12 of 1,672 recorded CWE-798 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-798 is exploited.
Bypass Protection Mechanism
Affects: Access Control
Read Application Data, Gain Privileges or Assume Identity, Execute Unauthorized Code or Commands, Other
Affects: Integrity, Confidentiality, Availability, Access Control, Other
Typically introduced during these phases of the software lifecycle.
Languages
Technologies
Practical mitigations for CWE-798, grouped by where in the lifecycle they apply.
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 are as restrictive as possible [1].
In Windows environments, the Encrypted File System (EFS) may provide some protection.
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.
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 the saved hash.
Use randomly assigned salts for each separate hash that is generated. This increases the amount of computation that an attacker needs to conduct a brute-force attack, possibly limiting the effectiveness of the rainbow table method.
For front-end to back-end connections: Three solutions are possible, although none are complete.
Credential 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.
Effectiveness: Moderate
Automated 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.
This 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. Configuration files could also be analyzed.
For 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 verify that the build phase did not introduce any new weaknesses. Examples include debuggers that directly attach to the running process; system-call tracing utilities such as truss (Solaris) and strace (Linux); system activity monitors such as FileMon, RegMon, Process Monitor, and other Sysinternals utilities (Windows); and sniffers and protocol analyzers that monitor network traffic.
Attach the monitor to the process and perform a login. Using call trees or similar artifacts from the output, examine the associated behaviors and see if any of them appear to be comparing the input to a fixed string or value.
According to SOAR [8], the following detection techniques may be useful:
Cost effective for partial coverage:
Effectiveness: SOAR Partial
According to SOAR [8], the following detection techniques may be useful:
Highly cost effective:
Effectiveness: High
According to SOAR [8], the following detection techniques may be useful:
Cost effective for partial coverage:
Effectiveness: SOAR Partial
According to SOAR [8], the following detection techniques may be useful:
Highly cost effective:
Effectiveness: High
According to SOAR [8], the following detection techniques may be useful:
Highly cost effective:
Effectiveness: High
According to SOAR [8], the following detection techniques may be useful:
Cost effective for partial coverage:
Effectiveness: SOAR Partial
According to SOAR [8], the following detection techniques may be useful:
Highly cost effective:
Effectiveness: High
MITRE examples of the weakness in code.
The following code uses a hard-coded password to connect to a database:
Vulnerable example
...
DriverManager.getConnection(url, "scott", "tiger");
...Attack input
javap -c ConnMngr.class
22: ldc #36; //String jdbc:mysql://ixne.com/rxsql
24: ldc #38; //String scott
26: ldc #17; //String tigerThis is an example of an external hard-coded password on the client-side of a connection. This code will run successfully, but anyone who has access to it will have access to the password. Once the program has shipped, there is no going back from the database user "scott" with a password of "tiger" unless the program is patched. A devious employee with access to this information can use it to break into the system. Even worse, if attackers have access to the bytecode for application, they can use the javap -c command to access the disassembled code, which will contain the values of the passwords used. The result of this operation might look something like the following for the example above:
The following code is an example of an internal hard-coded password in the back-end:
Vulnerable example
int VerifyAdmin(char *password) {
if (strcmp(password, "Mew!")) {
printf("Incorrect Password!\n");
return(0)
}
printf("Entering Diagnostic Mode...\n");
return(1);
}Vulnerable example
int VerifyAdmin(String password) {
if (!password.equals("Mew!")) {
return(0)
}
//Diagnostic Mode
return(1);
}Every instance of this program can be placed into diagnostic mode with the same password. Even worse is the fact that if this program is distributed as a binary-only distribution, it is very difficult to change that password or disable this "functionality."
The following code examples attempt to verify a password using a hard-coded cryptographic key.
Vulnerable example
int VerifyAdmin(char *password) {
if (strcmp(password,"68af404b513073584c4b6f22b6c63e6b")) {
printf("Incorrect Password!\n");
return(0);
}
printf("Entering Diagnostic Mode...\n");
return(1);
}Vulnerable example
public boolean VerifyAdmin(String password) {
if (password.equals("68af404b513073584c4b6f22b6c63e6b")) {
System.out.println("Entering Diagnostic Mode...");
return true;
}
System.out.println("Incorrect Password!");
return false;Vulnerable example
int VerifyAdmin(String password) {
if (password.Equals("68af404b513073584c4b6f22b6c63e6b")) {
Console.WriteLine("Entering Diagnostic Mode...");
return(1);
}
Console.WriteLine("Incorrect Password!");
return(0);
}The following examples show a portion of properties and configuration files for Java and ASP.NET applications. The files include username and password information but they are stored in cleartext.
Vulnerable example
# Java Web App ResourceBundle properties file
...
webapp.ldap.username=secretUsername
webapp.ldap.password=secretPassword
...Vulnerable example
...
<connectionStrings>
<add name="ud_DEV" connectionString="connectDB=uDB; uid=db2admin; pwd=password; dbalias=uDB;" providerName="System.Data.Odbc" />
</connectionStrings>
...In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT) vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by design" [5]. If exploited, these vulnerabilities often allowed adversaries to change how the products operated, ranging from denial of service to changing the code that the products executed. Since these products were often used in industries such as power, electrical, water, and others, there could even be safety implications.
Multiple vendors used hard-coded credentials in their OT products.
This code stores a database password in a PHP file.
Vulnerable example
<?php
$db_username = "secretUsername";
$db_password = "secretPassword";
$db_host = "localhost";
$db_name = "exampleDatabase";
// Database connection
$conn = mysqli_connect($db_host, $db_username, $db_password, $db_name);
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>Safe example
<?php
// config.php
return [
'db_username' => 'secretUsername',
'db_password' => 'secretPassword',
'db_host' => 'localhost',
'db_name' => 'exampleDatabase',
];Safe example
<?php
// Load config
$config = require DIR . '/../config.php';
// Create connection
$conn = new mysqli(
$config['db_host'],
$config['db_username'],
$config['db_password'],
$config['db_name']
);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>Real CVEs that MITRE cites as examples of this weakness.
CAPEC attack patterns that exploit this weakness.
Common questions about CWE-798.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-798 CVE affects your products, with AI-written analysis and remediation steps.
The cryptographic key is within a hard-coded string value that is compared to the password. It is likely that an attacker will be able to read the key and compromise the system.