Skip to content

Commit bb2dcc5

Browse files
Ignore requests from bot for headless router (calcom#23733)
1 parent 8f82e78 commit bb2dcc5

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"handlebars": "^4.7.7",
9494
"ical.js": "^1.4.0",
9595
"ics": "^2.37.0",
96+
"isbot": "^5.1.30",
9697
"jose": "^4.13.1",
9798
"jotai": "^2.12.2",
9899
"jsdom": "^22.0.0",

apps/web/server/lib/router/getServerSideProps.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
import { wrapGetServerSidePropsWithSentry } from "@sentry/nextjs";
2+
import { isbot } from "isbot";
23
import type { GetServerSidePropsContext } from "next";
34

45
import { getRoutedUrl, hasEmbedPath } from "@calcom/features/routing-forms/lib/getRoutedUrl";
6+
import logger from "@calcom/lib/logger";
57

68
import { TRPCError } from "@trpc/server";
79

10+
const log = logger.getSubLogger({ prefix: ["router/getServerSideProps"] });
11+
12+
// Show a positive message to the bots so that they don't think that the form is broken.
13+
const BOT_MESSAGE = "Thank you for your interest! We will be in touch soon.";
14+
815
export const getServerSideProps = wrapGetServerSidePropsWithSentry(async function getServerSideProps(
916
context: GetServerSidePropsContext
1017
) {
1118
try {
19+
// Check if the request is from a bot
20+
const userAgent = context.req.headers["user-agent"];
21+
if (userAgent && isbot(userAgent)) {
22+
log.info(`[BOT] Ignoring request from user agent: ${userAgent}`);
23+
return {
24+
props: {
25+
isEmbed: hasEmbedPath(context.req.url || ""),
26+
form: null,
27+
message: BOT_MESSAGE,
28+
errorMessage: null,
29+
},
30+
};
31+
}
32+
1233
return await getRoutedUrl(context);
1334
} catch (error) {
1435
if (error instanceof TRPCError && error.code === "TOO_MANY_REQUESTS") {

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,6 +4307,7 @@ __metadata:
43074307
handlebars: ^4.7.7
43084308
ical.js: ^1.4.0
43094309
ics: ^2.37.0
4310+
isbot: ^5.1.30
43104311
jose: ^4.13.1
43114312
jotai: ^2.12.2
43124313
jsdom: ^22.0.0
@@ -31899,6 +31900,13 @@ __metadata:
3189931900
languageName: node
3190031901
linkType: hard
3190131902

31903+
"isbot@npm:^5.1.30":
31904+
version: 5.1.30
31905+
resolution: "isbot@npm:5.1.30"
31906+
checksum: 296e6c13767d0d0cff22f778aa8e06fddf59eb347ed0c237647f9a65fd0681fd420468cc9e145f4c9fe7b9d17784816f4991d0299b1f3d489822c0d5c773d264
31907+
languageName: node
31908+
linkType: hard
31909+
3190231910
"isbuffer@npm:~0.0.0":
3190331911
version: 0.0.0
3190431912
resolution: "isbuffer@npm:0.0.0"

0 commit comments

Comments
 (0)