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-09 17:13:34 +08:00
**Status:** PASSED | **Risk Level: ** LOW | **Version: ** 1.19.0 (2026-01-09)
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-09 17:13:34 +08:00
| Audit Date | January 9, 2026 |
2025-12-28 21:30:39 +08:00
| Audit Conclusion | **PASSED ** |
2026-01-05 15:30:23 +08:00
| Mole Version | V1.19.0 |
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 |
| Next Review | June 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.
- 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
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-09 17:13:34 +08:00
**Exception:** `/System/Library/Caches/com.apple.coresymbolicationd/data` (safe, rebuildable cache).
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()`
#### 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.
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()` |
| Time Machine | Local snapshots, backups | Checks `backupd` process, aborts if active |
| 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 |
**Orphaned Helper Cleanup (`opt_startup_items_cleanup` ):**
Removes LaunchAgents/Daemons whose associated app has been uninstalled:
2026-01-09 17:13:34 +08:00
- Checks `AssociatedBundleIdentifiers` to detect orphans.
- Skips all `com.apple.*` system items.
- Skips paths under `/System/*` , `/usr/bin/*` , `/usr/lib/*` , `/usr/sbin/*` , `/Library/Apple/*` .
- Uses `safe_remove` / `safe_sudo_remove` with path validation.
- Unloads service via `launchctl` before deletion.
- **Timeout Protection:** 10-second limit on `mdfind` operations.
2025-12-29 19:06:04 +08:00
**Code:** `lib/optimize/tasks.sh:opt_startup_items_cleanup()`
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.*