LIVE NEWSROOM · --:-- · May 25, 2026
A LIBRARY FOR SECURITY RESEARCHERS

CWE WEAKNESSES  /  CWE-427

CWE-427

Uncontrolled Search Path Element

Base

What it is

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.

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 directoryIn 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 o

Impact

Confidentiality, Integrity, AvailabilityExecute Unauthorized Code or Commands

Mitigations

  • [Architecture and Design, Implementation] 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.
  • [Implementation] 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 ref
  • [Implementation] 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.
  • [Implementation] 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.
  • [Implementation] 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.

Real-world CVE examples

  • CVE-2023-25815 — 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:
  • CVE-2022-4826 — 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
  • CVE-2020-26284 — 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 mal
  • CVE-2022-24765 — 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
  • CVE-2019-1552 — SSL package searches under "C:/usr/local" for configuration files and other critical data, but C:/usr/local might be world-writable.
  • CVE-2010-3402 — "DLL hijacking" issue in document editor.
  • CVE-2010-3397 — "DLL hijacking" issue in encryption software.
  • CVE-2010-3138 — "DLL hijacking" issue in library used by multiple media players.
  • CVE-2010-3152 — "DLL hijacking" issue in illustration program.
  • CVE-2010-3147 — "DLL hijacking" issue in address book.
  • CVE-2010-3135 — "DLL hijacking" issue in network monitoring software.
  • CVE-2010-3131 — "DLL hijacking" issue in web browser.

Related weaknesses

Test & detect

Browse all common weaknesses, check related exploited CVEs, or map to ATT&CK techniques.

Source: MITRE CWE. View on cwe.mitre.org →

Scroll to Top