From b93d108cc0d27a1b5aa832e9023cf9d5638cbcc6 Mon Sep 17 00:00:00 2001 From: Emilien <4016501+unixfox@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:40:40 +0100 Subject: [PATCH] add more protection to videoplayback proxy + fix #11 --- src/routes/videoPlaybackProxy.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/routes/videoPlaybackProxy.ts b/src/routes/videoPlaybackProxy.ts index ec2422e..78b667f 100644 --- a/src/routes/videoPlaybackProxy.ts +++ b/src/routes/videoPlaybackProxy.ts @@ -6,13 +6,25 @@ import { HTTPException } from "hono/http-exception"; const videoPlaybackProxy = new Hono(); videoPlaybackProxy.get("/", async (c) => { - const { host, c: client } = c.req.query(); + const { host, c: client, expire } = c.req.query(); const rangeHeader = c.req.header("range") as string | undefined; const urlReq = new URL(c.req.url); if (host == undefined || !/[\w-]+.googlevideo.com/.test(host)) { throw new HTTPException(400, { - res: new Response("Host do not match or undefined."), + res: new Response("Host query string do not match or undefined."), + }); + } + + if (expire == undefined || Number(expire) < Number(Date.now().toString().slice(0, -3))){ + throw new HTTPException(400, { + res: new Response("Expire query string undefined or videoplayback URL has expired."), + }); + } + + if (client == undefined) { + throw new HTTPException(400, { + res: new Response("'c' query string undefined."), }); }