From 5201a44333e32da9833320b792e262e8caeb7187 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Tue, 24 Nov 2026 01:37:19 +0100 Subject: [PATCH] Answer 404 for unknown pastes and add robots.txt An unknown paste ID rendered the not-found panel with status 200. That made /robots.txt a paste page titled "Paste robots.txt", and every mistyped link looked like a real page to a crawler. The route now calls notFound(), and app/not-found.tsx shows the same panel with a 404. robots.txt allows the site and blocks /api/, /raw/ and /dl/, which serve the same content as the paste page. --- app/[id]/page.tsx | 12 +++++------- app/robots.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 app/robots.ts diff --git a/app/[id]/page.tsx b/app/[id]/page.tsx index 01efc52..c18d115 100644 --- a/app/[id]/page.tsx +++ b/app/[id]/page.tsx @@ -1,4 +1,5 @@ import { headers } from 'next/headers' +import { notFound } from 'next/navigation' import { SiteFrame } from '@/components/site/SiteFrame' import { PasteView } from '@/components/PasteView' import { PasswordPrompt } from '@/components/PasswordPrompt' @@ -25,14 +26,11 @@ interface PageProps { export default async function PastePage({ params }: PageProps) { const { id } = await params + // An unknown ID answers 404 through app/not-found.tsx, which shows the same + // panel. Rendering the panel here answered 200, so /robots.txt and every + // mistyped link looked like a real page ("Paste robots.txt") to a crawler. const row = await getPasteRow(id) - if (!row) { - return ( - - - - ) - } + if (!row) notFound() if (isPasteExpired(row)) { return ( diff --git a/app/robots.ts b/app/robots.ts new file mode 100644 index 0000000..a5e3980 --- /dev/null +++ b/app/robots.ts @@ -0,0 +1,12 @@ +import type { MetadataRoute } from 'next' + +/** + * robots.txt. Without this file `/robots.txt` fell through to the `[id]` + * route and came back as a paste page. Raw text and downloads are the same + * content as the paste page in another form, and the API is not for crawlers. + */ +export default function robots(): MetadataRoute.Robots { + return { + rules: [{ userAgent: '*', allow: '/', disallow: ['/api/', '/raw/', '/dl/'] }], + } +}