Research/CVE-2025-61035

Arbitrary File Overwrite via Symlink and Insecure File Permissions in seffaflik

A local vulnerability in the seffaflik Python package that allows arbitrary file overwrite through symlink attacks and exposes sensitive identity data via insecure default permissions.

CWE
CWE-276 · CWE-59
Vendor
seffaflik (PyPI)
Affected
≤ 0.0.9
Disclosed
Oct 2025

TL;DR

The seffaflik.Kimlik() function creates identity files with world-readable/writable permissions (0777) and is vulnerable to symlink attacks. An attacker can pre-create ~/.seffaflik/.kimlik as a symlink to overwrite arbitrary files, while overly permissive defaults expose sensitive identity data to other local users.

Summary

A local vulnerability in the seffaflik Python package (<= 0.0.9) allows arbitrary file overwrite through a symlink attack during identity file creation in the seffaflik.Kimlik() function. In addition, insecure default permissions expose sensitive identity data to other local users. This issue corresponds to CWE-276: Incorrect Default Permissions and can lead to both information disclosure and denial of service.

Affected Component

  • seffaflik.Kimlik() function (identity file creation logic)

Affected Versions

  • seffaflik <= 0.0.9

Vulnerability Classification

  • CWE-276: Incorrect Default Permissions
  • CWE-59: Improper Link Resolution Before File Access ('Link Following')

Vulnerability Types

  • Arbitrary File Overwrite via Symlink
  • World-readable / world-writable secret file
  • Insecure default file and directory permissions

Impact

Information Disclosure

The identity file ~/.seffaflik/.kimlik is created with permission mode 0777, and the parent directory ~/.seffaflik with 0775. These overly permissive settings allow other local users on the same system to read or modify sensitive identity-related data.

Arbitrary File Overwrite

A local attacker can pre-create a symlink at the identity file path, causing the application to overwrite arbitrary files writable by the victim user when seffaflik.Kimlik() is executed.

Potential Consequences

  • Confidentiality: Exposure of sensitive identity data to unauthorized local users
  • Integrity: Modification or corruption of arbitrary files via symlink attack
  • Availability: Denial of service through overwriting critical system or application files

Attack Vector

A local attacker can pre-create the path ~/.seffaflik/.kimlik as a symbolic link pointing to an arbitrary target file. When the victim executes seffaflik.Kimlik(), the function follows the symlink and overwrites the referenced file. Because no validation or symlink protection is in place, the write operation is performed on the attacker-controlled target. The insecure permission modes further amplify the impact by exposing secrets to other local users.

Prerequisites

  • Local access to the target system
  • Ability to create files in the victim's home directory or access to shared temporary directories
  • Victim must execute code that calls seffaflik.Kimlik()

Proof of Concept

bash
# Attacker creates the directory structure
mkdir -p ~/.seffaflik

# Create a symlink pointing to a target file (.bashrc)
ln -s ~/.bashrc ~/.seffaflik/.kimlik

Step 2: Victim Executes seffaflik.Kimlik()

python
from seffaflik import Kimlik

# When victim runs this, it follows the symlink and overwrites .bashrc
identity = Kimlik()

Step 3: Verify File Overwrite

bash
# The target file (.bashrc) has been overwritten with identity data
cat ~/.bashrc

Step 4: Verify Insecure Permissions

bash
# Check permissions on the identity directory and file
ls -la ~/.seffaflik/
# Expected output shows world-readable/writable permissions:
# drwxrwxr-x (0775) for directory
# -rwxrwxrwx (0777) for .kimlik file

Root Cause Analysis

The vulnerability stems from three fundamental issues:

  1. No Symlink Validation: The identity file creation logic does not check whether ~/.seffaflik/.kimlik is a symbolic link before writing to it.

  2. Insecure Default Permissions: Files and directories are created with overly permissive modes (0777 for files, 0775 for directories), allowing unauthorized access by other local users.

  3. Lack of Atomic Operations: The code does not use secure, atomic file creation mechanisms (e.g., os.O_CREAT | os.O_EXCL) that would prevent race conditions and symlink attacks.

For Developers

  1. Use Secure File Creation:
python
import os

# Open file with O_CREAT | O_EXCL to prevent symlink attacks
fd = os.open(filepath, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600)
with os.fdopen(fd, 'w') as f:
    f.write(identity_data)
  1. Set Restrictive Permissions:
python
# Directory: 0700 (rwx------)
os.makedirs(directory, mode=0o700, exist_ok=True)

# File: 0600 (rw-------)
os.chmod(filepath, 0o600)
  1. Validate File Paths:
python
# Check if path is a symlink before writing
if os.path.islink(filepath):
    raise SecurityError("Refusing to write to symlink")

For Users

  1. Update to a patched version of seffaflik when available
  2. Review and restrict permissions on ~/.seffaflik/ directory:
bash
chmod 700 ~/.seffaflik
chmod 600 ~/.seffaflik/.kimlik
  1. Monitor for unexpected symlinks in your home directory

References

Disclosure Timeline

  • 2025-09-01 – Vulnerability discovered
  • 2025-10-22 – CVE-2025-61035 published