Skip to content

Commit dcec66c

Browse files
committed
Add low-priority enhancements and polish
This commit implements 5 low-priority improvements to enhance documentation, activation handling, and overall plugin polish: 1. Improve GitHub update checker caching strategy - Increased cache duration from 6 to 12 hours (configurable constant) - Added debug logging for cache operations - Better error handling with structured logging - Improved handling of API failures and edge cases 2. Add activation/deactivation logic improvements - PHP version requirement check (7.2+) on activation - WordPress version requirement check (5.0+) on activation - Prevent settings overwrite on re-activation - Track activation timestamp and version - Clear options cache on deactivation - Comprehensive logging of activation/deactivation events 3. Complete internationalization (i18n) - Wrapped all wp_die() error messages in translation functions - Added text domain to all user-facing strings - Improved consistency across OIDC and SAML error messages - Plugin now fully translatable via .po/.mo files 4. Add CHANGELOG.md file - Comprehensive changelog following Keep a Changelog format - Documents all versions from 1.0.0 to current - Includes security notices and upgrade notes - Categorized changes (Added, Changed, Fixed, Security) 5. Enhance inline documentation - Added detailed PHPDoc blocks with @SInCE tags - Included usage examples in docblocks - Better parameter and return value documentation - Enhanced class-level documentation - Improved method descriptions with context These changes improve the overall polish and maintainability of the plugin without affecting functionality.
1 parent 8934c92 commit dcec66c

File tree

5 files changed

+272
-49
lines changed

5 files changed

+272
-49
lines changed

CHANGELOG.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Changelog
2+
3+
All notable changes to the Cloudflare Zero Trust Login for WordPress plugin will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- Centralized logging system with CFZT_Logger class
12+
- User helper class for consolidated user management
13+
- Type hints for improved code quality and IDE support
14+
- Class constants for magic strings (auth methods, app types, etc.)
15+
- Options caching to reduce database queries
16+
- PHP and WordPress version checking on activation
17+
- Activation timestamp tracking
18+
- Improved GitHub update checker with configurable cache duration
19+
20+
### Changed
21+
- Improved code organization by extracting duplicate user creation logic
22+
- Enhanced activation/deactivation hooks with proper cleanup
23+
- Increased GitHub update cache from 6 to 12 hours
24+
- Better error handling with structured logging context
25+
26+
### Fixed
27+
- Version mismatch between plugin header and constant
28+
- Encryption nonce now uses truly random values instead of wp_create_nonce()
29+
- All $_SERVER superglobal access now properly sanitized
30+
- Internationalization completed for all user-facing error messages
31+
32+
### Security
33+
- **CRITICAL**: Documented SAML signature validation limitation (NOT production-ready)
34+
- Added security warnings to SAML implementation
35+
- Improved sanitization across all components
36+
37+
## [1.0.2] - 2025-10-23
38+
39+
### Changed
40+
- Manual update feature improvements
41+
- Updated .gitignore
42+
43+
## [1.0.1] - 2025-10-20
44+
45+
### Changed
46+
- Initial public release refinements
47+
48+
## [1.0.0] - 2025-10-15
49+
50+
### Added
51+
- Initial release
52+
- OIDC (OpenID Connect) authentication with Cloudflare Zero Trust
53+
- Experimental SAML authentication support
54+
- Support for both SaaS and Self-hosted Cloudflare applications
55+
- Dual login modes (Primary and Secondary)
56+
- Automatic user creation with configurable roles
57+
- AES-256-CBC encryption for credentials (with fallback)
58+
- Rate limiting (10 attempts per 5 minutes)
59+
- Session protection with fingerprinting
60+
- Security headers on login pages
61+
- GitHub-based auto-update system
62+
- Environment variable support for credentials
63+
- Comprehensive admin settings interface
64+
- Authentication logging capability
65+
- SAML endpoints (ACS, SLS, metadata)
66+
- Login page UI modifications
67+
68+
### Security
69+
- Client secret encryption using WordPress salts
70+
- Rate limiting to prevent brute force attacks
71+
- Session ID regeneration after login
72+
- Security headers (CSP, X-Frame-Options, etc.)
73+
- Nonce verification for state parameters
74+
- CSRF protection
75+
76+
---
77+
78+
## Version History Summary
79+
80+
- **1.0.2**: Current release with manual update improvements
81+
- **1.0.1**: Initial public release refinements
82+
- **1.0.0**: Initial release with OIDC and experimental SAML support
83+
84+
---
85+
86+
## Upgrade Notes
87+
88+
### Upgrading to Future Versions
89+
90+
When upgrading, the plugin will:
91+
- Preserve your existing settings
92+
- Automatically flush rewrite rules
93+
- Clear cached transients
94+
- Not delete any user data or metadata
95+
96+
### Important Notes
97+
98+
- **SAML Support**: SAML authentication does not perform cryptographic signature validation and should NOT be used in production. Use OIDC for production deployments.
99+
- **PHP Requirements**: Requires PHP 7.2+ and WordPress 5.0+
100+
- **OpenSSL Recommended**: For proper credential encryption
101+
102+
---
103+
104+
## Links
105+
106+
- [GitHub Repository](https://github.com/cjscrofani/cloudflare-zero-trust-wordpress)
107+
- [Issue Tracker](https://github.com/cjscrofani/cloudflare-zero-trust-wordpress/issues)
108+
- [Cloudflare Zero Trust Documentation](https://developers.cloudflare.com/cloudflare-one/)
109+

class-cfzt-saml.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ private function create_authn_request() {
175175
private function handle_acs() {
176176
// Rate limiting
177177
if (!$this->security->check_rate_limit()) {
178-
wp_die('Too many authentication attempts. Please try again in 5 minutes.', 'Rate Limit Exceeded', array('response' => 429));
178+
wp_die(
179+
__('Too many authentication attempts. Please try again in 5 minutes.', 'cf-zero-trust'),
180+
__('Rate Limit Exceeded', 'cf-zero-trust'),
181+
array('response' => 429)
182+
);
179183
}
180-
184+
181185
if (!isset($_POST['SAMLResponse'])) {
182186
$this->log_authentication('unknown', false, 'No SAML response received');
183-
wp_die('No SAML response received.');
187+
wp_die(__('No SAML response received.', 'cf-zero-trust'));
184188
}
185189

186190
$saml_response = base64_decode($_POST['SAMLResponse']);
@@ -191,7 +195,7 @@ private function handle_acs() {
191195

192196
if (!$user_data) {
193197
$this->log_authentication('unknown', false, 'Invalid SAML response');
194-
wp_die('Invalid SAML response. Please check your Cloudflare Zero Trust configuration.');
198+
wp_die(__('Invalid SAML response. Please check your Cloudflare Zero Trust configuration.', 'cf-zero-trust'));
195199
}
196200

197201
// Authenticate user
@@ -385,7 +389,7 @@ private function authenticate_user($user_data, $redirect_to = '') {
385389
$email = $user_data['email'];
386390
if (empty($email)) {
387391
$this->log_authentication('unknown', false, 'No email in SAML assertion');
388-
wp_die('No email address provided in SAML assertion.');
392+
wp_die(__('No email address provided in SAML assertion.', 'cf-zero-trust'));
389393
}
390394

391395
// Check if user exists
@@ -421,7 +425,7 @@ private function authenticate_user($user_data, $redirect_to = '') {
421425
exit;
422426
} else {
423427
$this->log_authentication($email, false, 'User creation disabled or failed');
424-
wp_die('User authentication failed. Auto-creation may be disabled or you may not have permission to access this site.');
428+
wp_die(__('User authentication failed. Auto-creation may be disabled or you may not have permission to access this site.', 'cf-zero-trust'));
425429
}
426430
}
427431

includes/class-cfzt-auth.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,31 +129,35 @@ public function handle_callback() {
129129

130130
// Rate limiting
131131
if (!$this->security->check_rate_limit()) {
132-
wp_die('Too many authentication attempts. Please try again in 5 minutes.', 'Rate Limit Exceeded', array('response' => 429));
132+
wp_die(
133+
__('Too many authentication attempts. Please try again in 5 minutes.', 'cf-zero-trust'),
134+
__('Rate Limit Exceeded', 'cf-zero-trust'),
135+
array('response' => 429)
136+
);
133137
}
134-
138+
135139
// Verify state
136140
$state = sanitize_text_field($_GET['state']);
137141
if (!get_transient('cfzt_auth_state_' . $state)) {
138142
$this->log_authentication('unknown', false, 'Invalid state parameter');
139-
wp_die('Invalid state parameter');
143+
wp_die(__('Invalid state parameter', 'cf-zero-trust'));
140144
}
141145
delete_transient('cfzt_auth_state_' . $state);
142-
146+
143147
// Exchange code for token
144148
$token_data = $this->exchange_code_for_token(sanitize_text_field($_GET['code']));
145-
149+
146150
if (!$token_data || !isset($token_data['access_token'])) {
147151
$this->log_authentication('unknown', false, 'Token exchange failed');
148-
wp_die('Failed to exchange authorization code. Please check your Cloudflare Zero Trust configuration.');
152+
wp_die(__('Failed to exchange authorization code. Please check your Cloudflare Zero Trust configuration.', 'cf-zero-trust'));
149153
}
150-
154+
151155
// Get user info
152156
$user_info = $this->get_user_info($token_data['access_token']);
153-
157+
154158
if (!$user_info) {
155159
$this->log_authentication('unknown', false, 'Failed to retrieve user info');
156-
wp_die('Failed to retrieve user information. Check your error logs for details.');
160+
wp_die(__('Failed to retrieve user information. Check your error logs for details.', 'cf-zero-trust'));
157161
}
158162

159163
// Authenticate user
@@ -279,7 +283,7 @@ private function authenticate_user($user_info) {
279283

280284
if (empty($email)) {
281285
$this->log_authentication('unknown', false, 'No email provided');
282-
wp_die('No email address provided by Cloudflare Zero Trust.');
286+
wp_die(__('No email address provided by Cloudflare Zero Trust.', 'cf-zero-trust'));
283287
}
284288

285289
// Check if user exists
@@ -312,7 +316,7 @@ private function authenticate_user($user_info) {
312316
exit;
313317
} else {
314318
$this->log_authentication($email, false, 'User creation disabled or failed');
315-
wp_die('User authentication failed. Auto-creation may be disabled or you may not have permission to access this site.');
319+
wp_die(__('User authentication failed. Auto-creation may be disabled or you may not have permission to access this site.', 'cf-zero-trust'));
316320
}
317321
}
318322

0 commit comments

Comments
 (0)