/

CVE-2026-40342

Severity:

CRITICAL RISK

(9.9)

Path Traversal and Insecure Library Loading in Firebird

CVE-2026-40342

Analyzed

Vulnerability type

Category:

Path Traversal and Insecure Library Loading

CWE:

CWE-22, CWE-73, CWE-94, CWE-427

Impact:

Authenticated Remote Code Execution via Arbitrary Library Load

Severity:

CRITICAL RISK

(9.9)

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

Firebird's external engine plugin loader constructs filesystem paths by directly concatenating user-controlled engine names, without properly handling path separators or directory traversal sequences.

An authenticated user with CREATE FUNCTION privileges can craft an ENGINE name that points to an arbitrary shared library anywhere on the filesystem, causing its initialization code to run with the Firebird server's operating system privileges.

Affected context

This vulnerability affects Firebird database servers using the external engine plugin mechanism in versions prior to 5.0.4, 4.0.7, and 3.0.14.

It manifests when the server:

  • Accepts user-defined functions (UDFs) or external functions specifying an ENGINE name
  • Constructs the library path by concatenating a base plugin directory with the provided ENGINE name
  • Does not sanitize or normalize the resulting path to prevent directory traversal or escape from intended plugin directories

The issue is most relevant in multi-tenant or shared database environments where some users hold CREATE FUNCTION or similar privileges but are not expected to run arbitrary code on the host.

Exploit preconditions

  • Attack surface: Database protocol/API (remote or local, depending on deployment) via SQL statements that define external functions or plugins.
  • Required access: Valid authenticated Firebird account with CREATE FUNCTION (or equivalent external function creation) privileges.
  • Trigger point: Submission of a CREATE FUNCTION (or similar) statement using a specially crafted ENGINE name containing path traversal sequences or absolute paths.
  • Why exploitation is possible:
  • The plugin loader concatenates the ENGINE name directly into a filesystem path without filtering .. components or path separators.
  • The resulting path can escape the intended plugin directory and reference arbitrary shared libraries on the host.
  • When the library is loaded, its initialization code executes immediately, before any substantive validation of the module can occur.
  • This behavior aligns with CWE-22 (Path Traversal) and CWE-427 (Uncontrolled Search Path Element), enabling arbitrary code execution under the Firebird server's OS account.

Why this happens

The core defect lies in how Firebird's external engine plugin loader builds the path to shared libraries:

  • It treats the ENGINE name as a trusted component of the filesystem path.
  • It does not normalize, validate, or restrict the ENGINE name to a safe subset (such as a simple identifier or filename without path metacharacters).
  • It relies on the underlying operating system loader to resolve the final path, effectively delegating trust to an unvalidated value.

From a vulnerability taxonomy perspective:

  • CWE-22 (Improper Limitation of a Pathname to a Restricted Directory): The ENGINE name can contain ../ or equivalent constructs that traverse out of the intended plugin directory.
  • CWE-73 (External Control of File Name or Path): The file path of the library is influenced by user input.
  • CWE-427 (Uncontrolled Search Path Element): The loader allows user-controlled path elements to determine which library is loaded.
  • CWE-94 (Improper Control of Code Generation) is conceptually related, as the consequence is arbitrary code execution through loading attacker-chosen binaries.

Abstractly, this is an insecure pattern where plugin/module identifiers are not separated from filesystem paths, allowing user-controlled identifiers to become direct filesystem locations.

Potential impact

  • Execution of arbitrary native code with the privileges of the Firebird server's operating system account.
  • Reading, modification, or deletion of database files and configuration data accessible to the Firebird process.
  • Lateral movement on the host through access to other files, credentials, or inter-process communication channels.
  • Installation of persistent backdoors or rootkits by dropping and loading malicious libraries.
  • Full compromise of the affected server instance and potential pivoting to other systems in the environment.

General mitigation guidance

Effective mitigation centers on strictly separating user-supplied identifiers from filesystem paths and constraining where plugins can be loaded from.

Common defensive patterns include:

  • Input normalization and restriction:
  • Treat ENGINE names as logical identifiers, not paths.
  • Reject ENGINE names containing path separators (/, \), drive letters, or .. components.
  • Enforce a whitelist of allowed characters (e.g., alphanumerics, underscores) and maximum length.
  • Directory confinement:
  • Resolve plugin paths only within a predefined, fixed plugin directory.
  • Use canonicalization (e.g., realpath) and verify that the final resolved path remains within the intended directory tree before loading.
  • Explicit plugin mapping:
  • Maintain a static mapping of allowed ENGINE identifiers to specific library filenames instead of deriving paths directly from user input.
  • Privilege and isolation controls:
  • Run the Firebird server under a dedicated, least-privileged OS account with minimal filesystem access.
  • Use OS-level sandboxing, containers, or mandatory access control (e.g., SELinux, AppArmor) to restrict the process's ability to load arbitrary libraries and access sensitive files.
  • Privilege design in the database:
  • Treat CREATE FUNCTION and similar capabilities as highly privileged.
  • Grant them only to trusted roles and restrict their usage via database security policies.

How teams detect issues like this

Detecting and monitoring for this class of issue can involve both preventative and operational approaches:

  • Static analysis and code review:
  • Flag code paths where user-supplied values are concatenated into filesystem paths used for loading libraries or modules.
  • Look for absence of path normalization, character whitelisting, or directory boundary checks before calls to dlopen, LoadLibrary, or equivalent APIs.
  • Review plugin-loading logic to confirm that logical identifiers are not used as raw paths.
  • Configuration and policy checks:
  • Periodically review database role definitions and privileges to identify accounts that hold CREATE FUNCTION or external engine-related privileges.
  • Enforce internal policies restricting who can deploy external engines or UDFs.
  • Runtime and operational monitoring:
  • Monitor system logs for unexpected library loads originating from the Firebird process, especially from non-standard directories.
  • Use host-based intrusion detection systems (HIDS) to alert on unusual shared object loads or modifications in plugin directories.
  • Automated tooling:
  • Incorporate security-focused linters or SAST tools in CI pipelines, configured with rules for path traversal and uncontrolled library loading patterns.
  • Employ configuration assessment tools to track and alert on high-risk database privileges and plugin configurations.

Sources

SourceLink
github.comgithub.com/FirebirdSQL/firebird/releases/tag/v3.0.14
github.comgithub.com/FirebirdSQL/firebird/releases/tag/v4.0.7
github.comgithub.com/FirebirdSQL/firebird/releases/tag/v5.0.4
github.comgithub.com/FirebirdSQL/firebird/security/advisories/GHSA-7pxc-h3rv-r257

Frequently asked

questions

It is highly exploitable in environments where users with CREATE FUNCTION or equivalent privileges are not fully trusted. Any such user who can execute SQL against the Firebird server can typically trigger the vulnerable engine loading behavior and achieve code execution on the host.

No local shell access is required. The attacker only needs an authenticated Firebird account with sufficient database privileges (such as CREATE FUNCTION) and the ability to issue SQL statements over the database protocol.

The safest pattern is to treat ENGINE names purely as logical identifiers and map them to fixed library paths defined by the server configuration, combined with strict validation that rejects any path-like values. Additionally, ensure that all resolved library paths are confined to a dedicated plugin directory, verified after canonicalization.

Architect plugin and extension systems so that user-controllable values never directly influence filesystem paths or dynamic loading decisions. Enforce strong validation on any identifiers that map to files, constrain resolution to known-safe directories, minimize the privileges of processes that load plugins, and use code review and automated checks specifically targeting path handling and dynamic loading logic.

Find out what's already
exploitable in your codebase.