CVE-2026-136625 — CWE-61
ai-memory 2.6.0 before 3.3.2 contains a symlink following vulnerability in the ai-memory-wikisync companion that allows local attackers to overwrite arbitrary files by planting symlinks at predictable temporary names. Attackers can place a .wikisync-tmp-<page>.md symlink in a shared destination so atomic_write() truncates and overwrites its target with the victim's privileges.
ai-memory 2.6.0 before 3.3.2 contains a symlink following vulnerability in the ai-memory-wikisync companion that allows local attackers to overwrite arbitrary files by planting symlinks at predictable temporary names. Attackers can place a .wikisync-tmp-<page>.md symlink in a shared destination so atomic_write() truncates and overwrites its target with the victim's privileges.
🎯 What is this vulnerability?
This vulnerability is a Symlink Following flaw (CWE-61) within the ai-memory-wikisync companion tool, specifically affecting versions of ai-memory prior to 3.3.2.
The core technical failure lies in the implementation of the atomic_write() function. Standard atomic write operations typically involve:
1. Creating a temporary file in the same directory as the destination.
2. Writing data to the temporary file.
3. Renaming (or linking) the temporary file to the final destination name.
In this vulnerable implementation, the code likely uses a predictable naming convention for the temporary file (e.g., .wikisync-tmp-<page>.md) and fails to verify that this path does not already exist as a symbolic link before performing the write operation. Specifically, if the code uses open() with O_CREAT or similar flags without O_NOFOLLOW, or if it performs a truncate()/write() on a file descriptor obtained from a path that is a symlink, the kernel will resolve the symlink and write to the target file.
Because the temporary filename is predictable (based on the <page> identifier), a local attacker can pre-plant a symlink at this exact path pointing to an arbitrary file (e.g., /etc/passwd, ~/.ssh/authorized_keys, or a system binary). When the victim user runs the ai-memory-wikisync process, the atomic_write() function follows the symlink, truncates the target file, and overwrites it with the content intended for the wiki page. This results in Arbitrary File Overwrite with the privileges of the victim user.
⚡ Attack Chain
1. Discovery & Reconnaissance
- Identify Target: The attacker must have local access to the system (e.g., shared hosting environment, multi-user server, or compromised low-privilege account).
- Version Check: Verify that
ai-memoryis installed and the version is< 3.3.2. This can be done by checking package managers (pip show ai-memory,npm list ai-memory) or inspecting the binary/library version strings. - Identify Victim Process: Determine which user account runs the
ai-memory-wikisyncservice or command. The attacker needs to know the destination directory where the tool writes files and the naming convention for the temporary files (.wikisync-tmp-<page>.md). - Local access to the destination directory (or the ability to create files in a directory writable by the victim).
- Knowledge of the
<page>identifier that the victim will sync.
2. Exploitation
The attacker exploits the race condition/predictable temp file by planting a symlink.Prerequisites:
Step-by-Step Exploitation (Illustrative PoC):
Assume the victim user victim runs ai-memory-wikisync which attempts to write to /home/victim/wiki/page1.md. The tool creates a temp file /home/victim/wiki/.wikisync-tmp-page1.md.
1. Attacker (low-privilege user attacker) creates a symlink:
# The attacker must have write access to the directory where the temp file is created.
# If the directory is owned by 'victim' and not writable by 'attacker', this specific vector fails.
# However, if the temp file is created in a world-writable directory (e.g., /tmp) or a shared directory, this works.
# Let's assume the temp file is created in /tmp for this illustrative example, or the destination dir is group-writable.
# Target: Overwrite /etc/cron.d/attacker (or ~/.ssh/authorized_keys)
# Temp file name: .wikisync-tmp-page1.md
ln -s /etc/cron.d/attacker /tmp/.wikisync-tmp-page1.md2. Victim triggers the sync:
The victim runs the sync command. The atomic_write() function in ai-memory attempts to write to /tmp/.wikisync-tmp-page1.md.
* The OS resolves the symlink to /etc/cron.d/attacker.
* The function opens the file (following the symlink), truncates it, and writes the wiki content.
3. Result:
The file /etc/cron.d/attacker now contains the wiki page content. If the attacker crafts the wiki content to be a valid cron job, they achieve code execution as the victim user (or root, if the victim is root).
Alternative: Overwriting SSH Keys
# Attacker plants symlink
ln -s /home/victim/.ssh/authorized_keys /tmp/.wikisync-tmp-page1.md
# Attacker prepares malicious SSH public key in the wiki content
echo "ssh-rsa AAAAB3... attacker@attacker" > /tmp/malicious_key
# When victim syncs 'page1', the authorized_keys file is overwritten with the attacker's key.Note: The exact path of the temporary file depends on the implementation. If it is in the destination directory, the attacker needs write access to that directory. If it is in /tmp, the attacker needs write access to /tmp (usually true) and the ability to predict the filename.
3. Post-Exploitation
sudo privileges or is root, the attacker can escalate to full system control..bashrc, .profile), the attacker establishes persistence.~/.ssh/authorized_keys, the attacker can SSH into the victim's account./etc/passwd, /etc/shadow if permissions allow) to cause denial of service or lock out legitimate users.🌍 Real World Impact
ai-memory-wikisync runs in a shared container or build agent, a malicious build step or compromised dependency could plant symlinks to overwrite build artifacts or deployment scripts.
* Multi-User Servers: Any scenario where a low-privilege user can write to a directory where a high-privilege user's ai-memory process creates temporary files.🛡️ Remediation & Mitigation
1. Upgrade
ai-memory < 3.3.2ai-memory 3.3.2 and later.pip install --upgrade ai-memory>=3.3.2
# or
npm install ai-memory@^3.3.22. Workarounds (If Upgrade is Not Possible)
ai-memory-wikisync is not writable by other users. If the temp files are created in the destination directory, this prevents symlink planting.chmod 700 /path/to/wiki/destination
chown victim:group /path/to/wiki/destinationO_NOFOLLOW: If you have access to the source code, patch the atomic_write() function to open temporary files with the O_NOFOLLOW flag (on Linux) or equivalent to prevent following symlinks.mkstemp(): Replace predictable temporary file names with mkstemp() or tempfile.mkstemp(), which generates unique, unpredictable filenames and creates the file with O_EXCL (fail if exists).ai-memory-wikisync: If the feature is not required, disable it or remove the companion tool.3. Detection
File Integrity Monitoring (FIM): Monitor critical files (e.g.,/etc/cron.d/, ~/.ssh/authorized_keys, system binaries) for unexpected modifications.
auditd logs for unlink or rename operations on temporary files in shared directories.ai-memory operates.find /path/to/wiki/destination -type l -name ".wikisync-tmp-*"ai-memory-wikisync errors or warnings related to file permission issues or unexpected file contents.⚠️ Urgency
ai-memory-wikisync runs with elevated privileges. The ability to overwrite arbitrary files with the victim's privileges is a severe integrity and availability risk.[🤖 CVE Professor AI Security Engine]