From ee9ed6af1fd83d832d946e18ec25843295236736 Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 12 Jun 2024 11:57:59 +0530 Subject: [PATCH] Add server-side ads check for dearrow submissions --- src/routes/postBranding.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 1a6ab025..433819ae 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -36,7 +36,7 @@ interface ExistingVote { } export async function postBranding(req: Request, res: Response) { - const { videoID, userID, title, thumbnail, autoLock, downvote } = req.body as BrandingSubmission; + const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration } = req.body as BrandingSubmission; const service = getService(req.body.service); if (!videoID || !userID || userID.length < 30 || !service @@ -55,6 +55,10 @@ export async function postBranding(req: Request, res: Response) { const hashedIP = await getHashCache(getIP(req) + config.globalSalt as IPAddress); const isBanned = await checkBanStatus(hashedUserID, hashedIP); + if (videoDuration && await checkForWrongVideoDuration(videoID, videoDuration)) { + res.status(403).send("YouTube is currently testing a new anti-adblock technique called server-side ad-injection. This causes skips and submissions to be offset by the duration of the ad. It seems that you are affected by this A/B test, so until a fix is developed, we cannot accept submissions from your device due to them potentially being inaccurate."); + } + const lock = await acquireLock(`postBranding:${videoID}.${hashedUserID}`); if (!lock.status) { res.status(429).send("Vote already in progress"); @@ -325,4 +329,11 @@ async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID) { }); } } +} + +async function checkForWrongVideoDuration(videoID: VideoID, duration: number): Promise { + const apiVideoDetails = await getVideoDetails(videoID, true); + const apiDuration = apiVideoDetails?.duration; + + return apiDuration && apiDuration > 2 && duration && duration > 2 && Math.abs(apiDuration - duration) > 3; } \ No newline at end of file