mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-27 01:48:33 +03:00
create a request validator engine
This commit is contained in:
@@ -18,8 +18,9 @@ import { checkBanStatus } from "../utils/checkBan";
|
||||
import axios from "axios";
|
||||
import { getMaxResThumbnail } from "../utils/youtubeApi";
|
||||
import { getVideoDetails } from "../utils/getVideoDetails";
|
||||
import { canSubmitDeArrow, validSubmittedData } from "../utils/permissions";
|
||||
import { canSubmitDeArrow } from "../utils/permissions";
|
||||
import { parseUserAgent } from "../utils/userAgent";
|
||||
import { isRequestInvalid } from "../utils/requestValidator";
|
||||
|
||||
enum BrandingType {
|
||||
Title,
|
||||
@@ -58,8 +59,19 @@ 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 (!validSubmittedData(userAgent, req.headers["user-agent"])) {
|
||||
Logger.warn(`Rejecting submission based on invalid data: ${hashedUserID} ${videoID} ${videoDuration} ${userAgent} ${req.headers["user-agent"]}`);
|
||||
if (isRequestInvalid({
|
||||
userAgent,
|
||||
userAgentHeader: req.headers["user-agent"],
|
||||
videoDuration,
|
||||
userID,
|
||||
service,
|
||||
dearrow: {
|
||||
title,
|
||||
thumbnail,
|
||||
downvote,
|
||||
}
|
||||
})) {
|
||||
Logger.warn(`Rejecting submission based on invalid data: ${hashedUserID} ${videoID} ${videoDuration} ${userAgent} ${req.headers["user-agent"]} ${title.title} ${thumbnail.timestamp}`);
|
||||
res.status(200).send("OK");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,12 @@ import { parseUserAgent } from "../utils/userAgent";
|
||||
import { getService } from "../utils/getService";
|
||||
import axios from "axios";
|
||||
import { vote } from "./voteOnSponsorTime";
|
||||
import { canSubmit, canSubmitGlobal, validSubmittedData } from "../utils/permissions";
|
||||
import { canSubmit, canSubmitGlobal } from "../utils/permissions";
|
||||
import { getVideoDetails, videoDetails } from "../utils/getVideoDetails";
|
||||
import * as youtubeID from "../utils/youtubeID";
|
||||
import { acquireLock } from "../utils/redisLock";
|
||||
import { checkBanStatus } from "../utils/checkBan";
|
||||
import { isRequestInvalid } from "../utils/requestValidator";
|
||||
|
||||
type CheckResult = {
|
||||
pass: boolean,
|
||||
@@ -509,7 +510,14 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
}
|
||||
const userID: HashedUserID = await getHashCache(paramUserID);
|
||||
|
||||
if (!validSubmittedData(userAgent, req.headers["user-agent"])) {
|
||||
if (isRequestInvalid({
|
||||
userAgent,
|
||||
userAgentHeader: req.headers["user-agent"],
|
||||
videoDuration,
|
||||
userID: paramUserID,
|
||||
service,
|
||||
segments,
|
||||
})) {
|
||||
Logger.warn(`Rejecting submission based on invalid data: ${userID} ${videoID} ${videoDurationParam} ${userAgent} ${req.headers["user-agent"]}`);
|
||||
return res.status(200).send("OK");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user