CWE-73 Base Draft High likelihood

External Control of File Name or Path

This vulnerability occurs when an application uses unvalidated user input to construct file or directory paths for filesystem operations.

Definition

What is CWE-73?

This vulnerability occurs when an application uses unvalidated user input to construct file or directory paths for filesystem operations.
Path manipulation vulnerabilities arise when an attacker can control the path used in operations like reading, writing, or deleting files. By crafting special inputs containing sequences like '../' (directory traversal), they can force the application to access files or directories outside the intended, restricted location. This can lead to unauthorized access to sensitive system files, application source code, or configuration data. For a successful attack, two conditions must be met: the attacker must be able to specify the path used in a filesystem operation, and doing so must grant them a capability they shouldn't have, such as overwriting a critical file, reading private data, or forcing the application to use a malicious configuration file. The core defense is to never trust user input for path construction; instead, use allowlists, canonicalize paths, and then validate them against a strict list of permitted directories.
Auswirkungen in der Praxis

Real-world CVEs caused by CWE-73

  • Chain: a learning management tool debugger uses external input to locate previous session logs (CWE-73) and does not properly validate the given path (CWE-20), allowing for filesystem path traversal using "../" sequences (CWE-24)

  • Chain: external control of values for user's desired language and theme enables path traversal.

  • Chain: external control of user's target language enables remote file inclusion.

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 1

    Identifiziere einen Codepfad, der nicht vertrauenswürdige Eingaben ohne Validierung verarbeitet.

  2. 2

    Erzeuge eine Payload, die das unsichere Verhalten auslöst — Injection, Traversal, Overflow oder Logik-Missbrauch.

  3. 3

    Liefere die Payload über einen normalen Request aus und beobachte die Reaktion der Anwendung.

  4. 4

    Iteriere, bis die Antwort Daten preisgibt, Angreifer-Code ausführt oder Berechtigungen eskaliert.

Verwundbares Codebeispiel

Vulnerable Java

The following code uses input from an HTTP request to create a file name. The programmer has not considered the possibility that an attacker could provide a file name such as "../../tomcat/conf/server.xml", which causes the application to delete one of its own configuration files (CWE-22).

Verwundbar Java
String rName = request.getParameter("reportName");
  File rFile = new File("/usr/local/apfr/reports/" + rName);
  ...
  rFile.delete();
Sicheres Codebeispiel

Secure pseudo

Sicher pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Präventions-Checkliste

How to prevent CWE-73

  • Architecture and Design When the set of filenames is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames, and reject all other inputs. For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap provide this capability.
  • Architecture and Design / Operation Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict all access to files within a particular directory. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.
  • Architecture and Design For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
  • Implementation Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. When validating filenames, use stringent allowlists that limit the character set to be used. If feasible, only allow a single "." character in the filename to avoid weaknesses such as CWE-23, and exclude directory separators such as "/" to avoid CWE-36. Use a list of allowable file extensions, which will help to avoid CWE-434. Do not rely exclusively on a filtering mechanism that removes potentially dangerous characters. This is equivalent to a denylist, which may be incomplete (CWE-184). For example, filtering "/" is insufficient protection if the filesystem also supports the use of "\" as a directory separator. Another possible error could occur when the filtering is applied in a way that still produces dangerous data (CWE-182). For example, if "../" sequences are removed from the ".../...//" string in a sequential fashion, two instances of "../" would be removed from the original string, but the remaining characters would still form the "../" string.
  • Implementation Use a built-in path canonicalization function (such as realpath() in C) that produces the canonical version of the pathname, which effectively removes ".." sequences and symbolic links (CWE-23, CWE-59).
  • Installation / Operation Use OS-level permissions and run as a low-privileged user to limit the scope of any successful attack.
  • Operation / Implementation If you are using PHP, configure your application so that it does not use register_globals. During implementation, develop your application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.
  • Testing Use tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session. These may be more effective than strictly automated techniques. This is especially the case with weaknesses that are related to design and business rules.
Erkennungssignale

How to detect CWE-73

Automated Static Analysis

The external control or influence of filenames can often be detected using automated static analysis that models data flow within the product. Automated static analysis might not be able to recognize when proper input validation is being performed, leading to false positives - i.e., warnings that do not have any security consequences or require any code changes.

Plexicus Auto-Fix

Plexicus erkennt CWE-73 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist CWE-73?

This vulnerability occurs when an application uses unvalidated user input to construct file or directory paths for filesystem operations.

Wie gravierend ist CWE-73?

MITRE stuft die Exploit-Wahrscheinlichkeit als hoch ein — diese Schwachstelle wird aktiv in freier Wildbahn ausgenutzt und sollte priorisiert behoben werden.

Welche Sprachen oder Plattformen sind von CWE-73 betroffen?

MITRE lists the following affected platforms: Unix, Windows, macOS.

Wie kann ich CWE-73 verhindern?

When the set of filenames is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames, and reject all other inputs. For example, ID 1 could map to "inbox.txt" and ID 2 could map to "profile.txt". Features such as the ESAPI AccessReferenceMap provide this capability. Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict all…

Wie erkennt und behebt Plexicus CWE-73?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-73 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-73?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/73.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Verwandte Schwachstellen

Weaknesses related to CWE-73

CWE-642 Parent

External Control of Critical State Data

This vulnerability occurs when an application stores security-sensitive state data in locations that unauthorized users can access and…

CWE-15 Sibling

External Control of System or Configuration Setting

This vulnerability occurs when an application allows users to directly modify critical system settings or configuration values from an…

CWE-426 Sibling

Untrusted Search Path

This vulnerability occurs when an application relies on an external search path, provided by a user or environment, to find and load…

CWE-472 Sibling

External Control of Assumed-Immutable Web Parameter

This vulnerability occurs when a web application incorrectly trusts data that appears to be fixed or hidden from the user, such as values…

CWE-565 Sibling

Reliance on Cookies without Validation and Integrity Checking

This vulnerability occurs when an application uses cookies to make security decisions—like granting access or changing settings—but fails…

CWE-22 Kann vorausgehen

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

This vulnerability occurs when an application builds a file path using user input but fails to properly validate it, allowing an attacker…

CWE-41 Kann vorausgehen

Improper Resolution of Path Equivalence

This vulnerability occurs when an application fails to properly handle different text representations that refer to the same file or…

CWE-98 Kann vorausgehen

Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')

This vulnerability occurs when a PHP application uses unvalidated or insufficiently restricted user input directly within file inclusion…

CWE-434 Kann vorausgehen

Unrestricted Upload of File with Dangerous Type

This vulnerability occurs when an application accepts file uploads without properly restricting the file types, allowing attackers to…

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.