Skip to content

Symlink following in file deletion enables arbitrary file destruction #25

Closed

Description

@0x-man

Labels: bug, security

Summary

CleaningEngine.cleanItems() and ScanEngine.scanDirectory() do not resolve symlinks before deleting files. A symlink planted in any scanned directory (e.g. ~/Library/Caches/) can redirect deletion to arbitrary user-accessible paths like ~/.ssh/, ~/Documents/, or ~/.gnupg/.

Steps to reproduce

# 1. Create a symlink in a scanned cache directory
ln -s ~/.ssh ~/Library/Caches/fake-cache-entry
 
# 2. Run PureMac → Smart Scan
# 3. The symlink appears as a scannable cache item (auto-selected)
# 4. Click "Clean" → ~/.ssh is deleted

Impact

Any process running as the current user — malware, a rogue npm postinstall script, or even a cron job — can plant symlinks before a scheduled auto-clean runs. Combined with autoClean: true in SchedulerService, this becomes a zero-interaction attack that silently destroys targeted files.

Affected code

  • Services/CleaningEngine.swift:31 — removeItem(atPath:) follows symlinks
  • Services/ScanEngine.swift:302-347 — scanDirectory() doesn't check for symlinks

Suggested fix

Before any deletion, resolve the real path and verify it's still inside the expected scan root:

// Add to CleaningEngine, call before every removeItem
private func isSafeToDelete(path: String, allowedRoots: [String]) -> Bool {
    let resolved = URL(fileURLWithPath: path)
        .resolvingSymlinksInPath()
        .path
 
    // Reject if the resolved path escapes all allowed roots
    return allowedRoots.contains { root in
        resolved.hasPrefix(root)
    }
}

Each scan category already knows its root paths — pass them through to the cleaning engine and validate before deletion.

Additionally, in scanDirectory(), check FileManager.attributesOfItem(atPath:)[.type] for .typeSymbolicLink and either skip or flag symlinks to the user rather than treating them as normal cache entries.

Activity

  1. momenbasel commented on Apr 14, 2026

    @momenbasel
    Owner

    Valid finding. This is a real attack vector — especially dangerous combined with autoClean: true in SchedulerService since it becomes zero-interaction.

    Plan:

    1. ScanEngine — skip symlinks in scanDirectory() by checking FileAttributeType.typeSymbolicLink:
    let attrs = try fileManager.attributesOfItem(atPath: fullPath)
    if let fileType = attrs[.type] as? FileAttributeType, fileType == .typeSymbolicLink {
        continue // Skip symlinks entirely
    }
    1. CleaningEngine — resolve real path before deletion and validate against allowed roots:
    let resolved = URL(fileURLWithPath: path).resolvingSymlinksInPath().path
    guard allowedRoots.contains(where: { resolved.hasPrefix($0) }) else {
        // Log warning, skip deletion
        continue
    }
    1. Each CleaningCategory already defines its scan paths — those become the allowlist passed to the cleaning engine.

    Prioritizing this. Will tag the fix PR with this issue.

  2. added
    bugSomething isn't working
    securitySecurity vulnerability or hardening
    on Apr 14, 2026
  3. momenbasel commented on Apr 14, 2026

    @momenbasel
    Owner

    Hey @0x-man! You're credited in the v2.0 README under the Acknowledgments section for your symlink security report. That was a critical find that made PureMac significantly safer. Thank you!

  4. added a commit that references this issue on Apr 15, 2026
    cb813ab
  5. added a commit that references this issue on May 24, 2026
    fd703eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritySecurity vulnerability or hardening

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions