Skip to content

Commit fdcc8da

Browse files
committed
fix(landing): harden production robots domain check
Parse the configured landing URL and compare the hostname exactly. This prevents ragmir.com-prefixed arbitrary hosts from receiving production robots rules.
1 parent edc7e08 commit fdcc8da

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/ragmir-landing/src/pages/robots.txt.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { APIRoute } from "astro"
22

33
const PRODUCTION_DOMAIN = "https://ragmir.com"
4+
const PRODUCTION_HOSTNAME = new URL(PRODUCTION_DOMAIN).hostname
45

5-
const isProduction = (import.meta.env.PUBLIC_RAGMIR_LANDING_URL ?? PRODUCTION_DOMAIN).startsWith(
6-
PRODUCTION_DOMAIN,
7-
)
6+
const isProduction =
7+
siteHostname(import.meta.env.PUBLIC_RAGMIR_LANDING_URL ?? PRODUCTION_DOMAIN) ===
8+
PRODUCTION_HOSTNAME
89

910
const productionRobots = `User-agent: *
1011
Content-Signal: search=yes, ai-input=yes, ai-train=no
@@ -22,3 +23,11 @@ export const GET: APIRoute = () => {
2223
headers: { "Content-Type": "text/plain; charset=utf-8" },
2324
})
2425
}
26+
27+
function siteHostname(siteUrl: string): string {
28+
try {
29+
return new URL(siteUrl).hostname
30+
} catch {
31+
return ""
32+
}
33+
}

0 commit comments

Comments
 (0)