Safeguard
Security Guides•

Does encrypting a database column stop SQL injection from leaking it?

Not by itself. If the app decrypts on read, an injected query through the app can return plaintext. What column encryption covers and what it does not.

Safeguard Security Team
4 min read

Not by itself. Column encryption protects data at rest, such as stolen backups, snapshots or a raw database dump. If the application holds the key and decrypts values when it reads them, an attacker who takes over the application's queries or its database session may get plaintext back through the app's own logic.

What column encryption is good for

It reduces what an attacker gets from places that only see stored bytes: a copied backup, a leaked disk snapshot, a database administrator browsing tables, or a read only replica shared too widely. OWASP's guidance is that keys should be stored in a separate location from the encrypted data, so reaching one does not give both.

Where it falls short

AttackDoes column encryption help?
Stolen backup fileYes, if the key is not in the backup
Direct SQL injection that dumps the tableYes, the dumped column is ciphertext
Injection or abuse of a code path that decrypts and returns dataNo, the app does the decryption for the attacker
Compromised application server with key accessNo
Stolen application credentials that can call the key serviceNo
Insider with legitimate app accessNot by itself

The second row surprises people. A classic injection that reads tables directly may hit ciphertext. Real attacks often chain: read the encrypted value and the key from a place the app can reach, or abuse a function that returns decrypted data. The result depends on where the key lives and what the database account can reach.

The fix for injection is not encryption

Prevent injection at the source. Use parameterized queries, least privilege database accounts, input validation and testing. Encryption is a second layer, not a replacement. A dynamic scan can check whether endpoints are injectable.

Design choices that make encryption count

  1. Keep keys in a key vault or service, not in the database or the same host as the data.
  2. Give the application permission to use a key, and where the service allows, not to export it.
  3. Use a separate database account per function, so a vulnerable report page cannot read the encrypted columns.
  4. Log each decrypt call and alert on unusual volume.
  5. Encrypt only what needs it, and avoid returning decrypted fields in broad API responses.
  6. Test: with injection in a test environment, what comes back?

Searching encrypted fields

Encrypted values cannot be searched by equality or range without extra design. Teams then store a separate keyed hash for lookup, or decrypt many rows in the application, which expands exposure. Plan for this before choosing which fields to encrypt, and keep any lookup hash keyed, with its own key.

Compare with other layers

Disk or database level encryption protects against lost media. Application level encryption, with keys held elsewhere, protects against more, but it adds code you must get right. See encryption at rest: disk, database or application level for how to choose.

Safeguard can generate an SBOM and scan your dependencies, so outdated cryptography libraries with known advisories show up in one inventory, and policies can gate a build on them. A free scan is at gold.safeguard.sh/scan.

Quick check

Is transparent database encryption enough against injection?

No. The database decrypts for any authorized session, including one an attacker controls through injection.

Should I stop encrypting columns then?

No. Keep it for the threats it covers, and fix injection separately.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.