VI

Delphi

RAD Studio 13.2 TZipFile Security Patch

Embarcadero is releasing a security update for the Delphi Runtime Library (RTL) System.Zip.TZipFile class, addressing vulnerabilities that could affect applications extracting ZIP archives from untrusted sources. This update is also relevant for customers using C++Builder and RAD Studio, if they use the Delphi RTL in their applications.

Under specific conditions, a specially crafted ZIP archive could cause an application to create or overwrite files outside the intended extraction directory.

The scope of these vulnerabilities is limited to applications using the TZipFile class to process untrusted, potentially malicious and specially crafted ZIP archives. Most Delphi and C++Bu...

Description

Embarcadero is releasing a security update for the Delphi Runtime Library (RTL) System.Zip.TZipFile class, addressing vulnerabilities that could affect applications extracting ZIP archives from untrusted sources. This update is also relevant for customers using C++Builder and RAD Studio, if they use the Delphi RTL in their applications.

Under specific conditions, a specially crafted ZIP archive could cause an application to create or overwrite files outside the intended extraction directory.

The scope of these vulnerabilities is limited to applications using the TZipFile class to process untrusted, potentially malicious and specially crafted ZIP archives. Most Delphi and C++Builder applications are not expected to be affected, particularly those that do not use TZipFile, do not extract ZIP files, or exclusively process archives from trusted sources.

Embarcadero is providing a binary patch for RAD Studio 13 and source code updates for developers using Delphi or C++Builder 11 and 12. We are also in the process of releasing an updated version of RAD Studio 13.2 with the security patch embedded.

Affected Scenarios

These security vulnerabilities are relevant only to applications that use the Delphi RTL TZipFile class to extract ZIP archives from untrusted or potentially malicious sources. They do not affect the IDE.

Examples include applications that:

  • Accept ZIP file uploads from unknown users or external systems.
  • Download and automatically extract ZIP archives from untrusted Internet sources.
  • Process ZIP attachments or packages whose contents have not been validated.

Applications that do not use TZipFile for extraction, that exclusively create ZIP archives, or that process ZIP files from trusted and controlled sources, are generally not exposed to these attack scenarios.

Even when processing untrusted archives, exploitation depends on the application’s extraction workflow, the operating system, and the filesystem permissions available to the application.

Developers building applications that automatically extract ZIP archives from external sources should review their exposure and apply the relevant update.

Security Issues Addressed

The update addresses two categories of security vulnerabilities in the Delphi RTL ZIP extraction implementation.

1. ZIP Extraction Path Traversal

The ZIP extraction implementation does not adequately validate that extracted file paths remain within the specified destination directory.

A malicious ZIP archive can contain filenames with relative path traversal sequences (such as ../) or absolute paths, potentially causing files to be written outside the intended extraction location.

A related issue involves the ZIP Unicode Path extra field (header ID 0x7075), which can specify an alternative filename that differs from the filename recorded in the archive’s central directory. This could allow a malicious archive to bypass applications that inspect and validate ZIP entry filenames before extraction.

Both issues stem from insufficient validation of archive-controlled filenames and extraction paths.

2. Uncontrolled Symbolic Link Creation

When ZIP entry attributes indicate a symbolic link, TZipFile can automatically create that link using a target specified in the archive.

A malicious archive could exploit this behavior to create symbolic links pointing outside the extraction directory, potentially redirecting subsequent file extraction operations to unintended locations.

This scenario is particularly relevant on POSIX platforms, where symbolic link creation generally does not require special privileges. On Windows, symbolic link creation is subject to additional operating system restrictions.

Potential Impact

In affected applications, successful exploitation could allow unauthorized file creation or overwriting within the filesystem permissions of the application performing the extraction.

Depending on the application’s environment, this could result in modification of application data, configuration files, or other resources accessible to the process.

Remediation

Embarcadero has updated the Delphi RTL TZipFile extraction implementation to address these vulnerabilities. The changes strengthen validation of ZIP entry filenames and extraction paths, preventing archive-controlled paths from escaping the intended extraction directory. The update also addresses the handling of symbolic links originating from ZIP archive entries.

We recommend that developers review applications that extract ZIP archives from untrusted sources, apply the relevant update, rebuild these applications, and redeploy them to their customers.

Because the affected functionality is part of the Delphi RTL, applications incorporating the vulnerable implementation may need to be rebuilt with the updated library to benefit from these corrections.

Potential Side Effect of the Fix

There is a possibility that the stronger check on file names and paths changes the behavior of the extraction of legitimate ZIP files, which were leveraging the potentially harmful configuration in correct and controlled scenarios. In these cases, we recommend reviewing the ZIP file content and process. The note below is from Embarcadero R&D.

For archives written without the UTF-8 flag, FileName, FileNames, IndexOf and GetHeaderFileName now return the Unicode name from the archive’s central directory, the same name Extract uses. Before, they returned the name decoded with Encoding, while Extract used a name from the local header. A Unicode name is ignored when it isn’t valid UTF-8 or isn’t a safe relative path (absolute, drive, .., stream names). The name is then decoded with Encoding; for archives created on Linux or macOS, set Encoding to TEncoding.UTF8. Rename now removes the Unicode name of the renamed entry. GetHeaderFileName gives the extraction name only for headers from FileInfo or FileInfos, not for the header returned by Read or passed to onprogress.

Additional Information