/** * Backend Framework Fingerprinting (D-010) * * Detects backend frameworks from HTTP headers and HTML patterns, * then applies convention-based API patterns for each framework. * * Supported frameworks: * - Rails (Ruby) * - Django (Python) * - Phoenix (Elixir) * - FastAPI (Python) * - Spring Boot (Java) * - Laravel (PHP) * - Express (Node.js) * - ASP.NET Core (C#) * * Detection methods: * 1. HTTP response headers (X-Powered-By, X-Runtime, Server, etc.) * 2. Cookie patterns (session cookie names, CSRF tokens) * 3. HTML patterns (meta tags, CSRF token names, asset paths) * 4. Error page signatures * 5. API endpoint conventions */ import type { LearnedApiPattern } from '../types/api-patterns.js'; /** * Supported backend frameworks */ export type BackendFramework = 'rails' | 'django' | 'phoenix' | 'fastapi' | 'spring-boot' | 'laravel' | 'express' | 'aspnet-core' | 'unknown'; /** * Evidence for a framework detection */ export interface FrameworkEvidence { /** Type of evidence */ type: 'header' | 'cookie' | 'html' | 'error-page' | 'endpoint'; /** The specific indicator found */ indicator: string; /** Value that matched */ value: string; /** Confidence contribution (0-1) */ weight: number; } /** * Result of framework fingerprinting */ export interface FrameworkFingerprintResult { /** Detected framework (or 'unknown') */ framework: BackendFramework; /** Confidence in detection (0-1) */ confidence: number; /** All evidence collected */ evidence: FrameworkEvidence[]; /** Framework version if detectable */ version?: string; /** Suggested API patterns based on framework conventions */ suggestedPatterns: FrameworkApiPattern[]; /** Time taken for fingerprinting (ms) */ fingerprintTime: number; } /** * Convention-based API pattern for a framework */ export interface FrameworkApiPattern { /** Pattern path (e.g., '/api/v1/{resource}') */ path: string; /** HTTP methods typically supported */ methods: Array<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>; /** Description of the pattern */ description: string; /** Confidence in this pattern */ confidence: number; } /** * Options for framework fingerprinting */ export interface FingerprintOptions { /** Custom headers for requests */ headers?: Record; /** Request timeout (ms) */ timeout?: number; /** Custom fetch function */ fetchFn?: (url: string, init?: RequestInit) => Promise; /** Skip certain detection methods */ skipMethods?: Array<'header' | 'cookie' | 'html' | 'error-page' | 'endpoint'>; } /** * Discovery result with caching */ export interface BackendFrameworkDiscoveryResult { /** Whether a framework was detected */ found: boolean; /** The fingerprinting result */ result?: FrameworkFingerprintResult; /** Patterns generated from framework conventions */ patterns: LearnedApiPattern[]; /** Error message if discovery failed */ error?: string; /** When this was cached */ cachedAt?: number; } /** Cache TTL: 2 hours (frameworks don't change often) */ export declare const FRAMEWORK_CACHE_TTL_MS: number; /** Default request timeout */ export declare const DEFAULT_TIMEOUT_MS = 10000; /** Minimum confidence to report a detection */ export declare const MIN_DETECTION_CONFIDENCE = 0.4; /** * Header signatures for each framework */ export declare const HEADER_SIGNATURES: Record>; /** * Cookie name patterns for each framework */ export declare const COOKIE_SIGNATURES: Record>; /** * HTML patterns for each framework */ export declare const HTML_SIGNATURES: Record>; /** * API endpoint conventions for each framework */ export declare const API_CONVENTIONS: Record; /** * Get cached fingerprint result * Uses unified discovery cache with tenant isolation */ export declare function getCachedFingerprint(domain: string): Promise; /** * Cache a fingerprint result * Uses unified discovery cache */ export declare function cacheFingerprint(domain: string, result: BackendFrameworkDiscoveryResult, ttlMs?: number): Promise; /** * Clear fingerprint cache */ export declare function clearFingerprintCache(domain?: string): Promise; /** * Analyze HTTP headers for framework signatures */ export declare function analyzeHeaders(headers: Headers | Record): Map; /** * Analyze cookies for framework signatures */ export declare function analyzeCookies(cookieHeader: string | null): Map; /** * Analyze HTML content for framework signatures */ export declare function analyzeHtml(html: string): Map; /** * Combine evidence from multiple sources and determine the most likely framework */ export declare function combineEvidence(headerEvidence: Map, cookieEvidence: Map, htmlEvidence: Map): { framework: BackendFramework; confidence: number; evidence: FrameworkEvidence[]; }; /** * Fingerprint a domain to detect its backend framework */ export declare function fingerprintBackendFramework(domain: string, options?: FingerprintOptions): Promise; /** * Generate LearnedApiPattern objects from framework conventions */ export declare function generatePatternsFromFramework(framework: BackendFramework, domain: string, frameworkConfidence: number): LearnedApiPattern[]; /** * Discover backend framework and generate patterns */ export declare function discoverBackendFramework(domain: string, options?: FingerprintOptions): Promise; /** * Discover backend framework with caching * Uses unified discovery cache with failed domain tracking */ export declare function discoverBackendFrameworkCached(domain: string, options?: FingerprintOptions): Promise; export { fingerprintBackendFramework as fingerprint, discoverBackendFramework as discover, discoverBackendFrameworkCached as discoverCached, }; //# sourceMappingURL=backend-framework-fingerprinting.d.ts.map