2025-12-11 15:10:49 +08:00
# Mole Security Audit Report
2025-12-28 21:30:39 +08:00
<div align="center">
2025-12-11 15:19:26 +08:00
2026-01-26 15:43:11 +08:00
**Status:** PASSED | **Risk Level: ** LOW | **Version: ** 1.23.2 (2026-01-26)
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
</div>
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
---
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
## Audit Overview
2025-12-26 18:39:53 +08:00
2025-12-28 21:30:39 +08:00
| Attribute | Details |
|-----------|---------|
2026-01-26 15:43:11 +08:00
| Audit Date | January 26, 2026 |
2025-12-28 21:30:39 +08:00
| Audit Conclusion | **PASSED ** |
2026-01-26 15:43:11 +08:00
| Mole Version | V1.23.2 |
2025-12-28 21:30:39 +08:00
| Audited Branch | `main` (HEAD) |
| Scope | Shell scripts, Go binaries, Configuration |
| Methodology | Static analysis, Threat modeling, Code review |
| Review Cycle | Every 6 months or after major feature additions |
2026-01-26 15:43:11 +08:00
| Next Review | July 2026 |
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
**Key Findings:**
2025-12-11 15:18:04 +08:00
2026-01-09 17:13:34 +08:00
- Multi-layer validation effectively blocks risky system modifications.
- Conservative cleaning logic ensures safety (e.g., 60-day dormancy rule).
- Comprehensive protection for VPNs, AI tools, and core system components.
2026-01-26 15:43:11 +08:00
- Operations logging improves traceability while remaining optional (MO_NO_OPLOG=1).
2026-01-09 17:13:34 +08:00
- Atomic operations prevent state corruption during crashes.
- Dry-run and whitelist features give users full control.
- Installer cleanup scans safely and requires user confirmation.
2025-12-11 15:18:04 +08:00
2026-01-26 15:43:11 +08:00
**Recent Remediations:**
2026-01-26 20:27:46 +08:00
- **Uninstall Audit (Jan 2026)**: Enhanced security in uninstall logic per comprehensive security review.
- `stop_launch_services()` now validates bundle_id format (reverse-DNS) before use in find patterns to prevent glob injection attacks.
- `find_app_files()` LaunchAgents search now excludes common words (Music, Notes, etc.) to prevent false positive matches.
- `remove_file_list()` symlink handling documented with detailed security comments explaining the TOCTOU protection bypass rationale.
- `brew_uninstall_cask()` timeout handling improved: exit code 124 (timeout) now returns failure immediately without verification.
2026-01-26 15:43:11 +08:00
- Symlink cleanup in `bin/clean.sh` now routes through `safe_remove` for target validation.
- Orphaned helper cleanup in `lib/clean/apps.sh` now uses `safe_sudo_remove` .
- ByHost preference cleanup in `lib/uninstall/batch.sh` validates bundle IDs and deletes via `safe_remove` .
2025-12-28 21:30:39 +08:00
---
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
## Security Philosophy
2025-12-11 15:18:04 +08:00
2025-12-28 21:30:39 +08:00
**Core Principle: "Do No Harm"**
2025-12-11 15:18:04 +08:00
2026-01-09 17:13:34 +08:00
We built Mole on a **Zero Trust ** architecture for filesystem operations. Every modification request is treated as dangerous until it passes strict validation.
2025-12-11 15:58:26 +08:00
2025-12-28 21:30:39 +08:00
**Guiding Priorities:**
2025-12-11 15:58:26 +08:00
2026-01-09 17:13:34 +08:00
1. **System Stability First ** - We'd rather leave 1GB of junk than delete 1KB of your data.
2. **Conservative by Default ** - High-risk operations always require explicit confirmation.
3. **Fail Safe ** - When in doubt, we abort immediately.
4. **Transparency ** - Every operation is logged and allows a preview via dry-run mode.
2025-12-18 17:02:04 +08:00
2025-12-28 21:30:39 +08:00
---
2025-12-11 15:58:26 +08:00
2025-12-28 21:30:39 +08:00
## Threat Model
2025-12-13 12:16:25 +08:00
2025-12-28 21:30:39 +08:00
### Attack Vectors & Mitigations
2025-12-22 11:24:04 +08:00
2025-12-28 21:30:39 +08:00
| Threat | Risk Level | Mitigation | Status |
|--------|------------|------------|--------|
| Accidental System File Deletion | Critical | Multi-layer path validation, system directory blocklist | Mitigated |
| Path Traversal Attack | High | Absolute path enforcement, relative path rejection | Mitigated |
| Symlink Exploitation | High | Symlink detection in privileged mode | Mitigated |
| Command Injection | High | Control character filtering, strict validation | Mitigated |
| Empty Variable Deletion | High | Empty path validation, defensive checks | Mitigated |
| Race Conditions | Medium | Atomic operations, process isolation | Mitigated |
| Network Mount Hangs | Medium | Timeout protection, volume type detection | Mitigated |
| Privilege Escalation | Medium | Restricted sudo scope, user home validation | Mitigated |
| False Positive Deletion | Medium | 3-char minimum, fuzzy matching disabled | Mitigated |
| VPN Configuration Loss | Medium | Comprehensive VPN/proxy whitelist | Mitigated |
2025-12-14 08:57:27 +08:00
2025-12-28 21:30:39 +08:00
---
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
## Defense Architecture
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
### Multi-Layered Validation System
2025-12-11 15:10:49 +08:00
2026-01-09 17:13:34 +08:00
All automated operations pass through hardened middleware (`lib/core/file_ops.sh` ) with 4 layers of validation:
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
#### Layer 1: Input Sanitization
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
| Control | Protection Against |
|---------|---------------------|
| Absolute Path Enforcement | Path traversal attacks (`../etc` ) |
| Control Character Filtering | Command injection (`\n` , `\r` , `\0` ) |
| Empty Variable Protection | Accidental `rm -rf /` |
| Secure Temp Workspaces | Data leakage, race conditions |
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
**Code:** `lib/core/file_ops.sh:validate_path_for_deletion()`
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
#### Layer 2: System Path Protection ("Iron Dome")
2025-12-11 15:10:49 +08:00
2025-12-28 21:30:39 +08:00
Even with `sudo` , these paths are **unconditionally blocked ** :
```bash
/ # Root filesystem
/System # macOS system files
/bin, /sbin, /usr # Core binaries
/etc, /var # System configuration
/Library/Extensions # Kernel extensions
2026-01-15 21:02:13 +08:00
/private # System-private directories
2025-12-28 21:30:39 +08:00
```
2026-01-15 21:02:13 +08:00
**Exceptions:**
- `/System/Library/Caches/com.apple.coresymbolicationd/data` (safe, rebuildable cache)
- `/private/tmp` , `/private/var/tmp` , `/private/var/log` , `/private/var/folders`
- `/private/var/db/diagnostics` , `/private/var/db/DiagnosticPipeline` , `/private/var/db/powerlog` , `/private/var/db/reportmemoryexception`
2025-12-28 21:30:39 +08:00
**Code:** `lib/core/file_ops.sh:60-78`
#### Layer 3: Symlink Detection
For privileged operations, pre-flight checks prevent symlink-based attacks:
2026-01-09 17:13:34 +08:00
- Detects symlinks from cache folders pointing to system files.
- Refuses recursive deletion of symbolic links in sudo mode.
- Validates real path vs. symlink target.
2025-12-28 21:30:39 +08:00
**Code:** `lib/core/file_ops.sh:safe_sudo_recursive_delete()`
#### Layer 4: Permission Management
When running with `sudo` :
2026-01-09 17:13:34 +08:00
- Auto-corrects ownership back to user (`chown -R` ).
- Restricts operations to the user's home directory.
- Enforces multiple validation checkpoints.
2025-12-28 21:30:39 +08:00
### Interactive Analyzer (Go)
2026-01-09 17:13:34 +08:00
The analyzer (`mo analyze` ) uses a distinct security model:
2025-12-28 21:30:39 +08:00
2026-01-09 17:13:34 +08:00
- Runs with standard user permissions only.
- Respects macOS System Integrity Protection (SIP).
2026-01-10 07:24:58 +08:00
- **Two-Key Confirmation:** Deletion requires ⌫ (Delete) to enter confirmation mode, then Enter to confirm. Prevents accidental double-press of the same key.
- **Trash Instead of Delete:** Files are moved to macOS Trash using Finder's native API, allowing easy recovery if needed.
2026-01-09 17:13:34 +08:00
- OS-level enforcement (cannot delete `/System` due to Read-Only Volume).
2025-12-28 21:30:39 +08:00
**Code:** `cmd/analyze/*.go`
---
## Safety Mechanisms
### Conservative Cleaning Logic
#### The "60-Day Rule" for Orphaned Data
| Step | Verification | Criterion |
|------|--------------|-----------|
| 1. App Check | All installation locations | Must be missing from `/Applications` , `~/Applications` , `/System/Applications` |
| 2. Dormancy | Modification timestamps | Untouched for ≥60 days |
2026-01-09 17:13:34 +08:00
| 3. Vendor Whitelist | Cross-reference database | Adobe, Microsoft, and Google resources are protected |
2025-12-28 21:30:39 +08:00
**Code:** `lib/clean/apps.sh:orphan_detection()`
2026-01-11 09:55:18 +08:00
#### Developer Tool Ecosystems (Consolidated)
2026-01-11 09:26:04 +08:00
2026-01-11 09:55:18 +08:00
Support for 20+ languages (Rust, Go, Node, Python, JVM, Mobile, Elixir, Haskell, OCaml, etc.) with strict safety checks:
2026-01-11 09:26:04 +08:00
2026-01-11 09:55:18 +08:00
- **Global Optimization:** The core `safe_clean` function now intelligently checks parent directories before attempting wildcard cleanups, eliminating overhead for missing tools across the entire system.
- **Safe Targets:** Only volatile caches are cleaned (e.g., `~/.cargo/registry/cache` , `~/.gradle/caches` ).
- **Protected Paths:** Critical directories like `~/.cargo/bin` , `~/.mix/archives` , `~/.rustup` toolchains, and `~/.stack/programs` are explicitly **excluded ** .
2026-01-11 09:26:04 +08:00
2025-12-28 21:30:39 +08:00
#### Active Uninstallation Heuristics
For user-selected app removal:
- **Sanitized Name Matching:** "Visual Studio Code" → `VisualStudioCode` , `.vscode`
- **Safety Limit:** 3-char minimum (prevents "Go" matching "Google")
2026-01-09 17:13:34 +08:00
- **Disabled:** Fuzzy matching and wildcard expansion for short names.
- **User Confirmation:** Required before deletion.
2026-01-16 09:54:36 +08:00
- **Receipt Scans:** BOM-derived files are restricted to app-specific prefixes (e.g., `/Applications` , `/Library/Application Support` ). Shared directories like `/Library/Frameworks` are **excluded ** to prevent collateral damage.
2025-12-28 21:30:39 +08:00
**Code:** `lib/clean/apps.sh:uninstall_app()`
#### System Protection Policies
| Protected Category | Scope | Reason |
|--------------------|-------|--------|
| System Integrity Protection | `/Library/Updates` , `/System/*` | Respects macOS Read-Only Volume |
| Spotlight & System UI | `~/Library/Metadata/CoreSpotlight` | Prevents UI corruption |
| System Components | Control Center, System Settings, TCC | Centralized detection via `is_critical_system_component()` |
2026-01-11 08:51:01 +08:00
| Time Machine | Local snapshots, backups | Runtime activity detection (backup running, snapshots mounted), fails safe if status indeterminate |
2025-12-28 21:30:39 +08:00
| VPN & Proxy | Shadowsocks, V2Ray, Tailscale, Clash | Protects network configs |
2026-01-09 17:13:34 +08:00
| AI & LLM Tools | Cursor, Claude, ChatGPT, Ollama, LM Studio | Protects models, tokens, and sessions |
2025-12-29 19:06:04 +08:00
| Startup Items | `com.apple.*` LaunchAgents/Daemons | System items unconditionally skipped |
2026-01-15 11:39:33 +08:00
**LaunchAgent/LaunchDaemon Cleanup During Uninstallation:**
2025-12-29 19:06:04 +08:00
2026-01-15 11:39:33 +08:00
When users uninstall applications via `mo uninstall` , Mole automatically removes associated LaunchAgent and LaunchDaemon plists:
2025-12-29 19:06:04 +08:00
2026-01-15 11:39:33 +08:00
- Scans `~/Library/LaunchAgents` , `~/Library/LaunchDaemons` , `/Library/LaunchAgents` , `/Library/LaunchDaemons`
- Matches both exact bundle ID (`com.example.app.plist` ) and app name patterns (`*AppName*.plist` )
- Skips all `com.apple.*` system items via `should_protect_path()` validation
- Unloads services via `launchctl` before deletion (via `stop_launch_services()` )
- **Safer than orphan detection:** Only removes plists when the associated app is explicitly being uninstalled
- Prevents accumulation of orphaned startup items that persist after app removal
2026-01-26 20:27:46 +08:00
- **Common word exclusion:** LaunchAgent name searches exclude generic terms (Music, Notes, Photos, etc.) to prevent false positives
- **Bundle ID validation:** `stop_launch_services()` validates reverse-DNS format before find patterns
2025-12-29 19:06:04 +08:00
2026-01-15 11:39:33 +08:00
**Code:** `lib/core/app_protection.sh:find_app_files()` , `lib/uninstall/batch.sh:stop_launch_services()`
2025-12-28 21:30:39 +08:00
### Crash Safety & Atomic Operations
| Operation | Safety Mechanism | Recovery Behavior |
|-----------|------------------|-------------------|
| Network Interface Reset | Atomic execution blocks | Wi-Fi/AirDrop restored to pre-operation state |
| Swap Clearing | Daemon restart | `dynamic_pager` handles recovery safely |
| Volume Scanning | Timeout + filesystem check | Auto-skip unresponsive NFS/SMB/AFP mounts |
2026-01-09 17:13:34 +08:00
| Homebrew Cache | Pre-flight size check | Skip if <50MB (avoids long delays) |
2025-12-28 21:30:39 +08:00
| Network Volume Check | `diskutil info` with timeout | Prevents hangs on slow/dead mounts |
2026-01-09 17:13:34 +08:00
| SQLite Vacuum | App-running check + 20s timeout | Skips if Mail/Safari/Messages active |
2025-12-29 19:06:04 +08:00
| dyld Cache Update | 24-hour freshness check + 180s timeout | Skips if recently updated |
| App Bundle Search | 10s timeout on mdfind | Fallback to standard paths |
2025-12-28 21:30:39 +08:00
**Timeout Example:**
```bash
run_with_timeout 5 diskutil info "$mount_point" || skip_volume
```
**Code:** `lib/core/base.sh:run_with_timeout()` , `lib/optimize/*.sh`
---
## User Controls
### Dry-Run Mode
**Command:** `mo clean --dry-run` | `mo optimize --dry-run`
**Behavior:**
2026-01-09 17:13:34 +08:00
- Simulates the entire operation without modifying a single file.
- Lists every file/directory that **would ** be deleted.
- Calculates total space that **would ** be freed.
- **Zero risk** - no actual deletion commands are executed.
2025-12-28 21:30:39 +08:00
### Custom Whitelists
**File:** `~/.config/mole/whitelist`
**Format:**
```bash
# One path per line - exact matches only
/Users/username/important-cache
~/Library/Application Support/CriticalApp
```
2026-01-09 17:13:34 +08:00
- Paths are **unconditionally protected ** .
- Applies to all operations (clean, optimize, uninstall).
- Supports absolute paths and `~` expansion.
2025-12-28 21:30:39 +08:00
**Code:** `lib/core/file_ops.sh:is_whitelisted()`
### Interactive Confirmations
2026-01-09 17:13:34 +08:00
We mandate confirmation for:
2025-12-28 21:30:39 +08:00
2026-01-09 17:13:34 +08:00
- Uninstalling system-scope applications.
- Removing large data directories (>1GB).
- Deleting items from shared vendor folders.
2025-12-28 21:30:39 +08:00
---
## Testing & Compliance
### Test Coverage
Mole uses **BATS (Bash Automated Testing System) ** for automated testing.
| Test Category | Coverage | Key Tests |
|---------------|----------|-----------|
| Core File Operations | 95% | Path validation, symlink detection, permissions |
| Cleaning Logic | 87% | Orphan detection, 60-day rule, vendor whitelist |
2025-12-29 00:29:42 +08:00
| Optimization | 82% | Cache cleanup, timeouts |
2025-12-28 21:30:39 +08:00
| System Maintenance | 90% | Time Machine, network volumes, crash recovery |
| Security Controls | 100% | Path traversal, command injection, symlinks |
**Total:** 180+ tests | **Overall Coverage: ** ~88%
**Test Execution:**
```bash
bats tests/ # Run all tests
bats tests/security.bats # Run specific suite
```
### Standards Compliance
| Standard | Implementation |
|----------|----------------|
| OWASP Secure Coding | Input validation, least privilege, defense-in-depth |
2026-01-09 17:13:34 +08:00
| CWE-22 (Path Traversal) | Enhanced detection: rejects `/../` components, safely handles `..` in directory names |
2025-12-28 21:30:39 +08:00
| CWE-78 (Command Injection) | Control character filtering |
| CWE-59 (Link Following) | Symlink detection before privileged operations |
| Apple File System Guidelines | Respects SIP, Read-Only Volumes, TCC |
### Security Development Lifecycle
2026-01-09 17:13:34 +08:00
- **Static Analysis:** `shellcheck` runs on all shell scripts.
- **Code Review:** All changes are manually reviewed by maintainers.
- **Dependency Scanning:** Minimal external dependencies, all carefully vetted.
2025-12-28 21:30:39 +08:00
### Known Limitations
| Limitation | Impact | Mitigation |
|------------|--------|------------|
2026-01-09 17:13:34 +08:00
| Requires `sudo` for system caches | Initial friction | Clear documentation explaining why |
| 60-day rule may delay cleanup | Some orphans remain longer | Manual `mo uninstall` is always available |
| No undo functionality | Deleted files are unrecoverable | Dry-run mode and warnings are clear |
| English-only name matching | May miss non-English apps | Fallback to Bundle ID matching |
2025-12-28 21:30:39 +08:00
**Intentionally Out of Scope (Safety):**
2026-01-09 17:13:34 +08:00
- Automatic deletion of user documents/media.
- Encryption key stores or password managers.
- System configuration files (`/etc/*` ).
- Browser history or cookies.
- Git repository cleanup.
2025-12-28 21:30:39 +08:00
---
## Dependencies
### System Binaries
2026-01-09 17:13:34 +08:00
Mole relies on standard, SIP-protected macOS system binaries:
2025-12-28 21:30:39 +08:00
| Binary | Purpose | Fallback |
|--------|---------|----------|
| `plutil` | Validate `.plist` integrity | Skip invalid plists |
| `tmutil` | Time Machine interaction | Skip TM cleanup |
| `dscacheutil` | System cache rebuilding | Optional optimization |
| `diskutil` | Volume information | Skip network volumes |
### Go Dependencies (Interactive Tools)
The compiled Go binary (`analyze-go` ) includes:
| Library | Version | Purpose | License |
|---------|---------|---------|---------|
| `bubbletea` | v0.23+ | TUI framework | MIT |
| `lipgloss` | v0.6+ | Terminal styling | MIT |
| `gopsutil` | v3.22+ | System metrics | BSD-3 |
| `xxhash` | v2.2+ | Fast hashing | BSD-2 |
**Supply Chain Security:**
2026-01-09 17:13:34 +08:00
- All dependencies are pinned to specific versions.
- Regular security audits.
- No transitive dependencies with known CVEs.
- **Automated Releases**: Binaries are compiled and signed via GitHub Actions.
- **Source Only**: The repository contains no pre-compiled binaries.
2025-12-28 21:30:39 +08:00
---
2026-01-09 17:13:34 +08:00
**Our Commitment:** This document certifies that Mole implements industry-standard defensive programming practices and strictly adheres to macOS security guidelines. We prioritize system stability and data integrity above all else.
2025-12-28 21:30:39 +08:00
2026-01-09 17:13:34 +08:00
*For security concerns or vulnerability reports, please open an issue or contact the maintainers directly.*