CVE-2026-81730
Dolibarr 9.0.0 through 23.0.4 Path Traversal via EmailCollector Attachment Filename
Refuses Dolibarr EmailCollector attachment writes that traverse outside per-object document directories or into htdocs to mitigate CVE-2026-81730.
High 8.8Vetted
EPSS 0.6%: the estimated chance this CVE is exploited in the next 30 days, as of 25 Nov 2026.
At a glance
CVE-2026-81730 is a high (CVSS 8.8) vulnerability in Dolibarr, published 27 August 2026. A vetted upatch, cve-2026-81730-dolibarr-block, blocks it on running Linux machines with shirudo until Dolibarr is upgraded.
- Severity
- High 8.8 CVSS 4.0
- Chance of exploitation
- 0.6% in the next 30 days (EPSS, 25 Nov 2026)
- Known exploited
- No, not on CISA’s KEV list
- Weakness
- CWE-22
- Affected software
- Dolibarr
- Upatch status
- Vetted, merged into the registry
- How to apply
- Build, sign and roll out with shirudo
Overview
Dolibarr's EmailCollector (htdocs/emailcollector/class/emailcollector.class.php and htdocs/emailcollector/lib/emailcollector.lib.php) saves inbound email attachments during the recordjoinpiece, project and ticket operations using the raw filename from the message's MIME headers ($attachment->getName(), $attachment->getFilename(), or getAttachments()).
- In
htdocs/emailcollector/lib/emailcollector.lib.php, the globalsaveAttachment($target, $name, $content)splits$nameon its last dot into$filenameand$ext, builds$filepath = $path . $filename . '.' . $ext, and passes$filepathdirectly tofile_put_contents($filepath, $content). - In
htdocs/emailcollector/class/emailcollector.class.php, the privateEmailCollector::saveAttachment($destdir, $filename, $content)callsfile_put_contents($destdir.'/'.$filename, $content)directly.
Because neither function strips directory traversal sequences (..) before calling file_put_contents(), an inbound email attachment whose MIME filename contains ../ escapes the per-object directory (documents/<module>/<ref>/) and writes attacker-controlled content into higher directories of documents or into htdocs.
Upstream commit 264a44defb5e438689c75679617f6edc4c038abc fixes this by replacing the duplicate attachment helpers with EmailCollector::saveEmailCollectorAttachmentsToDir(), which sanitizes the destination directory with dol_sanitizePathName() and reduces each attachment name to a safe basename with dol_sanitizeFileName().
Official description
Dolibarr 9.0.0 through 23.0.4 saves inbound email attachments under the name supplied in the message's MIME headers without reducing it to a safe basename. The global saveAttachment() in htdocs/emailcollector/lib/emailcollector.lib.php builds $filepath = $path . $filename . '.' . $ext and hands it to file_put_contents(), and the private saveAttachment() in htdocs/emailcollector/class/emailcollector.class.php writes to $destdir.'/'.$filename; the name reaches both from the attachment's own getName() or getFilename() value by way of the record-join, create-ticket and create-project operations. A traversal sequence in the filename therefore survives intact, so any sender who can email a mailbox that an EmailCollector monitors, which is the module's ordinary use for a support or ticket inbox, can place attacker-controlled content outside the per-object attachment directory without holding a Dolibarr account. Under the hardened layout Dolibarr's SECURITY.md requires, with htdocs read-only, the write is confined to the documents tree and corrupts or forges other objects' documents; where htdocs is writable the same primitive reaches a web-executable path. Version 24.0.0 applies dol_sanitizePathName() and dol_sanitizeFileName() before the write.
Sources
More references from NVD (4)
Mitigation
A legitimate EmailCollector attachment is written inside a per-object directory at depth two or deeper below documents (documents/<module>/<ref>/<file>, or documents/<module>/<ref>/thumbs/<file> for image thumbnails) and never inside htdocs or with a PHP script extension.
| Hook | Refuses when | Effect |
|---|---|---|
lsm/inode_create |
Current process executable is php*, apache2 or httpd, and the target dentry is under htdocs, directly inside documents/ or documents/<module>/, or under documents with a .php, .phtml, .phar, .php3-.php8 or .inc suffix |
openat(..., O_CREAT, ...) from file_put_contents() fails with EPERM; no traversed file is created |
lsm/file_open |
Current process executable is php*, apache2 or httpd, file->f_mode & FMODE_WRITE is set, and the target dentry matches the same path or extension check |
Opening an existing file for overwrite outside the per-object directory or under htdocs fails with EPERM |
Each refusal increments its counter in the refused per-CPU array map (key 0 for inode_create, key 1 for file_open).
Scope and limitations
- Matches processes whose executable starts with
phpor equalsapache2orhttpd. - Assumes Dolibarr's web root directory is named
htdocsand its data root directory ($dolibarr_main_data_root) is nameddocuments. Deployments that rename those directories are not matched. - Normal attachments saved inside
documents/<module>/<ref>/<filename>with non-PHP extensions continue to work while the upatch is loaded.
The policy
207 lines of BPF C, attached at lsm/inode_create and lsm/file_open.
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
#define EPERM 1
#define FMODE_WRITE 0x2
char _license[] SEC("license") = "Dual BSD/GPL";
enum {
REFUSED_CREATE,
REFUSED_OPEN,
NR_COUNTERS,
};
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, NR_COUNTERS);
__type(key, __u32);
__type(value, __u64);
} refused SEC(".maps");
static __always_inline void count(__u32 key)
{
__u64 *value = bpf_map_lookup_elem(&refused, &key);
if (value)
__sync_fetch_and_add(value, 1);
}
static __always_inline int earlier_verdict(int ret)
{
return ret >= -4095 && ret < 0 ? ret : -EPERM;
}
static __always_inline bool is_documents_dir(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
char buf[10] = {};
if (!dentry || BPF_CORE_READ(dentry, d_name.len) != 9 || !name)
return false;
if (bpf_probe_read_kernel(buf, 9, name))
return false;
return buf[0] == 'd' && buf[1] == 'o' && buf[2] == 'c' &&
buf[3] == 'u' && buf[4] == 'm' && buf[5] == 'e' &&
buf[6] == 'n' && buf[7] == 't' && buf[8] == 's';
}
static __always_inline bool is_htdocs_dir(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
char buf[8] = {};
if (!dentry || BPF_CORE_READ(dentry, d_name.len) != 6 || !name)
return false;
if (bpf_probe_read_kernel(buf, 6, name))
return false;
return buf[0] == 'h' && buf[1] == 't' && buf[2] == 'd' &&
buf[3] == 'o' && buf[4] == 'c' && buf[5] == 's';
}
static __always_inline bool has_php_ext(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
__u32 len = BPF_CORE_READ(dentry, d_name.len);
char tail[6] = {};
if (!dentry || !name || len < 4 || len > 255)
return false;
if (bpf_probe_read_kernel(tail, 4, name + len - 4))
return false;
if (tail[0] == '.' && tail[1] == 'p' && tail[2] == 'h' && tail[3] == 'p')
return true;
if (tail[0] == '.' && tail[1] == 'i' && tail[2] == 'n' && tail[3] == 'c')
return true;
if (len < 5)
return false;
if (bpf_probe_read_kernel(tail, 5, name + len - 5))
return false;
if (tail[0] == '.' && tail[1] == 'p' && tail[2] == 'h') {
if (tail[3] == 'p' && tail[4] >= '3' && tail[4] <= '8')
return true;
if (tail[3] == 'a' && tail[4] == 'r')
return true;
}
if (len < 6)
return false;
if (bpf_probe_read_kernel(tail, 6, name + len - 6))
return false;
return tail[0] == '.' && tail[1] == 'p' && tail[2] == 'h' &&
tail[3] == 't' && tail[4] == 'm' && tail[5] == 'l';
}
static __always_inline bool under_htdocs(const struct dentry *dentry)
{
const struct dentry *cur = BPF_CORE_READ(dentry, d_parent);
for (int i = 0; i < 6; i++) {
const struct dentry *parent;
if (!cur)
return false;
if (is_htdocs_dir(cur))
return true;
parent = BPF_CORE_READ(cur, d_parent);
if (parent == cur)
return false;
cur = parent;
}
return false;
}
static __always_inline bool under_documents(const struct dentry *dentry)
{
const struct dentry *cur = BPF_CORE_READ(dentry, d_parent);
for (int i = 0; i < 6; i++) {
const struct dentry *parent;
if (!cur)
return false;
if (is_documents_dir(cur))
return true;
parent = BPF_CORE_READ(cur, d_parent);
if (parent == cur)
return false;
cur = parent;
}
return false;
}
static __always_inline bool is_traversed_dolibarr_write(const struct dentry *dentry)
{
const struct dentry *p1;
const struct dentry *p2;
if (!dentry)
return false;
if (under_htdocs(dentry))
return true;
p1 = BPF_CORE_READ(dentry, d_parent);
if (!p1)
return false;
if (is_documents_dir(p1))
return true;
p2 = BPF_CORE_READ(p1, d_parent);
if (p2 && is_documents_dir(p2))
return true;
if (has_php_ext(dentry) && under_documents(dentry))
return true;
return false;
}
static __always_inline bool current_is_php_runtime(void)
{
struct task_struct *task = bpf_get_current_task_btf();
const struct dentry *exe = BPF_CORE_READ(task, mm, exe_file, f_path.dentry);
const unsigned char *name = BPF_CORE_READ(exe, d_name.name);
__u32 len = BPF_CORE_READ(exe, d_name.len);
char buf[8] = {};
if (!exe || len < 3 || !name)
return false;
if (bpf_probe_read_kernel(buf, 7, name))
return false;
if (buf[0] == 'p' && buf[1] == 'h' && buf[2] == 'p')
return true;
if (len == 7 && buf[0] == 'a' && buf[1] == 'p' && buf[2] == 'a' &&
buf[3] == 'c' && buf[4] == 'h' && buf[5] == 'e' && buf[6] == '2')
return true;
if (len == 5 && buf[0] == 'h' && buf[1] == 't' && buf[2] == 't' &&
buf[3] == 'p' && buf[4] == 'd')
return true;
return false;
}
SEC("lsm/inode_create")
int BPF_PROG(cve_2026_81730_create, const struct mnt_idmap *idmap,
struct inode *dir, struct dentry *dentry, umode_t mode, int ret)
{
if (ret)
return earlier_verdict(ret);
if (!is_traversed_dolibarr_write(dentry) || !current_is_php_runtime())
return 0;
count(REFUSED_CREATE);
return -EPERM;
}
SEC("lsm/file_open")
int BPF_PROG(cve_2026_81730_open, struct file *file, int ret)
{
const struct dentry *dentry = file->f_path.dentry;
if (ret)
return earlier_verdict(ret);
if (!(file->f_mode & FMODE_WRITE))
return 0;
if (!is_traversed_dolibarr_write(dentry) || !current_is_php_runtime())
return 0;
count(REFUSED_OPEN);
return -EPERM;
}
The package: name, license, the program and the CVE it fixes.
[package]
name = "cve-2026-81730"
description = "Refuses Dolibarr EmailCollector attachment writes that traverse outside per-object document directories or into htdocs to mitigate CVE-2026-81730"
license = "GPL-2.0 OR BSD-2-Clause"
[[upatches]]
source = "cve-2026-81730-dolibarr-block.bpf.c"
[upatches.tree]
id = "cve-2026-81730-dolibarr-block"
fixes = ["CVE-2026-81730"]
Process
How this upatch was written, checked and reviewed, from the registry’s history.
- 27 Aug 2026CVECVE published
No human review is recorded on GitHub for this upatch yet.
Evidence
On a vulnerable Dolibarr 23.0.4, the loaded upatch refused the EmailCollector attachment traversal write into documents/ while allowing the normal attachment write inside documents/ticket/<ref>/.
- Tested
- 25 Nov 2026
- Target
- Dolibarr 23.0.4
- Kernel
- 7.4-shirudo-ci-20261123
- Architecture
- x86_64
| State | EmailCollector traversal probe (../../upatch-probe-<token>.txt) | Normal ticket attachment (upatch-safe-<token>.txt) |
|---|---|---|
| Before loading | reached — wrote upatch-probe-dd9f7f92ee50.txt into documents/ | wrote into documents/ticket/<ref>/ |
| Upatch loaded | blocked — writing upatch-probe-9818fd4df718.txt into documents/ was refused | wrote upatch-safe-9818fd4df718.txt into documents/ticket/<ref>/ |
| After unloading | reached — wrote upatch-probe-96555bc3121d.txt into documents/ | wrote into documents/ticket/<ref>/ |
tools-test.log Output of tools/test --setup before, while and after the upatch was loaded on Dolibarr 23.0.4.
tools/test --setup, 2026-11-25T15:30:23Z Target: shirudo test VM, Linux 7.4-shirudo-ci-20261123, x86_64, swtpm cve-2026-81730 setup done DOLIBARR_URL=http://127.0.0.1:18080 DOLIBARR_DOCUMENTS_DIR=/opt/upatch-payload/cve-2026-81730/dolibarr-23.0.4/documents DOLIBARR_IMAP_PORT=11143 before reached EmailCollector wrote upatch-probe-dd9f7f92ee50.txt outside ticket/<ref>/ into documents/ loaded blocked EmailCollector wrote upatch-safe-9818fd4df718.txt in ticket/<ref>/ but writing upatch-probe-9818fd4df718.txt into documents/ was refused after reached EmailCollector wrote upatch-probe-96555bc3121d.txt outside ticket/<ref>/ into documents/ PASS: reached before, blocked while loaded, reached again after
Use it
Build the upatch from source, sign it with your own shirudo key, and publish it to your own OCI registry. Machines that follow your upatch tree load it within about a minute.
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-81730shirudo bpm push build/packages/cve-2026-81730-1.0.0.bee oci://<registry>/<namespace>/cve-2026-81730 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-81730-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>