CWE-427: Uncontrolled Search Path Element (Base)

Description: The product uses a fixed or controlled search path to find resources, but one or more locations in that path can be under the control of unintended actors.

Extended Description: Although this weakness can occur with any type of resource, it is frequently introduced when a product uses a directory search path to find executables or code libraries, but the path contains a directory that can be modified by an attacker, such as /tmp or the current working directory. In Windows-based systems, when the LoadLibrary or LoadLibraryEx function is called with a DLL name that does not contain a fully qualified path, the function follows a search order that includes two path elements that might be uncontrolled: the directory from which the program has been loaded the current working directory In some cases, the attack can be conducted remotely, such as when SMB or WebDAV network shares are used. One or more locations in that path could include the Windows drive root or its subdirectories. This often exists in Linux-based code assuming the controlled nature of the root directory (/) or its subdirectories (/etc, etc), or a code that recursively accesses the parent directory. In Windows, the drive root and some of its subdirectories have weak permissions by default, which makes them uncontrolled. In some Unix-based systems, a PATH might be created that contains an empty element, e.g. by splicing an empty variable into the PATH. This empty element can be interpreted as equivalent to the current working directory, which might be an untrusted search element. In software package management frameworks (e.g., npm, RubyGems, or PyPi), the framework may identify dependencies on third-party libraries or other packages, then consult a repository that contains the desired package. The framework may search a public repository before a private repository. This could be exploited by attackers by placing a malicious package in the public repository that has the same name as a package from the private repository. The search path might not be directly under control of the developer relying on the framework, but this search order effectively contains an untrusted element.


Alternate Terms: ::TERM:DLL preloading:DESCRIPTION:This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.::TERM:Binary planting:DESCRIPTION:This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.::TERM:Insecure library loading:DESCRIPTION:This term is one of several that are used to describe exploitation of untrusted search path elements in Windows systems, which received wide attention in August 2010. From a weakness perspective, the term is imprecise because it can apply to both CWE-426 and CWE-427.::TERM:Dependency confusion:DESCRIPTION:As of February 2021, this term is used to describe CWE-427 in the context of managing installation of software package dependencies, in which attackers release packages on public sites where the names are the same as package names used by private repositories, and the search for the dependent package tries the public site first, downloading untrusted code. It may also be referred to as a substitution attack.::

Applicable Platforms: ::LANGUAGE CLASS:Not Language-Specific:LANGUAGE PREVALENCE:Undetermined::OPERATING SYSTEM CLASS:Not OS-Specific:OPERATING SYSTEM PREVALENCE:Undetermined::

Modes of Introduction: ::PHASE:Implementation::



Common Consequences: ::SCOPE:Confidentiality:SCOPE:Integrity:SCOPE:Availability:IMPACT:Execute Unauthorized Code or Commands::

Detection Methods: ::METHOD:Automated Static Analysis:DESCRIPTION: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 searching for potentially-vulnerable patterns that connect sources (origins of input) with sinks (destinations where the data interacts with external components, a lower layer such as the OS, etc.):EFFECTIVENESS:High::

Potential Mitigations: ::PHASE:Architecture and Design Implementation:STRATEGY:Attack Surface Reduction:DESCRIPTION:Hard-code the search path to a set of known-safe values (such as system directories), or only allow them to be specified by the administrator in a configuration file. Do not allow these settings to be modified by an external party. Be careful to avoid related weaknesses such as CWE-426 and CWE-428.::PHASE:Implementation:STRATEGY:Attack Surface Reduction:DESCRIPTION:When invoking other programs, specify those programs using fully-qualified pathnames. While this is an effective approach, code that uses fully-qualified pathnames might not be portable to other systems that do not use the same pathnames. The portability can be improved by locating the full-qualified paths in a centralized, easily-modifiable location within the source code, and having the code refer to these paths.::PHASE:Implementation:STRATEGY:Attack Surface Reduction:DESCRIPTION:Remove or restrict all environment settings before invoking other programs. This includes the PATH environment variable, LD_LIBRARY_PATH, and other settings that identify the location of code libraries, and any application-specific search paths.::PHASE:Implementation:DESCRIPTION:Check your search path before use and remove any elements that are likely to be unsafe, such as the current working directory or a temporary files directory. Since this is a denylist approach, it might not be a complete solution.::PHASE:Implementation:DESCRIPTION:Use other functions that require explicit paths. Making use of any of the other readily available functions that require explicit paths is a safe way to avoid this problem. For example, system() in C does not require a full path since the shell can take care of finding the program using the PATH environment variable, while execl() and execv() require a full path.::

Observed Examples: ::REFERENCE:CVE-2023-25815:DESCRIPTION:chain: a change in an underlying package causes the gettext function to use implicit initialization with a hard-coded path (CWE-1419) under the user-writable C: drive, introducing an untrusted search path element (CWE-427) that enables spoofing of messages.:LINK:https://www.cve.org/CVERecord?id=CVE-2023-25815::REFERENCE:CVE-2022-4826:DESCRIPTION:Go-based git extension on Windows can search for and execute a malicious ..exe in a repository because Go searches the current working directory if git.exe is not found in the PATH:LINK:https://www.cve.org/CVERecord?id=CVE-2022-4826::REFERENCE:CVE-2020-26284:DESCRIPTION:A Static Site Generator built in Go, when running on Windows, searches the current working directory for a command, possibly allowing code execution using a malicious .exe or .bat file with the name being searched:LINK:https://www.cve.org/CVERecord?id=CVE-2020-26284::REFERENCE:CVE-2022-24765:DESCRIPTION:Windows-based fork of git creates a .git folder in the C: drive, allowing local attackers to create a .git folder with a malicious config file:LINK:https://www.cve.org/CVERecord?id=CVE-2022-24765::REFERENCE:CVE-2019-1552:DESCRIPTION:SSL package searches under C:/usr/local for configuration files and other critical data, but C:/usr/local might be world-writable.:LINK:https://www.cve.org/CVERecord?id=CVE-2019-1552::REFERENCE:CVE-2010-3402:DESCRIPTION:DLL hijacking issue in document editor.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3402::REFERENCE:CVE-2010-3397:DESCRIPTION:DLL hijacking issue in encryption software.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3397::REFERENCE:CVE-2010-3138:DESCRIPTION:DLL hijacking issue in library used by multiple media players.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3138::REFERENCE:CVE-2010-3152:DESCRIPTION:DLL hijacking issue in illustration program.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3152::REFERENCE:CVE-2010-3147:DESCRIPTION:DLL hijacking issue in address book.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3147::REFERENCE:CVE-2010-3135:DESCRIPTION:DLL hijacking issue in network monitoring software.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3135::REFERENCE:CVE-2010-3131:DESCRIPTION:DLL hijacking issue in web browser.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-3131::REFERENCE:CVE-2010-1795:DESCRIPTION:DLL hijacking issue in music player/organizer.:LINK:https://www.cve.org/CVERecord?id=CVE-2010-1795::REFERENCE:CVE-2002-1576:DESCRIPTION:Product uses the current working directory to find and execute a program, which allows local users to gain privileges by creating a symlink that points to a malicious version of the program.:LINK:https://www.cve.org/CVERecord?id=CVE-2002-1576::REFERENCE:CVE-1999-1461:DESCRIPTION:Product trusts the PATH environmental variable to find and execute a program, which allows local users to obtain root access by modifying the PATH to point to a malicous version of that program.:LINK:https://www.cve.org/CVERecord?id=CVE-1999-1461::REFERENCE:CVE-1999-1318:DESCRIPTION:Software uses a search path that includes the current working directory (.), which allows local users to gain privileges via malicious programs.:LINK:https://www.cve.org/CVERecord?id=CVE-1999-1318::REFERENCE:CVE-2003-0579:DESCRIPTION:Admin software trusts the user-supplied -uv.install command line option to find and execute the uv.install program, which allows local users to gain privileges by providing a pathname that is under control of the user.:LINK:https://www.cve.org/CVERecord?id=CVE-2003-0579::REFERENCE:CVE-2000-0854:DESCRIPTION:When a document is opened, the directory of that document is first used to locate DLLs , which could allow an attacker to execute arbitrary commands by inserting malicious DLLs into the same directory as the document.:LINK:https://www.cve.org/CVERecord?id=CVE-2000-0854::REFERENCE:CVE-2001-0943:DESCRIPTION:Database trusts the PATH environment variable to find and execute programs, which allows local users to modify the PATH to point to malicious programs.:LINK:https://www.cve.org/CVERecord?id=CVE-2001-0943::REFERENCE:CVE-2001-0942:DESCRIPTION:Database uses an environment variable to find and execute a program, which allows local users to execute arbitrary programs by changing the environment variable.:LINK:https://www.cve.org/CVERecord?id=CVE-2001-0942::REFERENCE:CVE-2001-0507:DESCRIPTION:Server uses relative paths to find system files that will run in-process, which allows local users to gain privileges via a malicious file.:LINK:https://www.cve.org/CVERecord?id=CVE-2001-0507::REFERENCE:CVE-2002-2017:DESCRIPTION:Product allows local users to execute arbitrary code by setting an environment variable to reference a malicious program.:LINK:https://www.cve.org/CVERecord?id=CVE-2002-2017::REFERENCE:CVE-1999-0690:DESCRIPTION:Product includes the current directory in root's PATH variable.:LINK:https://www.cve.org/CVERecord?id=CVE-1999-0690::REFERENCE:CVE-2001-0912:DESCRIPTION:Error during packaging causes product to include a hard-coded, non-standard directory in search path.:LINK:https://www.cve.org/CVERecord?id=CVE-2001-0912::REFERENCE:CVE-2001-0289:DESCRIPTION:Product searches current working directory for configuration file.:LINK:https://www.cve.org/CVERecord?id=CVE-2001-0289::REFERENCE:CVE-2005-1705:DESCRIPTION:Product searches current working directory for configuration file.:LINK:https://www.cve.org/CVERecord?id=CVE-2005-1705::REFERENCE:CVE-2005-1307:DESCRIPTION:Product executable other program from current working directory.:LINK:https://www.cve.org/CVERecord?id=CVE-2005-1307::REFERENCE:CVE-2002-2040:DESCRIPTION:Untrusted path.:LINK:https://www.cve.org/CVERecord?id=CVE-2002-2040::REFERENCE:CVE-2005-2072:DESCRIPTION:Modification of trusted environment variable leads to untrusted path vulnerability.:LINK:https://www.cve.org/CVERecord?id=CVE-2005-2072::REFERENCE:CVE-2005-1632:DESCRIPTION:Product searches /tmp for modules before other paths.:LINK:https://www.cve.org/CVERecord?id=CVE-2005-1632::



Notes: ::TYPE:Relationship:NOTE:Unlike untrusted search path (CWE-426), which inherently involves control over the definition of a control sphere (i.e., modification of a search path), this entry concerns a fixed control sphere in which some part of the sphere may be under attacker control (i.e., the search path cannot be modified by an attacker, but one element of the path can be under attacker control).::TYPE:Theoretical:NOTE:This weakness is not a clean fit under CWE-668 or CWE-610, which suggests that the control sphere model might need enhancement or clarification.::