Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): harden clip deletion path, thumbnail stride, and cache key

Richie McIlroye487f86a3f3c
diff --git a/apps/desktop/src-tauri/src/clip_thumbnails.rs b/apps/desktop/src-tauri/src/clip_thumbnails.rs
index d92adb4ec..bc898f7fc 100644
--- a/apps/desktop/src-tauri/src/clip_thumbnails.rs
+++ b/apps/desktop/src-tauri/src/clip_thumbnails.rs
@@ -178,6 +178,11 @@ fn decode_clip_thumbnail(input: &Path, time: f64, output: &Path) -> Result<(), S
let height = rgb_frame.height() as usize;
let src_stride = rgb_frame.stride(0);
let dst_stride = width * 3;
+ if src_stride < dst_stride {
+ return Err(format!(
+ "Unexpected RGB stride: src_stride={src_stride}, expected >= {dst_stride}"
+ ));
+ }
let mut img_buffer = vec![0u8; height * dst_stride];
for y in 0..height {
let src_slice = &rgb_frame.data(0)[y * src_stride..y * src_stride + dst_stride];
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index d127affb2..f6158a1be 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -3540,12 +3540,37 @@ fn list_recordings(app: AppHandle) -> Result<Vec<(PathBuf, RecordingMetaWithMeta
#[instrument(skip(app))]
async fn delete_recording_directory(app: AppHandle, path: PathBuf) -> Result<(), String> {
let recordings_dir = recordings_path(&app);
+
+ // Reject `..` components up front: `Path::starts_with` compares raw components
+ // and does not normalize them, so a path like `<recordings_dir>/../../etc` would
+ // otherwise pass the prefix check below.
+ if path
+ .components()
+ .any(|component| matches!(component, std::path::Component::ParentDir))
+ {
+ return Err("Invalid path".to_string());
+ }
+
if !path.starts_with(&recordings_dir) {
return Err("Path is not inside the recordings directory".to_string());
}
if path.exists() {
- std::fs::remove_dir_all(&path).map_err(|e| format!("Failed to delete recording: {e}"))?;
+ // Canonicalize both paths so symlinks can't be used to escape the
+ // recordings directory before we recursively delete.
+ let recordings_dir = recordings_dir
+ .canonicalize()
+ .map_err(|e| format!("Failed to resolve recordings directory: {e}"))?;
+ let canonical_path = path
+ .canonicalize()
+ .map_err(|e| format!("Failed to resolve recording path: {e}"))?;
+
+ if !canonical_path.starts_with(&recordings_dir) {
+ return Err("Path is not inside the recordings directory".to_string());
+ }
+
+ std::fs::remove_dir_all(&canonical_path)
+ .map_err(|e| format!("Failed to delete recording: {e}"))?;
}
let _ = RecordingDeleted { path }.emit(&app);
diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rs
index f1f4ddb5b..cd4afc704 100644
--- a/apps/desktop/src-tauri/src/recording.rs
+++ b/apps/desktop/src-tauri/src/recording.rs
@@ -2890,6 +2890,14 @@ async fn handle_recording_end(
app.selected_camera_id = None;
}
+ // Fallback for in-editor recordings that did NOT reach
+ // `apply_post_studio_editor_behaviour` (failed/cancelled recordings, or
+ // non-studio modes). On the studio success path `handle_recording_finish`
+ // — awaited above into `res` — already consumed the target and emitted
+ // `EditorRecordingAdded`, so this `take()` returns `None` and is a no-op.
+ // Using `take()` (not `current()`) here is deliberate: it restores the
+ // editor window AND clears any stale target so it can't leak into the next
+ // recording session.
if let Some(editor_path) = EditorRecordingTarget::take(&handle)
&& let Some(editor_window) = editor_window_for_path(&handle, &editor_path)
{
diff --git a/apps/desktop/src/routes/editor/ClipsSidebar.tsx b/apps/desktop/src/routes/editor/ClipsSidebar.tsx
index 277ef16b1..bd77e6bfd 100644
--- a/apps/desktop/src/routes/editor/ClipsSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ClipsSidebar.tsx
@@ -84,8 +84,11 @@ let thumbnailPumpScheduled = false;
const MAX_THUMBNAIL_LOADS = 2;
-const clipThumbnailKey = (recordingSegment: number, start: number) =>
- `${recordingSegment}-${Math.round(start * 1000)}`;
+const clipThumbnailKey = (
+ projectPath: string,
+ recordingSegment: number,
+ start: number,
+) => `${projectPath}::${recordingSegment}-${Math.round(start * 1000)}`;
const scheduleThumbnailWork = (callback: () => void) => {
const requestIdle = (
@@ -158,6 +161,7 @@ const loadClipThumbnail = (
};
function ClipThumbnail(props: {
+ projectPath: string;
recordingSegment: number;
start: number;
index: number;
@@ -169,7 +173,7 @@ function ClipThumbnail(props: {
let disposed = false;
const cacheKey = createMemo(() =>
- clipThumbnailKey(props.recordingSegment, props.start),
+ clipThumbnailKey(props.projectPath, props.recordingSegment, props.start),
);
const applySrc = (key: string, url: string | null) => {
@@ -789,6 +793,7 @@ function ClipsSidebarInner(props: { open: boolean; class?: string }) {
>
<div class="overflow-hidden relative w-24 rounded-md aspect-video shrink-0 bg-gray-4">
<ClipThumbnail
+ projectPath={editorInstance.path}
recordingSegment={segment.recordingSegment ?? 0}
start={segment.start}
index={index()}