Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: allow public resume pictures on custom domains

Amruth Pillai95823a651623
diff --git a/apps/server/src/static/uploads-s3.test.ts b/apps/server/src/static/uploads-s3.test.ts
index f11ac23c3..166a2305d 100644
--- a/apps/server/src/static/uploads-s3.test.ts
+++ b/apps/server/src/static/uploads-s3.test.ts
@@ -99,6 +99,22 @@ it("stores images without ACLs and serves them through the signed application pr
expect(requests.at(-1)?.headers.authorization).toMatch(/^AWS4-HMAC-SHA256 /);
});
+it("allows custom-domain pages to embed public pictures, including after cache revalidation", async () => {
+ const key = "uploads/user-1/pictures/photo.png";
+ await storage.write({ key, data: new Uint8Array([137, 80, 78, 71]), contentType: "image/png" });
+ const headers = { Referer: "https://custom.example.cv/", "Sec-Fetch-Site": "cross-site" };
+ const response = await handleUpload(new Request(`${envMock.APP_URL}/api/${key}`, { headers }));
+ expect(response.status).toBe(200);
+ expect(response.headers.get("Cross-Origin-Resource-Policy")).toBe("cross-origin");
+ const cached = await handleUpload(
+ new Request(`${envMock.APP_URL}/api/${key}`, {
+ headers: { ...headers, "If-None-Match": response.headers.get("ETag") ?? "" },
+ }),
+ );
+ expect(cached.status).toBe(304);
+ expect(cached.headers.get("Cross-Origin-Resource-Policy")).toBe("cross-origin");
+});
+
it("stops serving a banned owner's public pictures", async () => {
const key = "uploads/user-1/pictures/photo.png";
await storage.write({ key, data: new Uint8Array([137, 80, 78, 71]), contentType: "image/png" });
@@ -124,13 +140,14 @@ it("stores private attachments without ACLs while keeping them outside the publi
});
it.each(["text/html", "image/svg+xml"])("downloads stored %s uploads instead of rendering them", async (type) => {
- const key = "uploads/user-1/pictures/upload.bin";
+ const key = "uploads/user-1/pictures/upload.png";
await storage.write({ key, data: new TextEncoder().encode("<script>alert(1)</script>"), contentType: type });
resolveAuthentication.mockResolvedValue({ user: { id: "user-1" }, permissions: ["read"] });
const response = await handleUpload(new Request(`${envMock.APP_URL}/api/${key}`));
expect(response.status).toBe(200);
expect(response.headers.get("Content-Type")).toBe("application/octet-stream");
- expect(response.headers.get("Content-Disposition")).toBe('attachment; filename="upload.bin"');
+ expect(response.headers.get("Content-Disposition")).toBe('attachment; filename="upload.png"');
+ expect(response.headers.get("Cross-Origin-Resource-Policy")).toBe("same-site");
});
it("requires the upload owner before serving application PDFs, including conditional requests", async () => {
@@ -158,4 +175,5 @@ it("requires the upload owner before serving application PDFs, including conditi
expect(response.status).toBe(200);
expect(await response.text()).toBe("private application PDF");
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
+ expect(response.headers.get("Cross-Origin-Resource-Policy")).toBe("same-site");
});
diff --git a/apps/server/src/static/uploads.ts b/apps/server/src/static/uploads.ts
index f2d63b866..e384d8633 100644
--- a/apps/server/src/static/uploads.ts
+++ b/apps/server/src/static/uploads.ts
@@ -45,7 +45,14 @@ export async function handleUpload(request: Request) {
const etag = createEtag(storedFile);
if (isPublicPicture && matchesIfNoneMatch(request.headers.get("If-None-Match"), etag))
- return new Response(null, { status: 304, headers: { ETag: etag, "Cache-Control": PUBLIC_PICTURE_CACHE_CONTROL } });
+ return new Response(null, {
+ status: 304,
+ headers: {
+ ETag: etag,
+ "Cache-Control": PUBLIC_PICTURE_CACHE_CONTROL,
+ "Cross-Origin-Resource-Policy": "cross-origin",
+ },
+ });
const shouldForceDownload = !INLINE_CONTENT_TYPES.has(contentType);
@@ -61,7 +68,8 @@ export async function handleUpload(request: Request) {
headers.set("ETag", etag);
headers.set("X-Content-Type-Options", "nosniff");
headers.set("X-Robots-Tag", "noindex, nofollow");
- headers.set("Cross-Origin-Resource-Policy", "same-site");
+ // Public pictures load from the app origin even on custom-domain resume pages.
+ headers.set("Cross-Origin-Resource-Policy", isPublicPicture ? "cross-origin" : "same-site");
headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
headers.set("X-Frame-Options", "DENY");
headers.set("X-Download-Options", "noopen");