Data Loss Prevention

Production engineering guide for data loss prevention covering patterns, implementation strategies, and operational best practices.

Data Loss Prevention (DLP) is a security discipline focused on detecting and preventing unauthorized exfiltration, leakage, or deletion of sensitive data across systems, networks, and endpoints. It matters when data is at risk—during transfer, in motion, in use, or at rest—and when a single breach can expose customer PII, financial records, intellectual property, or compliance-regulated information. DLP systems monitor, classify, and protect data across email, file shares, cloud storage, databases, and applications, acting as the last line of defense against insider threats, ransomware, and targeted attacks.

Detecting Sensitive Data

The foundation of DLP is identifying what constitutes sensitive data. This begins with pattern matching and content analysis using predefined and custom rules. The system scans data for known formats, values, or linguistic patterns.

A typical rule scans for U.S. Social Security numbers (SSNs) using the pattern ^\d{3}-\d{2}-\d{4}$, and classifies any match as “PII – SSN”. The system applies rules across file contents, database columns, email bodies, and API request payloads.

To define such rules, a configuration schema is used. Rules are grouped into policies, each with a priority, a scope, and a set of triggers.

{
  "policies": [
    {
      "name": "Customer PII Protection",
      "priority": 10,
      "scope": {
        "sources": [
          "email",
          "file-share",
          "cloud-storage"
        ],
        "locations": [
          "s3://internal-data/",
          "drive://customers/"
        ],
        "fileTypes": [
          "pdf",
          "xlsx",
          "docx"
        ]
      },
      "rules": [
        {
          "name": "SSN Detection",
          "type": "regex",
          "pattern": "^\\d{3}-\\d{2}-\\d{4}$",
          "confidence": 0.9,
          "classification": "PII – SSN"
        },
        {
          "name": "Credit Card Number",
          "type": "luhn",
          "classification": "PII – Credit Card"
        },
        {
          "name": "Keyword Match",
          "type": "keywords",
          "keywords": [
            "confidential",
            "proprietary",
            "draft",
            "quarterly report"
          ],
          "minMatches": 2,
          "classification": "Internal Document"
        }
      ]
    }
  ]
}

The system evaluates data at ingestion, during scheduled scans, or on-demand. A file uploaded to s3://internal-data/2024/financials.xlsx triggers a scan, which returns a list of detected sensitive data items:

{
  "scanId": "scan-20240402-1234",
  "source": "s3://internal-data/2024/financials.xlsx",
  "detected": [
    {
      "type": "PII – SSN",
      "value": "123-45-6789",
      "context": "Employee ID: 12345, Name: Jane Doe",
      "location": "Sheet1!A5",
      "confidence": 0.98
    },
    {
      "type": "PII – Credit Card",
      "value": "4111111111111111",
      "context": "Payment details for vendor invoice #1002",
      "location": "Sheet2!B12",
      "confidence": 0.92
    }
  ]
}

Common Pitfalls in Detection

Classifying and Tagging Data

Once detected, sensitive data is classified and tagged. Classification is not just labeling—it involves enriching data with metadata that influences downstream actions.

The system assigns a classification field to each data element, and optionally attaches labels, categories, and risk scores.

{
  "data": {
    "id": "doc-789",
    "source": "email",
    "timestamp": "2024-04-02T10:30:00Z",
    "content": "Please find attached the Q1 financials. The data is confidential. SSN: 123-45-6789.",
    "classification": [
      "PII – SSN",
      "PII – Credit Card",
      "Internal Document"
    ],
    "labels": [
      "high-impact",
      "regulatory",
      "quarterly-report"
    ],
    "riskScore": 8.7,
    "metadata": {
      "sourceSystem": "Outlook",
      "owner": "[email protected]",
      "created": "2024-04-01T09:00:00Z"
    }
  }
}

Classification rules can be hierarchical. A document with both a credit card number and an SSN is classified as “PII – Credit Card” and “PII – SSN”, and the system may merge them into a single “PII” category.

Key Failure Modes

Protecting Data with Policies

After classification, DLP policies determine how data is protected. Policies are evaluated in sequence and may trigger actions such as encryption, access restrictions, alerts, or automatic workflows.

A policy is defined by a set of conditions and actions. Conditions may be based on classification, location, user, time, or metadata.

{
  "policy": {
    "name": "Export to External Share",
    "conditions": [
      {
        "field": "classification",
        "operator": "contains",
        "value": "PII – SSN"
      },
      {
        "field": "source",
        "operator": "equals",
        "value": "cloud-storage"
      },
      {
        "field": "metadata.owner",
        "operator": "in",
        "value": [
          "[email protected]",
          "[email protected]"
        ]
      }
    ],
    "actions": [
      {
        "type": "encrypt",
        "algorithm": "aes-256-gcm",
        "keyId": "key-123",
        "scope": "file"
      },
      {
        "type": "add-tag",
        "tag": "external-share-ready"
      },
      {
        "type": "send-alert",
        "channel": "email",
        "template": "external-share-ready",
        "recipients": [
          "[email protected]",
          "[email protected]"
        ]
      },
      {
        "type": "apply-retention",
        "days": 365,
        "label": "long-term-retention"
      }
    ],
    "enforcement": {
      "mode": "enforce",
      "trigger": "on-upload",
      "delay": "30s"
    }
  }
}

When a file is uploaded to cloud-storage with an SSN and owned by Jane Doe, the system evaluates the policy and executes all actions in sequence.

Sharp Edges in Enforcement

Monitoring and Alerting

DLP systems generate logs and alerts to track data flow and policy effectiveness. Events are emitted on every classification, policy execution, and action completion.

A typical event log entry:

{
  "eventId": "event-20240402-001",
  "timestamp": "2024-04-02T10:31:15Z",
  "eventType": "policy-execution",
  "policy": "Export to External Share",
  "status": "success",
  "details": {
    "input": {
      "file": "s3://internal-data/2024/financials.xlsx",
      "classification": [
        "PII – SSN",
        "PII – Credit Card"
      ],
      "owner": "[email protected]"
    },
    "actions": [
      {
        "type": "encrypt",
        "status": "success",
        "output": {
          "encryptedFile": "s3://internal-data/2024/financials.xlsx.enc",
          "keyId": "key-123"
        }
      },
      {
        "type": "add-tag",
        "status": "success",
        "tag": "external-share-ready"
      },
      {
        "type": "send-alert",
        "status": "failed",
        "error": "SMTP connection timeout",
        "recipients": [
          "[email protected]",
          "[email protected]"
        ]
      }
    ]
  }
}

Alerts are sent via email, Slack, or webhook. A failure in the send-alert action triggers a secondary alert with details.

Common Alerting Failures

Integrating with Existing Systems

DLP is not a standalone system. It integrates with identity providers, file systems, databases, and application platforms.

SELECT customer_id, name, email, ssn, credit_card, address
FROM customers
WHERE created_at >= '2024-01-01';

-- Output:
--   ssn: 123-45-6789 (PII – SSN)
--   credit_card: 4111111111111111 (PII – Credit Card)
--   address: 123 Main St, Anytown, CA 90210 (PII – Address)

Integration Pitfalls

Summary: What You Must Know

The system fails silently when it does not propagate classification changes, when actions are not retried on failure, and when policies are evaluated with stale data. A DLP system is not just a scanner—it is a data protection engine.

This page was rewritten on 16 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.