Description
Source code on a web server or repository often contains sensitive information and should generally not be accessible to users.
There are situations where it is critical to remove source code from an area or server. For example, obtaining Perl source code on a system allows an attacker to understand the logic of the script and extract extremely useful information such as code bugs or logins and passwords.
Potential Impact
Confidentiality
Read Application Data
Demonstrative Examples
<?php$dbName = 'usersDB';$dbPassword = 'skjdh#67nkjd3$3$';?><?phpinclude('database.inc');$db = connectToDB($dbName, $dbPassword);$db.authenticateUser($username, $password);?><!-- FIXME: calling this with more than 30 args kills the JDBC server -->Mitigations & Prevention
Recommendations include removing this script from the web server and moving it to a location not accessible from the Internet.
Detection Methods
- Automated Static Analysis — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2022-25512 | Server for Team Awareness Kit (TAK) application includes sensitive tokens in the JavaScript source code. |
| CVE-2022-24867 | The LDAP password might be visible in the html code of a rendered page in an IT Asset Management tool. |
| CVE-2007-6197 | Version numbers and internal hostnames leaked in HTML comments. |
Related Weaknesses
Frequently Asked Questions
What is CWE-540?
CWE-540 (Inclusion of Sensitive Information in Source Code) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. Source code on a web server or repository often contains sensitive information and should generally not be accessible to users.
How can CWE-540 be exploited?
Attackers can exploit CWE-540 (Inclusion of Sensitive Information in Source Code) to read application data. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-540?
Key mitigations include: Recommendations include removing this script from the web server and moving it to a location not accessible from the Internet.
What is the severity of CWE-540?
CWE-540 is classified as a Base-level weakness (Medium abstraction). It has been observed in 3 real-world CVEs.