Conversation
clears app data (cache, preferences, databases) without uninstalling. android: adb shell pm clear. ios simulator: simctl get_app_container + filesystem delete. real ios: not supported.
WalkthroughThis pull request adds support for clearing installed app data across the codebase. The changes include a new CLI command 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@devices/simulator.go`:
- Around line 839-855: The code unconditionally deletes everything under
containerPath (from get_app_container output) which is dangerous; before calling
os.RemoveAll in the loop, resolve and sanitize the path (use filepath.Abs and
filepath.Clean on containerPath and each joined path) and verify it is strictly
inside the expected simulator app-data root (e.g., compare that containerPath
has the expected container root prefix with a trailing separator or use
filepath.Rel to ensure the relative path does not start with ".."), also reject
obvious unsafe values (empty string or root "/"); only after these checks
proceed with s.TerminateApp and the RemoveAll calls (references: containerPath,
s.TerminateApp, filepath.Join, os.RemoveAll).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0c82d11c-1377-4228-9089-c8f0d93b2df3
📒 Files selected for processing (10)
README.mdcli/apps.gocommands/apps.godevices/android.godevices/common.godevices/ios.godevices/remote.godevices/simulator.goserver/dispatch.goserver/server.go
| containerPath := strings.TrimSpace(string(output)) | ||
| if containerPath == "" { | ||
| return fmt.Errorf("no data container found for %s", bundleID) | ||
| } | ||
|
|
||
| _ = s.TerminateApp(bundleID) | ||
|
|
||
| entries, err := os.ReadDir(containerPath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read data container: %w", err) | ||
| } | ||
|
|
||
| for _, entry := range entries { | ||
| if err := os.RemoveAll(filepath.Join(containerPath, entry.Name())); err != nil { | ||
| return fmt.Errorf("failed to remove %s: %w", entry.Name(), err) | ||
| } | ||
| } |
There was a problem hiding this comment.
Validate container path before recursive deletion.
Lines 839-855 perform recursive deletion based on get_app_container output without constraining the target path. Add a strict prefix/sanity check before os.RemoveAll to prevent accidental deletion outside the simulator app-data container.
🛡️ Suggested hardening patch
func (s SimulatorDevice) ClearApp(bundleID string) error {
output, err := runSimctl("get_app_container", s.UDID, bundleID, "data")
if err != nil {
return fmt.Errorf("failed to get data container for %s: %w", bundleID, err)
}
- containerPath := strings.TrimSpace(string(output))
+ containerPath := filepath.Clean(strings.TrimSpace(string(output)))
if containerPath == "" {
return fmt.Errorf("no data container found for %s", bundleID)
}
+ expectedRoot := filepath.Join(
+ os.Getenv("HOME"),
+ "Library", "Developer", "CoreSimulator", "Devices", s.UDID, "data", "Containers", "Data", "Application",
+ )
+ if containerPath == "." || containerPath == "/" ||
+ !strings.HasPrefix(containerPath+string(os.PathSeparator), expectedRoot+string(os.PathSeparator)) {
+ return fmt.Errorf("refusing to clear unexpected container path: %s", containerPath)
+ }
_ = s.TerminateApp(bundleID)
entries, err := os.ReadDir(containerPath)
if err != nil {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| containerPath := strings.TrimSpace(string(output)) | |
| if containerPath == "" { | |
| return fmt.Errorf("no data container found for %s", bundleID) | |
| } | |
| _ = s.TerminateApp(bundleID) | |
| entries, err := os.ReadDir(containerPath) | |
| if err != nil { | |
| return fmt.Errorf("failed to read data container: %w", err) | |
| } | |
| for _, entry := range entries { | |
| if err := os.RemoveAll(filepath.Join(containerPath, entry.Name())); err != nil { | |
| return fmt.Errorf("failed to remove %s: %w", entry.Name(), err) | |
| } | |
| } | |
| containerPath := filepath.Clean(strings.TrimSpace(string(output))) | |
| if containerPath == "" { | |
| return fmt.Errorf("no data container found for %s", bundleID) | |
| } | |
| expectedRoot := filepath.Join( | |
| os.Getenv("HOME"), | |
| "Library", "Developer", "CoreSimulator", "Devices", s.UDID, "data", "Containers", "Data", "Application", | |
| ) | |
| if containerPath == "." || containerPath == "/" || | |
| !strings.HasPrefix(containerPath+string(os.PathSeparator), expectedRoot+string(os.PathSeparator)) { | |
| return fmt.Errorf("refusing to clear unexpected container path: %s", containerPath) | |
| } | |
| _ = s.TerminateApp(bundleID) | |
| entries, err := os.ReadDir(containerPath) | |
| if err != nil { | |
| return fmt.Errorf("failed to read data container: %w", err) | |
| } | |
| for _, entry := range entries { | |
| if err := os.RemoveAll(filepath.Join(containerPath, entry.Name())); err != nil { | |
| return fmt.Errorf("failed to remove %s: %w", entry.Name(), err) | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@devices/simulator.go` around lines 839 - 855, The code unconditionally
deletes everything under containerPath (from get_app_container output) which is
dangerous; before calling os.RemoveAll in the loop, resolve and sanitize the
path (use filepath.Abs and filepath.Clean on containerPath and each joined path)
and verify it is strictly inside the expected simulator app-data root (e.g.,
compare that containerPath has the expected container root prefix with a
trailing separator or use filepath.Rel to ensure the relative path does not
start with ".."), also reject obvious unsafe values (empty string or root "/");
only after these checks proceed with s.TerminateApp and the RemoveAll calls
(references: containerPath, s.TerminateApp, filepath.Join, os.RemoveAll).
clears app data (cache, preferences, databases) without uninstalling.
android: adb shell pm clear.
ios simulator: simctl get_app_container + filesystem delete.
real ios: not supported.