Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Validate worker file IDs

Manav Rathib44ee6870af0
diff --git a/infra/workers/cast-albums/src/index.ts b/infra/workers/cast-albums/src/index.ts
index 55c3ab7ed8..8aa44ea1d5 100644
--- a/infra/workers/cast-albums/src/index.ts
+++ b/infra/workers/cast-albums/src/index.ts
@@ -50,7 +50,8 @@ const handleGET = async (request: Request) => {
const url = new URL(request.url);
const fileID = url.searchParams.get("fileID");
- if (!fileID) return new Response(null, { status: 400 });
+ if (!fileID || !/^\d+$/.test(fileID))
+ return new Response(null, { status: 400 });
const filePath = url.pathname.startsWith("/download")
? "download"
diff --git a/infra/workers/files/src/index.ts b/infra/workers/files/src/index.ts
index 0946cb9d6d..45286f5034 100644
--- a/infra/workers/files/src/index.ts
+++ b/infra/workers/files/src/index.ts
@@ -53,9 +53,10 @@ const handleGET = async (request: Request) => {
const url = new URL(request.url);
// Random bots keep trying to pentest causing noise in the logs. If the
- // request doesn't have a fileID, we can just safely ignore it thereafter.
+ // request doesn't have a valid fileID, we can safely ignore it thereafter.
const fileID = url.searchParams.get("fileID");
- if (!fileID) return new Response(null, { status: 400 });
+ if (!fileID || !/^\d+$/.test(fileID))
+ return new Response(null, { status: 400 });
const museumURL = `https://api.ente.com/files/download/v3/${fileID}`;
const museumRequest = new Request(museumURL, request);
diff --git a/infra/workers/public-albums/src/index.ts b/infra/workers/public-albums/src/index.ts
index eb267fb3d2..1ce8b921ef 100644
--- a/infra/workers/public-albums/src/index.ts
+++ b/infra/workers/public-albums/src/index.ts
@@ -29,7 +29,8 @@ const handleGET = async (request: Request) => {
const url = new URL(request.url);
const fileID = url.searchParams.get("fileID");
- if (!fileID) return new Response(null, { status: 400 });
+ if (!fileID || !/^\d+$/.test(fileID))
+ return new Response(null, { status: 400 });
const filePath = url.pathname.startsWith("/download")
? "download"
diff --git a/infra/workers/thumbnails/src/index.ts b/infra/workers/thumbnails/src/index.ts
index 09b3915d4d..aad7c5e123 100644
--- a/infra/workers/thumbnails/src/index.ts
+++ b/infra/workers/thumbnails/src/index.ts
@@ -53,7 +53,8 @@ const handleGET = async (request: Request) => {
const url = new URL(request.url);
const fileID = url.searchParams.get("fileID");
- if (!fileID) return new Response(null, { status: 400 });
+ if (!fileID || !/^\d+$/.test(fileID))
+ return new Response(null, { status: 400 });
const museumURL = `https://api.ente.com/files/thumbnail/v3/${fileID}`;
const museumRequest = new Request(museumURL, request);