A comprehensive collection of WordPress security implementations that demonstrate how to secure WordPress without relying on third-party plugins. This repository showcases security measures from basic hardening to advanced cryptographic implementations.
This repository is designed for WordPress developers and security professionals who want to understand and implement security measures directly in their WordPress applications. All examples follow WordPress best practices and coding standards.
- Custom 2FA Implementation (
custom-2fa.php) - RFC 6238 compliant TOTP with WordPress hooks - Strong Password Policies (
strong-authentication.php) - Enforced complexity requirements - Secure Login Process (
secure-login-process.php) - Custom URLs, rate limiting, error hiding - WordPress Integration (
custom-2fa-usage.php) - Complete 2FA integration example
- Input Validation (
validate-input.php) - SQL injection prevention with prepared statements - Output Escaping (
escape-output.php) - XSS prevention with context-aware escaping - AJAX Security (
secure-ajax.php) - Nonce verification and capability checks
- WordPress Configuration (
wp-config.php) - Essential wp-config.php hardening - HTTP Security Headers (
http-security-headers.php) - Browser security headers - Server Configuration (
apache.conf,nginx.conf) - Web server security rules - Database Security (
db-security.sql) - MySQL user privilege restrictions - File Permissions (
file-folder-permissions.sh) - WordPress file system security
- Security Logger (
security-logger.php) - Comprehensive security event monitoring - File Integrity Monitor (
file-integrity-monitor.php) - Automated file change detection - Incident Response (
incident-response-checklist.md) - Complete security Incident Response Checklist procedures
git clone https://github.com/yourusername/wc-security-beyond-plugins.git
cd wc-security-beyond-pluginsInclude the security files you need in your theme's functions.php or plugin:
// Add 2FA to your site
require_once 'path/to/custom-2fa-usage.php';
// Add security logging
$security_logger = new Security_Logger();
// Add file integrity monitoring
$file_monitor = new File_Integrity_Monitor();- Apache: Add contents of
apache.confto your.htaccessor virtual host - Nginx: Include
nginx.confrules in your server block - Database: Execute
db-security.sqlfor MySQL hardening
Complete two-factor authentication system with:
- Cryptographically secure secret generation
- RFC 6238 compliant TOTP algorithm
- WordPress user profile integration
- Login form integration
- Admin management interface
$twofa = new WP_Custom_2FA();
$secret = $twofa->generate_secret();
$is_valid = $twofa->verify_token($secret, $user_token);Monitor critical security events:
- Login attempts (successful/failed)
- User registrations
- Plugin activations
- Theme changes
- Admin actions
Automated detection of file modifications:
- WordPress core files monitoring
- Active theme/plugin monitoring
- Scheduled daily integrity checks
- Email alerts for changes
- Admin dashboard notifications
Prevent common vulnerabilities:
// SQL Injection Prevention
$wpdb->prepare('SELECT * FROM wp_posts WHERE title = %s', $user_input);
// XSS Prevention
echo esc_html($user_data);
echo '<a href="' . esc_url($url) . '">Link</a>';
// CSRF Protection
wp_verify_nonce($_POST['_wpnonce'], 'my_action');- Directory browsing disabled
- Sensitive file protection
- PHP execution blocked in uploads
- HTTP method restrictions
- Security headers
- Rate limiting for login attempts
- File access restrictions
- Security headers
- Method filtering
- Dedicated WordPress user
- Minimal required privileges
- No remote access
- Principle of least privilege
- Change Default Values: Update all placeholder passwords and secrets
- Review File Permissions: Ensure proper file/directory permissions
- Test Thoroughly: Validate all implementations in staging environment
- Monitor Logs: Regularly review security logs for suspicious activity
- Keep Updated: Stay current with WordPress security best practices
The login rate limiting examples should be complemented with:
- IP-based blocking for persistent attackers
- Progressive delays for repeated failures
- Whitelist for trusted IP addresses
- Provide backup codes for device loss scenarios
- Consider SMS or email backup methods
- Implement proper QR code generation for easy setup
- Add recovery mechanisms for locked accounts
This repository is maintained for educational and demonstration purposes. If you find security issues or have improvements:
- Security Issues: Please report privately via email
- Improvements: Submit pull requests with detailed explanations
- Documentation: Help improve examples and explanations
This project is released under the MIT License.
These implementations are for educational and demonstration purposes. While following security best practices, always:
- Conduct thorough security testing
- Review code for your specific use case
- Keep systems updated with security patches
- Consider professional security audits for production systems
This repository was created to accompany the "WordPress Security Beyond Plugins" talk, demonstrating that robust security can be implemented directly in WordPress without relying on third-party plugins. Each implementation showcases security measures that developers can adapt for their specific needs.
The goal is to empower WordPress developers with the knowledge and tools to implement comprehensive security measures.