Skip to main content

PII Detection

Border’s detection engine scans request bodies for 20+ types of personally identifiable information using pattern matching with algorithmic validation.

Detection Process

  1. Quick Check: Fast heuristics determine if content might contain PII
  2. Pattern Matching: Regex patterns identify potential matches
  3. Validation: Algorithmic checks confirm validity (Luhn, checksums)
  4. Confidence Scoring: Each match is assigned high/medium/low confidence

Using the Detection API

import { findPii, createDefaultDetectionConfig } from "@dotsetlabs/border";

const config = createDefaultDetectionConfig();
const matches = findPii("Email: [email protected], SSN: 123-45-6789", config);

for (const match of matches) {
  console.log(`${match.type}: ${match.text} (${match.confidence})`);
}
// email: [email protected] (high)
// ssn: 123-45-6789 (high)

Validation Algorithms

Border uses algorithmic validation to reduce false positives:
TypeAlgorithm
Credit CardsLuhn checksum + network detection
SSNsArea/group/serial validation
IBANsMOD-97 checksum
ABA RoutingWeighted checksum
VINsCheck digit validation
import { luhnCheck, validateSsn, detectCardNetwork } from "@dotsetlabs/border";

luhnCheck("4532015112830366");     // true
validateSsn("123-45-6789");        // true
detectCardNetwork("4532...");      // "visa"

Confidence Levels

LevelMeaningExample
highAlgorithmically validatedLuhn-valid credit card
mediumStrong pattern matchWell-formatted email
lowPattern match onlyUnformatted 9-digit number
Configure sensitivity to filter by confidence:
init({
  sensitivity: "low", // Only high-confidence matches
});

Custom Patterns

Add your own detection patterns:
init({
  customPatternDefinitions: [
    {
      name: "internal_id",
      pattern: /ACME-[A-Z0-9]{8}/g,
      description: "ACME Corp internal IDs",
      confidence: "high",
    },
  ],
});

Disabling Detectors

Disable specific PII types:
init({
  disabledDetectors: ["ip_address", "mac_address"],
});

Next Steps