Skip to content

Full Toolkit for Next-Level Domain Analysis

Filter requests to map page from bots 🛡️

Felix Wotschofskya15c29c0245c
diff --git a/app/lookup/[domain]/map/page.tsx b/app/lookup/[domain]/map/page.tsx
index c341188..8268f79 100644
--- a/app/lookup/[domain]/map/page.tsx
+++ b/app/lookup/[domain]/map/page.tsx
@@ -1,5 +1,10 @@
+import { isbot } from 'isbot';
+import { ShieldAlertIcon } from 'lucide-react';
+import { headers } from 'next/headers';
import type { FC } from 'react';
+import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
+
import ResultsGlobe from '@/components/ResultsGlobe';
import { REGIONS } from '@/lib/data';
import InternalDoHResolver from '@/lib/resolvers/InternalDoHResolver';
@@ -15,6 +20,25 @@ type MapResultsPageProps = {
const MapResultsPage: FC<MapResultsPageProps> = async ({
params: { domain },
}) => {
+ const userAgent = headers().get('user-agent');
+ const shouldBlockRequest = !userAgent || isbot(userAgent);
+
+ if (shouldBlockRequest) {
+ console.log('Bot detected, blocking request, UA:', userAgent);
+ return (
+ <Alert className="mx-auto mt-24 w-max">
+ <ShieldAlertIcon className="h-4 w-4" />
+ <AlertTitle>Bot or crawler detected!</AlertTitle>
+ <AlertDescription>
+ To protect our infrastructure, this page is not available for bots or
+ crawlers.
+ <br />
+ But don&apos;t be sad, there&apos;s to crawl here anyway.
+ </AlertDescription>
+ </Alert>
+ );
+ }
+
const markers = await Promise.all(
Object.entries(REGIONS).map(async ([code, data]) => {
const resolver = new InternalDoHResolver(code, 'cloudflare');
diff --git a/components/ui/alert.tsx b/components/ui/alert.tsx
new file mode 100644
index 0000000..d2b59cc
--- /dev/null
+++ b/components/ui/alert.tsx
@@ -0,0 +1,59 @@
+import * as React from 'react';
+import { cva, type VariantProps } from 'class-variance-authority';
+
+import { cn } from '@/lib/utils';
+
+const alertVariants = cva(
+ 'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground',
+ {
+ variants: {
+ variant: {
+ default: 'bg-background text-foreground',
+ destructive:
+ 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive',
+ },
+ },
+ defaultVariants: {
+ variant: 'default',
+ },
+ }
+);
+
+const Alert = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
+>(({ className, variant, ...props }, ref) => (
+ <div
+ ref={ref}
+ role="alert"
+ className={cn(alertVariants({ variant }), className)}
+ {...props}
+ />
+));
+Alert.displayName = 'Alert';
+
+const AlertTitle = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLHeadingElement>
+>(({ className, ...props }, ref) => (
+ <h5
+ ref={ref}
+ className={cn('mb-1 font-medium leading-none tracking-tight', className)}
+ {...props}
+ />
+));
+AlertTitle.displayName = 'AlertTitle';
+
+const AlertDescription = React.forwardRef<
+ HTMLParagraphElement,
+ React.HTMLAttributes<HTMLParagraphElement>
+>(({ className, ...props }, ref) => (
+ <div
+ ref={ref}
+ className={cn('text-sm [&_p]:leading-relaxed', className)}
+ {...props}
+ />
+));
+AlertDescription.displayName = 'AlertDescription';
+
+export { Alert, AlertTitle, AlertDescription };
diff --git a/package.json b/package.json
index 13c7dc7..4590a2f 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
"dataloader": "^2.2.2",
"dns-packet": "^5.6.1",
"hyperscript": "^2.0.2",
+ "isbot": "^4.4.0",
"leaflet": "^1.9.4",
"leaflet-defaulticon-compatibility": "^0.1.2",
"lucide-react": "^0.294.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f75c87f..186cf95 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -59,6 +59,9 @@ dependencies:
hyperscript:
specifier: ^2.0.2
version: 2.0.2
+ isbot:
+ specifier: ^4.4.0
+ version: 4.4.0
leaflet:
specifier: ^1.9.4
version: 1.9.4
@@ -4396,6 +4399,11 @@ packages:
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
dev: true
+ resolution: {integrity: sha512-8ZvOWUA68kyJO4hHJdWjyreq7TYNWTS9y15IzeqVdKxR9pPr3P/3r9AHcoIv9M0Rllkao5qWz2v1lmcyKIVCzQ==}
+ engines: {node: '>=18'}
+ dev: false
+
resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
dev: true