mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-24 00:18:23 +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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user