/** * Copyright 2026 aphrody-code * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @module bxc/google/detector * * Specialized fingerprinting for Google-specific frameworks and anti-bot signals. */ import type { DetectedTech } from "../detect.ts"; import { isGoogleDomain } from "./dns.ts"; export interface GoogleDetection { isGoogleOwned: boolean; isMaterialDesign: boolean; framework: "angular" | "lit" | "wiz" | "internal" | "none"; hasAntiBot: boolean; /** Specific anti-bot mechanism, when identifiable. */ antiBotKind: | "recaptcha-v2" | "recaptcha-v3" | "recaptcha-enterprise" | "captcha-form" | null; /** Detected first-party Google products, e.g. ["Gemini", "Firebase", "GTM"]. */ products: string[]; /** Hosting signal: appspot, firebase, cloud-run, none. */ hosting: "appspot" | "firebase" | "cloud-run" | "google-sites" | "none"; evidence: string[]; } const GOOGLE_MARKERS_REGEX = /(ng-version|ng-app|_nghost-|lit-html|, body: string, ): GoogleDetection { const evidence: string[] = []; let hostname = ""; try { hostname = new URL(url).hostname; } catch {} const isGoogleOwned = isGoogleDomain(hostname); if (isGoogleOwned) evidence.push("hostname matches google domain list"); // Framework detection let framework: GoogleDetection["framework"] = "none"; // Single highly optimized V8 regex pass const matchesArray = body.match(GOOGLE_MARKERS_REGEX); const matches = matchesArray ? new Set(matchesArray) : new Set(); if ( matches.has("ng-version") || matches.has("ng-app") || matches.has("_nghost-") ) { framework = "angular"; evidence.push("angular markers (ng-version/ng-app) found"); } else if (matches.has("lit-html") || matches.has(" = { TensorFlow: "TensorFlow", Flutter: "Flutter", Firebase: "Firebase", GCP: "Google Cloud Platform", Kubernetes: "Kubernetes", Go: "Go", }; for (const evidence of detection.evidence) { for (const [key, name] of Object.entries(projectMap)) { if (evidence.includes(key)) { techs.push({ name, categories: ["Libraries", "Development"] }); } } } if (detection.framework !== "none") { const names = { angular: "Angular", lit: "Lit", wiz: "Wiz (Google Internal)", internal: "Google Internal", }; techs.push({ name: names[detection.framework as keyof typeof names], categories: ["JavaScript frameworks"], }); } if (detection.hasAntiBot) { const antiBotName = detection.antiBotKind ? `Google Anti-Bot (${detection.antiBotKind})` : "Google Anti-Bot"; techs.push({ name: antiBotName, categories: ["Security"] }); } for (const product of detection.products) { techs.push({ name: product, categories: ["Google Products"] }); } if (detection.hosting !== "none") { const hostingMap = { appspot: "Google App Engine", firebase: "Firebase Hosting", "cloud-run": "Google Cloud Run", "google-sites": "Google Sites", } as const; techs.push({ name: hostingMap[detection.hosting], categories: ["PaaS", "Hosting"], }); } return techs; }