-
-
Notifications
You must be signed in to change notification settings - Fork 406
增加vaptcha对忘记密码页面和注册界面的支持,修复ip因为获取到x_forwarded_for多个代理ip而导致vaptcha不可用 #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3362,6 +3362,8 @@ function vaptchaInit() | |||||||||||||||||||||
| echo $vaptcha->script(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| add_action('login_form', 'vaptchaInit'); | ||||||||||||||||||||||
| add_action('register_form', 'vaptchaInit'); | ||||||||||||||||||||||
| add_action('lostpassword_form', 'vaptchaInit'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function checkVaptchaAction($user) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
|
|
@@ -3399,6 +3401,81 @@ function checkVaptchaAction($user) | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| add_filter('authenticate', 'checkVaptchaAction', 20, 3); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function Vaptcha_lostpassword_CHECK($errors) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if (empty($_POST)) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return false; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| return false; | |
| return $errors; |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing space after error code identifier 'invalid_vaptcha '. Remove the trailing space to make it 'invalid_vaptcha' for consistency.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication between this function and checkVaptchaAction (lines 3368-3402). The only differences are in line 3409 (return value) and line 3413 (error code). Consider extracting the common validation logic into a shared helper function to improve maintainability and reduce code duplication.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function name should follow the codebase naming convention. Change Vaptcha_registration_CHECK to vaptcha_registration_check to match the style used by similar functions like registration_CAPTCHA_CHECK, turnstile_registration_check, and other captcha verification functions in this file.
| function Vaptcha_registration_CHECK($errors, $sanitized_user_login, $user_email) | |
| function vaptcha_registration_check($errors, $sanitized_user_login, $user_email) |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before concatenation operator. The error message should be '<strong>错误</strong>:非法数据' . $errorcode with spaces around the . operator for better readability and consistency with PHP coding standards.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication between this function and checkVaptchaAction (lines 3368-3402). The validation logic is nearly identical. Consider extracting the common validation logic into a shared helper function to improve maintainability and reduce code duplication.
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delimiter handling uses pipe character | but HTTP_X_FORWARDED_FOR typically uses commas (,) as separators, not pipes. The str_replace(',', '|', $ip) converts commas to pipes and then explodes on pipes, which is unnecessarily convoluted. Consider simplifying to: $ip_array = explode(',', $ip); return apply_filters('wpb_get_ip', trim($ip_array[0]));
| $ip2 = explode('|', str_replace(',', '|', $ip)); | |
| return apply_filters('wpb_get_ip', trim($ip2[0])); //解决HTTP_X_FORWARDED_FOR获取到代理地址而导致人机验证不通过 | |
| $ip_array = explode(',', $ip); | |
| return apply_filters('wpb_get_ip', trim($ip_array[0])); //解决HTTP_X_FORWARDED_FOR获取到代理地址而导致人机验证不通过 |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function assumes HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR always contain valid IP addresses, but these headers can be spoofed by clients. While this PR fixes the issue of multiple proxy IPs, consider adding validation to ensure the extracted IP is actually a valid IP address using filter_var($ip, FILTER_VALIDATE_IP) before returning it.
| return apply_filters('wpb_get_ip', trim($ip2[0])); //解决HTTP_X_FORWARDED_FOR获取到代理地址而导致人机验证不通过 | |
| $user_ip = trim($ip2[0]); | |
| if (!filter_var($user_ip, FILTER_VALIDATE_IP)) { | |
| $user_ip = ''; | |
| } | |
| return apply_filters('wpb_get_ip', $user_ip); //解决HTTP_X_FORWARDED_FOR获取到代理地址而导致人机验证不通过 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function name should follow the codebase naming convention. Change
Vaptcha_lostpassword_CHECKtovaptcha_lostpassword_checkto match the style used by similar functions likelostpassword_CHECK,turnstile_lostpassword_check, and other captcha verification functions in this file.