← All articles

Secrets in Backup Files and Archives: The Credentials Hiding in .zip, .sql, and .bak Dumps

July 13, 2026

The Backup File Nobody Audits

When a developer commits a .env file to a repo, there's a reasonable chance a secret scanner will catch it. When they upload a database_backup_2024-01-15.sql.gz to an S3 bucket or check a config_backup.zip into an internal file share, almost nothing catches it. Backup files and archives are one of the most reliably overlooked vectors for credential exposure—not because the risk is theoretical, but because backups are designed to be complete snapshots of a system's state, and a system's state almost always includes secrets.

This article walks through exactly where credentials hide in backup artifacts, how they get into places you don't expect, and the concrete steps you can take to close the gap before an auditor—or an attacker—finds it first.

Why Backups Carry Secrets in the First Place

Backups exist to capture everything. That thoroughness is also their vulnerability. Consider what ends up in a typical full-database dump:

  • Application config tables — Many apps store third-party API keys, OAuth tokens, and webhook signing secrets directly in the database, often in a settings or configurations table.
  • User session tokens — Long-lived session tokens stored in the database are live credentials at the moment of backup and may remain valid long after.
  • Encrypted-but-weak passwords — MD5 or unsalted SHA-1 hashes in a dumped users table are effectively plaintext given modern cracking hardware.
  • Stored procedures and migration scripts — It's surprisingly common to find hardcoded connection strings or API keys embedded directly in SQL migration files, which then get captured in every subsequent dump.

Archive files compound the problem because they're often built by scripting a directory snapshot. A tar -czf app_backup.tar.gz /var/www/app will happily include .env, config/database.yml, config/secrets.yml, and any credential file that exists in the directory tree at that moment.

The Five Most Common Backup Formats Where Credentials Hide

1. SQL Dumps (.sql, .sql.gz, .dump)

A mysqldump or pg_dump of a production database is a flat text file (sometimes compressed) containing every row in every table. If your app ever stored a Stripe secret key, a SendGrid API key, or an AWS access key in the database, it's in that file verbatim. These dumps are routinely uploaded to S3 for DR, attached to support tickets, or copied to a developer's laptop for local debugging—each transfer multiplies the exposure surface.

2. Application Archives (.zip, .tar.gz, .tar.bz2)

Developers frequently zip an application directory to move it between environments or share it with a vendor for debugging. Unless there's an explicit exclusion list, .env files, credential JSON files (like GCP service account keys), and private key files travel with the archive.

3. Database Binary Backups (.bak, .frm, .ibd, RDB files)

SQL Server .bak files and MySQL/InnoDB data files are binary, which means they won't trigger a naive text-based grep for secrets—but they can be restored to extract the same sensitive table data as a SQL dump. Redis RDB snapshots fall into the same category: a binary file containing the entire in-memory key-value store, including any session tokens or cached API responses.

4. Virtual Machine and Container Snapshots

VM snapshots and exported container images are effectively archives of an entire runtime environment. A VMware OVF export or a docker save output can contain secrets baked into image layers, mounted config files, and environment variables set at runtime—the same layer-leakage problem that affects Docker images, but now in a file that's probably sitting on a NAS somewhere with no scanning coverage.

5. Code and Configuration Backups from IDEs and Editors

Some editors and deployment tools create automatic backup archives of project directories. PhpStorm's remote deployment logs, Visual Studio's publish profiles, and cPanel's "backup wizard" output all have a history of capturing credential files that the developer never intended to export.

Where These Files End Up

The location of a backup file matters as much as its contents. The highest-risk destinations are:

  • Public or misconfigured S3 / GCS / Azure Blob buckets — "I'll make it private later" is one of the most expensive promises in cloud infrastructure.
  • Internal file shares with overly broad permissions — A backup readable by "Everyone" in an Active Directory environment is a single phishing attack away from exfiltration.
  • Developer laptops — A production database dump copied for local debugging that then syncs to iCloud or Google Drive is now reachable from a personal device with weaker security controls.
  • Support tickets and chat tools — Developers debugging a production issue sometimes attach a config dump to a Jira ticket or paste it into Slack. Both platforms index content and retain it indefinitely.
  • Git repositories.sql files and .zip archives get committed more often than you'd expect, particularly in projects that treat the repo as a general-purpose file store.

Concrete Steps to Reduce Backup-Related Credential Exposure

Step 1: Audit What You're Actually Backing Up

Run a one-time inventory of your backup processes. For each job, answer: what directories and tables are included, and does any of that content contain secrets? For application archives, use grep -rE with patterns for common secret formats before the archive is created or shipped:

# Check a directory for common secret patterns before archiving
grep -rE \
  "(AKIA[0-9A-Z]{16}|sk_live_[0-9a-zA-Z]+|ghp_[0-9a-zA-Z]+|AIza[0-9A-Za-z\-_]{35})" \
  /var/www/app/ --include="*.env" --include="*.yml" --include="*.json"

Step 2: Exclude Credential Files from Archives

Add explicit exclusions to your backup scripts for known credential file patterns:

# tar with exclusions
tar --exclude='*.env' \
    --exclude='*credentials*' \
    --exclude='*secret*' \
    --exclude='serviceAccountKey.json' \
    -czf app_backup.tar.gz /var/www/app/

For database backups, identify which tables store application secrets and either exclude them from dumps used for non-production purposes, or replace their values with placeholders before export.

Step 3: Enforce Encryption at Rest for All Backup Storage

Backup files should never land on storage that is unencrypted or world-readable. For S3, enforce Block Public Access at the account level, require SSE-KMS encryption, and attach a bucket policy that denies s3:GetObject for any principal outside your backup IAM role. Set bucket access logging so you have an audit trail of every download.

Step 4: Treat Backup Access Like Production Access

A backup of your production database is your production database. Apply the same IAM controls, the same audit logging, and the same break-glass procedures. Restrict who can restore a backup to the same people who have production database access—not to the entire engineering team because "it's just a backup."

Step 5: Scan Backup Destinations Regularly

Static scanning of your codebase is necessary but not sufficient. You need to scan the places where backup files accumulate—S3 buckets, internal file shares, artifact repositories. If you haven't scanned your repos and cloud-adjacent file stores recently, run a free GhostCred scan to get a fast picture of what's exposed before you undertake a fuller remediation effort.

Step 6: Rotate Any Secret Found in a Backup File

If a scan or audit finds a live credential in a backup file, treat it as compromised. The backup may have been accessed by someone with storage access who isn't authorized to use that credential. Rotate immediately, check access logs for the storage location, and investigate whether the credential was used in any unexpected region, service, or time window.

The SOC 2 and HIPAA Angle

Auditors reviewing SOC 2 CC6.7 (logical access) and HIPAA §164.312(a)(2)(iv) (encryption and decryption) will ask about how you protect data at rest—and backup files are data at rest. More specifically, SOC 2 CC6.1 requires that you identify assets containing sensitive information. If you can't demonstrate that you know what's in your backup files and where they're stored, that's a finding. Maintaining a backup inventory, scanning backup destinations, and enforcing encryption are the concrete controls that satisfy these requirements and give you something defensible to show an auditor.

The Practical Takeaway

Backup files earn their credential-leakage risk through a combination of completeness (they capture everything), longevity (they're retained for months or years), and invisibility (nobody thinks to scan them). The fix isn't to stop backing up—it's to apply the same discipline to backup artifacts that you (hopefully) already apply to your codebase: know what's in them, control who can access them, encrypt them at rest, and scan them for secrets on a regular schedule. Start with the low-hanging fruit: find every S3 bucket or file share that holds backup archives and verify its access policy today.

See what's exposed in your own code.

Run a free scan