Skip to content

Commit b3142c9

Browse files
committed
cleanup
1 parent d8feb5e commit b3142c9

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

apps/web/actions/images/remove-image.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function removeImage(
6464

6565
return { success: true } as const;
6666
} catch (error) {
67-
console.error(`Error removing ${type} image:`, error);
67+
console.error(`Error removing %s image:`, type, error);
6868
throw new Error(error instanceof Error ? error.message : "Remove failed");
6969
}
7070
}

apps/web/actions/images/upload-image.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { OrganisationId, UserId } from "@cap/web-domain";
77
import { eq } from "drizzle-orm";
88
import { Effect, Option } from "effect";
99
import { revalidatePath } from "next/cache";
10+
import * as path from "path";
1011
import { runPromise } from "@/lib/server";
1112

1213
export async function uploadImage(
@@ -29,7 +30,15 @@ export async function uploadImage(
2930
oldImageUrlOrKey.startsWith("https://")
3031
) {
3132
const url = new URL(oldImageUrlOrKey);
32-
oldS3Key = url.pathname.substring(1);
33+
const raw = url.pathname.startsWith("/")
34+
? url.pathname.slice(1)
35+
: url.pathname;
36+
const decoded = decodeURIComponent(raw);
37+
const normalized = path.posix.normalize(decoded);
38+
if (normalized.includes("..")) {
39+
throw new Error("Invalid S3 key path");
40+
}
41+
oldS3Key = normalized;
3342
}
3443

3544
// Only delete if it looks like the correct type of image key
@@ -38,7 +47,7 @@ export async function uploadImage(
3847
yield* bucket.deleteObject(oldS3Key);
3948
}
4049
} catch (error) {
41-
console.error(`Error deleting old ${type} image from S3:`, error);
50+
console.error(`Error deleting old %s image from S3:`, type, error);
4251
}
4352
}
4453

@@ -77,7 +86,7 @@ export async function uploadImage(
7786

7887
return { success: true, image: s3Key } as const;
7988
} catch (error) {
80-
console.error(`Error uploading ${type} image:`, error);
89+
console.error(`Error uploading %s image:`, type, error);
8190
throw new Error(error instanceof Error ? error.message : "Upload failed");
8291
}
8392
}

apps/web/app/(org)/dashboard/_components/Navbar/SpaceDialog.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import { faLayerGroup } from "@fortawesome/free-solid-svg-icons";
1818
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
1919
import { zodResolver } from "@hookform/resolvers/zod";
2020
import type React from "react";
21-
import { useEffect, useId, useRef, useState } from "react";
21+
import { useEffect, useRef, useState } from "react";
2222
import { useForm } from "react-hook-form";
2323
import { toast } from "sonner";
2424
import * as z from "zod";
2525
import { updateSpace } from "@/actions/organization/update-space";
2626
import { FileInput } from "@/components/FileInput";
27-
import { SignedImageUrl } from "@/components/SignedImageUrl";
2827
import { useDashboardContext } from "../../Contexts";
2928
import { MemberSelect } from "../../spaces/[spaceId]/components/MemberSelect";
3029
import { createSpace } from "./server";

0 commit comments

Comments
 (0)