Table of Contents
Start by limiting who can reach the database and what each account can do. Keep the database on a private network or local socket, give each application a limited role, and test that backups can restore the data you need. These controls protect against different failures, from stolen credentials to accidental deletion.

Keep the database off the public network
Allow connections only from approved application hosts and administrative paths. Use a private endpoint, firewall rules, or a local socket as appropriate. Require database TLS with certificate verification for network connections. HTTPS between a browser and the application covers a separate connection from the application to the database.
Give every account the access it needs
- Use a different account for each service and environment. Give a read-only reporting service only the reads it needs.
- Keep administrative access and schema migrations separate from everyday application queries. Review roles periodically and revoke accounts that are no longer needed.
- Store credentials in an approved secret store. Rotate exposed secrets and use managed identities or short-lived credentials when your platform supports them.
- Use parameterized queries in application code. A web application firewall adds a layer of filtering, while the database and application still need their own access and input controls.
Protect backups and verify recovery
Encrypt databases and backups where appropriate and restrict access to the encryption keys. Keep a backup copy that ordinary application credentials cannot modify or delete. Restore a backup to an isolated environment and check how much data you can recover and how long recovery takes.
Patch and monitor the database

Schedule updates for the database engine, drivers, and host. Collect logs for failed logins, role changes, administrative activity, and unusual exports. Restrict access to logs and avoid recording passwords or unnecessary personal data. If you operate the physical server, restrict physical access as well.
See the OWASP Database Security Cheat Sheet for engine-specific configuration considerations.
Reader Comments 0
Sign in with email or Google to join the discussion.