Skip to main content

Credential Detection

The detection engine scans text for 47 credential patterns across AI providers, cloud platforms, SaaS services, and infrastructure tools. Each detection includes a confidence score.

Functions

detectCredentials(text)

Scan a string for credentials. Returns all matches with position, type, confidence, and the matched pattern name. Returns: DetectionResult[]
import { detectCredentials } from '@id-wispera/core';

const results = detectCredentials(fs.readFileSync('.env', 'utf8'));
results.forEach(r => {
  console.log(`${r.name}: ${r.type} (confidence: ${r.confidence})`);
});

classifyCredential(value)

Classify a single credential string by matching it against known patterns. Returns the highest-confidence credential type. Returns: CredentialType

mightContainCredentials(text)

Fast pre-check using 11 lightweight patterns. Use before detectCredentials() to skip files that clearly contain no credentials. Returns: boolean

maskCredentialsInText(text)

Replace all detected credentials in a string with masked versions. Useful for safe logging. Returns: string

getDetectionStats(results)

Summarize detection results: total count, breakdown by type, high-confidence count, average confidence.

Supported Patterns (47)

CategoryPatterns
AI ProvidersOpenAI (4 variants), Anthropic, Google, Azure
CloudAWS Access Key, AWS Secret, Google Cloud
Code PlatformsGitHub (5 variants), npm, PyPI
CommunicationSlack (3 variants), Discord (2 variants), Twilio
PaymentStripe (3 variants)
EmailSendGrid, Mailgun
Auth TokensJWT, Bearer Token
SecretsPrivate Keys (RSA, EC, OpenSSH, generic)
Connection StringsMongoDB, PostgreSQL, MySQL, Redis
OpenClawGateway Token, Telegram Bot, OpenRouter, WhatsApp JID
GenericAPI Key, Secret