-
Notifications
You must be signed in to change notification settings - Fork 8
Honeypot update #832
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: dev
Are you sure you want to change the base?
Honeypot update #832
Changes from 4 commits
e641c50
4acbcab
290606b
5865ce4
b60b7e3
363b7b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| namespace Cleantalk\Antispam\IntegrationsByClass; | ||
|
|
||
| use Cleantalk\ApbctWP\Honeypot; | ||
| use Cleantalk\ApbctWP\Variables\AltSessions; | ||
| use DOMDocument; | ||
|
|
||
| /** | ||
|
|
@@ -27,6 +28,9 @@ public function doPublicWork() | |
| global $apbct; | ||
| if ($apbct->settings['forms__search_test']) { | ||
| add_filter('get_search_form', array($this, 'apbctFormSearchAddFields'), 999); | ||
| // The block search form (core/search) is rendered by render_block_core_search() | ||
| // and does not fire get_search_form, so it is handled on its dedicated render hook. | ||
| add_filter('render_block_core/search', array($this, 'apbctFormSearchAddFields'), 999); | ||
| } | ||
| if ($this->isNativeSearchFormRequest()) { | ||
| // Default search | ||
|
|
@@ -127,6 +131,18 @@ public function testSpam($search) | |
| 'exception_action' => 0, | ||
| ); | ||
|
|
||
| // Honeypot, same approach as CF7 (see apbct_form__contactForm7__testSpam): when the honeypot field is | ||
| // enabled the search form always renders it, so read its value and set the status directly - | ||
| // empty is clean (1), filled is spam (0). With JS the value travels via alt-sessions (the field is | ||
| // stripped from the GET URL); without JS the field stays in the GET request. | ||
| if ( $apbct->settings['data__honeypot_field'] ) { | ||
| $cookie_name = apbct__get_cookie_prefix() . 'apbct_search_form__honeypot_value'; | ||
| $honeypot_value = $_GET['apbct__email_id__search_form'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Get::getString()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| ?? ( $_COOKIE[$cookie_name] ?? null ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Cookie::getString()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| ?? AltSessions::get('apbct_search_form__honeypot_value'); | ||
| $honeypot_value = (string)($honeypot_value ?? ''); | ||
| $data['honeypot_field'] = ( $honeypot_value === '' ) ? 1 : 0; | ||
|
|
||
| $base_call_result = apbct_base_call($data); | ||
|
|
||
| if ( isset($base_call_result['ct_result']) ) { | ||
|
|
||
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.
We must skip all the "GET" forms excepting the "get_search_form" hook.
This filter "render_block_core/search" may cause unexpected requests.
Discuss this change among the team due daily scrum , but be prepared to explain what exactly you wanted to do.