Ignore requests from bot for headless router (#23733)
This commit is contained in:
@@ -93,6 +93,7 @@
|
||||
"handlebars": "^4.7.7",
|
||||
"ical.js": "^1.4.0",
|
||||
"ics": "^2.37.0",
|
||||
"isbot": "^5.1.30",
|
||||
"jose": "^4.13.1",
|
||||
"jotai": "^2.12.2",
|
||||
"jsdom": "^22.0.0",
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
import { wrapGetServerSidePropsWithSentry } from "@sentry/nextjs";
|
||||
import { isbot } from "isbot";
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
|
||||
import { getRoutedUrl, hasEmbedPath } from "@calcom/features/routing-forms/lib/getRoutedUrl";
|
||||
import logger from "@calcom/lib/logger";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["router/getServerSideProps"] });
|
||||
|
||||
// Show a positive message to the bots so that they don't think that the form is broken.
|
||||
const BOT_MESSAGE = "Thank you for your interest! We will be in touch soon.";
|
||||
|
||||
export const getServerSideProps = wrapGetServerSidePropsWithSentry(async function getServerSideProps(
|
||||
context: GetServerSidePropsContext
|
||||
) {
|
||||
try {
|
||||
// Check if the request is from a bot
|
||||
const userAgent = context.req.headers["user-agent"];
|
||||
if (userAgent && isbot(userAgent)) {
|
||||
log.info(`[BOT] Ignoring request from user agent: ${userAgent}`);
|
||||
return {
|
||||
props: {
|
||||
isEmbed: hasEmbedPath(context.req.url || ""),
|
||||
form: null,
|
||||
message: BOT_MESSAGE,
|
||||
errorMessage: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return await getRoutedUrl(context);
|
||||
} catch (error) {
|
||||
if (error instanceof TRPCError && error.code === "TOO_MANY_REQUESTS") {
|
||||
|
||||
@@ -4307,6 +4307,7 @@ __metadata:
|
||||
handlebars: ^4.7.7
|
||||
ical.js: ^1.4.0
|
||||
ics: ^2.37.0
|
||||
isbot: ^5.1.30
|
||||
jose: ^4.13.1
|
||||
jotai: ^2.12.2
|
||||
jsdom: ^22.0.0
|
||||
@@ -31899,6 +31900,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"isbot@npm:^5.1.30":
|
||||
version: 5.1.30
|
||||
resolution: "isbot@npm:5.1.30"
|
||||
checksum: 296e6c13767d0d0cff22f778aa8e06fddf59eb347ed0c237647f9a65fd0681fd420468cc9e145f4c9fe7b9d17784816f4991d0299b1f3d489822c0d5c773d264
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"isbuffer@npm:~0.0.0":
|
||||
version: 0.0.0
|
||||
resolution: "isbuffer@npm:0.0.0"
|
||||
|
||||
Reference in New Issue
Block a user