Skip to content

Commit

Permalink
Add server-side ads check for dearrow submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jun 12, 2024
1 parent ec1e6d6 commit ee9ed6a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/routes/postBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 39 in src/routes/postBranding.ts

View workflow job for this annotation

GitHub Actions / Lint with ESLint and build

Property 'videoDuration' does not exist on type 'BrandingSubmission'.
const service = getService(req.body.service);

if (!videoID || !userID || userID.length < 30 || !service
Expand All @@ -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");
Expand Down Expand Up @@ -325,4 +329,11 @@ async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID) {
});
}
}
}

async function checkForWrongVideoDuration(videoID: VideoID, duration: number): Promise<boolean> {
const apiVideoDetails = await getVideoDetails(videoID, true);
const apiDuration = apiVideoDetails?.duration;

return apiDuration && apiDuration > 2 && duration && duration > 2 && Math.abs(apiDuration - duration) > 3;
}

0 comments on commit ee9ed6a

Please sign in to comment.