/

CVE-2026-120641

Severity:

HIGH RISK

(8.8)

Path Traversal (CWE-22) in Perl CGI Upload Filenames

CVE-2026-120641

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Unauthorized file writes outside the intended upload directory

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Perl CGI versions before 5.00 return an uploaded file's client-supplied filename, including any path components, unchanged. If an application uses that value directly as a save path, an attacker may be able to write the upload outside the intended directory.

Affected context

The issue occurs in file-upload handling by CGI for Perl versions before 5.00: the returned upload filename is taken from the part's Content-Disposition header without removing client-supplied path components. The risk depends on how the application uses that value; applications that save uploads under the returned name without safely constraining the destination may allow writes outside the intended directory.

Exploit preconditions

  • Attack surface: An application accepts file uploads through CGI for Perl.
  • Required access: The attacker must be able to submit an upload; authentication requirements depend on the application.
  • Trigger point: The application saves the uploaded file using the filename returned by CGI.
  • Why exploitation is possible: Client-supplied path components are returned unchanged, and the application may resolve them outside its intended upload directory.

Why this happens

The upload-handling code preserves path information from an untrusted filename rather than ensuring that the value is only a filename. When an application uses that value to construct a filesystem path, traversal components may escape the intended directory. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

Potential impact

  • An attacker may write uploaded content outside the designated upload directory.
  • Files may be overwritten or created if the application process has sufficient filesystem permissions.
  • The affected application or host could be disrupted if sensitive or operational files are modified.
  • Written files could be used to affect other components, depending on their location and how they are handled.

General mitigation guidance

Defensive patterns focus on treating upload filenames as untrusted metadata and controlling the destination independently of the supplied name.

  • Prefer server-generated storage names and keep the original filename only as safely encoded display metadata.
  • If retaining a client filename is necessary, reduce it to a basename and verify that the resolved destination remains within the designated upload directory.
  • Use APIs and storage designs that constrain writes to a dedicated directory.
  • Limit filesystem permissions for the application process and avoid granting write access to sensitive locations.
  • Validate upload types and content as separate controls; validation does not replace safe path handling.

How teams detect issues like this

  • Use static analysis to find upload-handling code that combines client-controlled filenames with filesystem paths.
  • Review code for direct use of returned upload names in file creation, rename, or copy operations.
  • Add tests and security checks that verify upload destinations remain within an approved directory for varied path formats.
  • Enforce code-review or CI policies requiring server-generated storage names or verified path containment.

Sources

SourceLink
github.comgithub.com/leejo/CGI.pm/commit/5379eb18e87b7f985613f5c4f7bae94478a4fa2f.patch
metacpan.orgmetacpan.org/release/LEEJO/CGI-4.72/source/lib/CGI.pm
metacpan.orgmetacpan.org/release/LEEJO/CGI-5.00/changes

Frequently asked

questions

The filename handling issue is in CGI for Perl versions before 5.00. File writes outside an intended directory require an application to use the returned name unsafely when saving an upload.

The attacker needs to be able to submit an upload to an affected application. Whether authentication is required depends on the application's access controls.

Generate storage names on the server and choose the destination directory independently of client-supplied filenames. If a client name is retained, ensure it cannot influence the resolved path.

Treat filenames and other upload metadata as untrusted, verify path containment, restrict write permissions, and use code review and automated checks to identify unsafe path construction.

Find out what's already
exploitable in your codebase.