Security for Legal SaaS

Episode 30 · Module 7 · Data Protection

Secrets Management

19 May 2026 · 8:04 · Security for Legal SaaS

8:04 8:04

In Episode 29, we covered cryptographic key management — the infrastructure protecting your encryption keys. But encryption keys are only one type of secret your application depends on. Every legal SaaS platform runs on dozens of secrets: database passwords, API keys for e-filing integrations, LLM provider tokens, OAuth client secrets, SMTP credentials, and webhook signing keys. If any of these leak, an attacker doesn't need to break your encryption — they walk through the front door.

Today’s Lesson

Security for Legal SaaS — Episode 30: Secrets Management

If It's in Your Git History, It's Not a Secret

In Episode 29, we covered cryptographic key management — the infrastructure protecting your encryption keys. But encryption keys are only one type of secret your application depends on. Every legal SaaS platform runs on dozens of secrets: database passwords, API keys for e-filing integrations, LLM provider tokens, OAuth client secrets, SMTP credentials, and webhook signing keys. If any of these leak, an attacker doesn't need to break your encryption — they walk through the front door.

GitGuardian's 2025 State of Secrets Sprawl Report found that 23.8 million secrets were leaked on public GitHub repositories in 2024 — a 25% increase year-over-year. Worse, 70% of secrets detected in 2022 were still active two years later. Nobody revoked them.1

This episode covers the secrets lifecycle: how to generate, store, distribute, rotate, and revoke the credentials that keep your system running.

What Counts as a Secret

A secret is any credential, token, or key that grants access to a system or resource. In a typical legal SaaS stack:

Secret Type What It Accesses Risk If Leaked
Database connection string Production database with client case data Full data exfiltration
LLM API key (OpenAI, Anthropic) AI model endpoints; billed per-token Financial abuse + data exposure via prompts
OAuth client secret Identity provider integration (Okta, Azure AD) Account impersonation
SMTP credentials Email sending (client notifications, e-filing confirmations) Phishing from your domain
Webhook signing key Verification of inbound webhooks (payment processors, court APIs) Forged event injection
Cloud IAM credentials AWS/GCP/Azure infrastructure Full infrastructure compromise

Every one of these is a skeleton key to a different room in your building. Secrets management is about ensuring none of them are lying on the floor.

The Secrets Lifecycle

The OWASP Secrets Management Cheat Sheet defines five stages:2

1. Generation

Secrets must be generated with sufficient entropy using cryptographically secure random number generators (CSPRNGs — as we introduced in Episode 19). Never use predictable patterns, sequential values, or human-chosen passwords for machine credentials. API keys should be at least 256 bits of randomness.

2. Storage

Secrets belong in a dedicated secrets manager — never in source code, environment files checked into version control, or configuration management databases.

The .env trap: Many developers store secrets in `.env` files during development. The problem arrives when `.env` gets committed to git. Removing it from the current branch does not remove it from git history. Every clone of the repository — every developer's laptop, every CI runner, every fork — contains the full history, including the secret. Git history is permanent.3

3. Distribution

Secrets must reach your application at runtime without passing through insecure channels. The two dominant patterns:

Pattern How It Works Example
Pull-based Application authenticates to secrets manager and retrieves secrets at startup App uses IAM role to pull from AWS Secrets Manager
Injection-based Orchestration platform injects secrets as environment variables at deployment Kubernetes Secrets mounted as volumes; CI/CD variable injection

Pull-based is generally preferred because the application authenticates independently, and secrets are never written to disk or deployment manifests.4

4. Rotation

Secrets should have defined lifetimes. Dynamic secrets — short-lived credentials generated on demand — are the gold standard. HashiCorp Vault's dynamic secrets engine can generate database credentials that automatically expire after a configurable TTL (time to live, as we covered in Episode 19). The application requests credentials, uses them for the session, and they self-destruct.5

5. Revocation

When a secret is compromised — or when an employee leaves, a service is decommissioned, or a vendor relationship ends — the secret must be immediately revoked. This requires a centralised system that knows every active secret and can invalidate any of them instantly.

Secrets Managers Compared

Tool Type Dynamic Secrets Secret Scanning Best For
HashiCorp Vault Self-hosted or managed Yes (database, cloud, PKI) No (pair with scanner) Full lifecycle; multi-cloud
AWS Secrets Manager Managed Yes (RDS rotation) No AWS-native stacks
Doppler Managed No Yes (drift detection) Developer experience; small teams
1Password for Teams Managed No CLI integration Shared team secrets; non-engineering

For legal SaaS platforms, the minimum viable setup is: a managed secrets manager (AWS Secrets Manager or Vault), pre-commit secret scanning in CI, and a documented rotation policy.6

Secret Scanning: Catching Leaks Before They Ship

The defence against accidental commits is a pre-commit hook that scans staged changes for patterns matching known secret formats. Tools include:

The AI complication: GitHub Copilot usage increased 27% between 2023 and 2024. Repositories using Copilot had a 6.4% secret leakage rate — AI code completion can suggest patterns that include placeholder credentials matching real formats.8

LLM API Keys: A Special Case

LLM API keys deserve particular attention for legal SaaS:

  1. High financial exposure. A leaked OpenAI or Anthropic API key can generate thousands of dollars in charges within hours.
  2. Data exposure. If an attacker uses your API key, they can send prompts containing your clients' legal documents to the model provider — and those prompts may be logged.
  3. Per-environment isolation. Development, staging, and production must use separate API keys. A developer's test key should never have access to production-tier models or billing.
  4. Rate limiting and spend caps. Configure provider-side spending limits and alert thresholds so a compromised key burns through a cap, not your budget.

Real-World Secret Leaks in Legal and Professional Services

Incident What Happened Impact
Uber (2016) Engineers stored AWS credentials in a private GitHub repository; attackers found them 57 million records exposed; $148 million settlement
Samsung (2022) Employees pasted proprietary source code — including secret keys — into ChatGPT prompts Internal secrets exposed to a third-party AI provider; Samsung banned ChatGPT internally
CircleCI (2023) An engineer's laptop was compromised, exposing the master encryption key that protected all customers' secrets in the CI/CD platform Every customer secret potentially exposed; immediate rotation required across all customers

For legal SaaS, the Samsung case is particularly instructive. As legal teams adopt AI coding assistants and LLM-powered research tools, the risk of accidentally pasting secrets — API keys, credentials, even privileged client data — into third-party AI prompts is growing. Secret scanning should cover not just git commits but also AI tool integrations.10

The 96% stat: GitGuardian found that 96% of leaked GitHub tokens had write access — not just read access. A compromised token doesn't just let an attacker see your code. It lets them modify it, inject backdoors, or push malicious releases. For a legal SaaS platform, that means a leaked deployment token could allow an attacker to push code that exfiltrates client data.1

The Twelve-Factor App and Configuration

The Twelve-Factor App methodology, widely adopted in modern SaaS development, states: "Store config in the environment." Configuration that varies between deployments — including secrets — should come from environment variables, not from files in the codebase. This principle keeps secrets out of version control by design.9

But environment variables have their own risks. They appear in process listings (`ps aux`), crash dumps, and logging frameworks that capture the full environment. The safest approach is to use environment variables as pointers to a secrets manager, not as the secrets themselves: `DATABASE_URL_SECRET_ARN=arn:aws:secretsmanager:...` rather than `DATABASE_URL=postgres://user:password@host/db`.

What's Next

Episode 31 covers PII Handling and Anonymisation — how to classify, minimise, and protect personally identifiable information in legal tech, where personal data is often also privileged data.

Sources & Further Reading

Sources & references

  1. GitGuardian, State of Secrets Sprawl 2025 — 23.8 million secrets leaked on public GitHub in 2024; 70% of 2022 secrets still active in 2024.
  2. OWASP, Secrets Management Cheat Sheet.
  3. Snyk, Why 28 Million Credentials Leaked on GitHub in 2025 — git history permanence and remediation challenges.
  4. Palo Alto Networks, The Top 5 Secrets Management Mistakes and How to Avoid Them.
  5. HashiCorp, Vault Secrets Management Tutorials — Dynamic Secrets.
  6. OWASP, Non-Human Identities Top 10: NHI2:2025 Secret Leakage.
  7. GitGuardian, The State of Secrets Sprawl 2025 — Push Protection.
  8. GitGuardian, 70% of Leaked Secrets Stay Active Two Years Later — Copilot secret leakage rate.
  9. Twelve-Factor App, III. Config.
  10. InfoQ, Secret Sprawl in Public Repos is Worse Than Ever.