description: Data & storage security (DB isolation, TLS, least privilege, RLS/CLS, backups, auditing)
languages:
- c
- javascript
- sql
- yaml
alwaysApply: false
rule_id: codeguard-0-data-storage
Database Security Guidelines
This rule advises on securely configuring SQL and NoSQL databases to protect against data breaches and unauthorized access:
Backend Database Protection
- Isolate database servers from other systems and limit host connections.
- Disable network (TCP) access when possible; use local socket files or named pipes.
- Configure database to bind only on localhost when appropriate.
- Restrict network port access to specific hosts with firewall rules.
- Place database server in separate DMZ isolated from application server.
- Never allow direct connections from thick clients to backend database.
Transport Layer Security
- Configure database to only allow encrypted connections.
- Install trusted digital certificates on database servers.
- Use TLSv1.2+ with modern ciphers (AES-GCM, ChaCha20) for client connections.
- Verify digital certificate validity in client applications.
- Ensure all database traffic is encrypted, not just initial authentication.
Secure Authentication Configuration
- Always require authentication, including from local server connections.
- Protect accounts with strong, unique passwords.
- Use dedicated accounts per application or service.
- Configure minimum required permissions only.
- Regularly review accounts and permissions.
- Remove accounts when applications are decommissioned.
- Change passwords when staff leave or compromise is suspected.
Database Credential Storage
- Never store credentials in application source code.
- Store credentials in configuration files outside web root.
- Set appropriate file permissions for credential access.
- Never check credential files into source code repositories.
- Encrypt credential storage using built-in functionality when available.
- Use environment variables or secrets management solutions.
Secure Permission Management
- Apply principle of least privilege to all database accounts.
- Do not use built-in root, sa, or SYS accounts.
- Do not grant administrative rights to application accounts.
- Restrict account connections to allowed hosts only.
- Use separate databases and accounts for Development, UAT, and Production.
- Grant only required permissions (SELECT, UPDATE, DELETE as needed).
- Avoid making accounts database owners to prevent privilege escalation.
- Implement table-level, column-level, and row-level permissions when needed.
Database Configuration and Hardening
- Install required security updates and patches regularly.
- Run database services under low-privileged user accounts.
- Remove default accounts and sample databases.
- Store transaction logs on separate disk from main database files.
- Configure regular encrypted database backups with proper permissions.
- Disable unnecessary stored procedures and dangerous features.
- Implement database activity monitoring and alerting.
Platform-Specific Hardening
- SQL Server: Disable xp_cmdshell, CLR execution, SQL Browser service, Mixed Mode Authentication (unless required).
- MySQL/MariaDB: Run mysql_secure_installation, disable FILE privilege for users.
- PostgreSQL: Follow PostgreSQL security documentation guidelines.
- MongoDB: Implement MongoDB security checklist requirements.
- Redis: Follow Redis security guide recommendations.
Summary:
Isolate database systems, enforce encrypted connections, implement strong authentication, store credentials securely using secrets management, apply least privilege permissions, harden database configurations, and maintain regular security updates and monitoring.
1---2name: 447-control-set-10-data-protection-cbab8bd53description: <!-- Threat Modeling Skill | Version 3.0.3 (20260209a) | https://github.com/fr33d3m0n/threat-modeling | License: BSD-3-Clause -->4---5<!-- Threat Modeling Skill | Version 3.0.3 (20260209a) | https://github.com/fr33d3m0n/threat-modeling | License: BSD-3-Clause -->67---8description: Data & storage security (DB isolation, TLS, least privilege, RLS/CLS, backups, auditing)9languages:10- c11- javascript12- sql13- yaml14alwaysApply: false15---1617rule_id: codeguard-0-data-storage1819## Database Security Guidelines2021This rule advises on securely configuring SQL and NoSQL databases to protect against data breaches and unauthorized access:2223- Backend Database Protection24 - Isolate database servers from other systems and limit host connections.25 - Disable network (TCP) access when possible; use local socket files or named pipes.26 - Configure database to bind only on localhost when appropriate.27 - Restrict network port access to specific hosts with firewall rules.28 - Place database server in separate DMZ isolated from application server.29 - Never allow direct connections from thick clients to backend database.3031- Transport Layer Security32 - Configure database to only allow encrypted connections.33 - Install trusted digital certificates on database servers.34 - Use TLSv1.2+ with modern ciphers (AES-GCM, ChaCha20) for client connections.35 - Verify digital certificate validity in client applications.36 - Ensure all database traffic is encrypted, not just initial authentication.3738- Secure Authentication Configuration39 - Always require authentication, including from local server connections.40 - Protect accounts with strong, unique passwords.41 - Use dedicated accounts per application or service.42 - Configure minimum required permissions only.43 - Regularly review accounts and permissions.44 - Remove accounts when applications are decommissioned.45 - Change passwords when staff leave or compromise is suspected.4647- Database Credential Storage48 - Never store credentials in application source code.49 - Store credentials in configuration files outside web root.50 - Set appropriate file permissions for credential access.51 - Never check credential files into source code repositories.52 - Encrypt credential storage using built-in functionality when available.53 - Use environment variables or secrets management solutions.5455- Secure Permission Management56 - Apply principle of least privilege to all database accounts.57 - Do not use built-in root, sa, or SYS accounts.58 - Do not grant administrative rights to application accounts.59 - Restrict account connections to allowed hosts only.60 - Use separate databases and accounts for Development, UAT, and Production.61 - Grant only required permissions (SELECT, UPDATE, DELETE as needed).62 - Avoid making accounts database owners to prevent privilege escalation.63 - Implement table-level, column-level, and row-level permissions when needed.6465- Database Configuration and Hardening66 - Install required security updates and patches regularly.67 - Run database services under low-privileged user accounts.68 - Remove default accounts and sample databases.69 - Store transaction logs on separate disk from main database files.70 - Configure regular encrypted database backups with proper permissions.71 - Disable unnecessary stored procedures and dangerous features.72 - Implement database activity monitoring and alerting.7374- Platform-Specific Hardening75 - SQL Server: Disable xp_cmdshell, CLR execution, SQL Browser service, Mixed Mode Authentication (unless required).76 - MySQL/MariaDB: Run mysql_secure_installation, disable FILE privilege for users.77 - PostgreSQL: Follow PostgreSQL security documentation guidelines.78 - MongoDB: Implement MongoDB security checklist requirements.79 - Redis: Follow Redis security guide recommendations.8081Summary: 82Isolate database systems, enforce encrypted connections, implement strong authentication, store credentials securely using secrets management, apply least privilege permissions, harden database configurations, and maintain regular security updates and monitoring.