-
Notifications
You must be signed in to change notification settings - Fork 41
Antispam improvements #2285
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
Merged
Merged
Antispam improvements #2285
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
e290f02
Move honeypot setting and update honeypot field markup
truongwp 45a5f2e
Use JS to hide honeypot fields
truongwp bec48f8
Add stopforumspam support
truongwp 144f4e1
Complete stopforumspam check
truongwp 375d0aa
Add blacklist spam check
truongwp 37db53d
Reuse existing blacklist_check() method
truongwp 5d64fc6
Add custom blacklist and whitelist settings
truongwp a350faf
Add WP spam comment check setting
truongwp 15d63c4
Fix blacklist check doesn't work at some cases
truongwp 52ee754
Complete wp spam comment check
truongwp 2a990b4
Remove unused code
3553510
Improving the antispam code
truongwp 5502046
Improve blacklist IP check
truongwp ca4ca9d
Update blacklist check
truongwp 912073c
Completed blacklist check improvement
truongwp 68e977d
Clean code
truongwp edd53ee
Update unit tests for honeypot
truongwp b4a235e
Fix some unit tests errors
truongwp b10602a
Adding unit tests for blacklist check
truongwp a7a2f39
Complete unit tests for blacklist data
truongwp 4597c3d
Fix Psalm and PHPCS
truongwp a9a04a5
Fix PHPStan and PHPCS
truongwp 5119f38
Merge branch 'master' into antispam-improvements
truongwp 57e29bf
Fix PHPStan
truongwp 867468e
Fix workflow
truongwp ed74b78
Fix error in unit tests
truongwp 3a0247b
Add doc comments
truongwp 64d97a7
Remove debug code
truongwp ac62c29
Fix PHPStan
truongwp e525e71
Fix Psalm
truongwp 42316ed
Fix typos check
truongwp 010838d
Fix unit tests
truongwp 1a22b52
Fix phpunit
truongwp fdafc93
Update classes/models/FrmHoneypot.php
truongwp f6cffef
Update get spam comments for better performance
truongwp ed58657
Fix PHP notice
truongwp 833b929
Support regex spam check
truongwp 8ecb484
Fix stopforumspam
truongwp 060af66
Fix use WP spam comment check
truongwp 0c0796c
Remove TODO
truongwp e815b10
Merge branch 'master' into antispam-improvements
truongwp b79ab9e
Add filter hook for whitelist IP
truongwp b2c2c4b
Rename blacklist folder
truongwp b2eee42
Update honeypot tooltip
truongwp f1c45d5
Change setting label
truongwp e0ad9eb
Rename whitelist IP in code
truongwp 172b21b
Use denylist instead of blacklist
truongwp 64440c5
Fix unit tests
truongwp 1694721
Rename class
truongwp 46ad799
Update IP check to match IP CIDR format
truongwp 640da78
Update stopforumspam tooltip
truongwp c735512
Add some filters to stopforumspam request
truongwp 36d7f8f
Add IPv6 loopback address to allowed list
truongwp 310cfac
Handle stopforumspam failed request
truongwp 6b99949
Fix unit tests
truongwp 05c6810
Only support IPv4 for CIDR check
truongwp 124872c
Add splorp WP comment denylist
truongwp 12fecdb
Fix unit tests
truongwp 95d13ab
Fix phpcs
truongwp 3e37e71
Fix phpcs
truongwp 01d8a48
Add missing denylist-ip test file
truongwp 8fd4d90
Merge branch 'master' into antispam-improvements
truongwp 036c2fc
Fix accessibility issue
truongwp d7ed1a3
Use number input for reCAPTCHA threshold setting
truongwp 3336b08
Update stopforumspam tooltip
truongwp 146c723
Skip Splord denylist for users with create entries permisison
truongwp 3a5c129
Add unit tests
truongwp c8bf541
Support custom spam message for each check
truongwp 2a3a82d
Prevent honeypot field is tabbed through
truongwp b28f7e6
Prevent autofilling to honeypot field
truongwp c52efad
Fix PHP notice related to form_id
truongwp 8875269
Print CSS for honeypot field if form is loaded via API
truongwp 1706f1c
Support skipping field types for each denylist
truongwp d611f6c
Skip Splord check for file type
truongwp dfdedd0
Fix phpcs
truongwp 085afb5
Fix PHPStan
truongwp 1535ecd
Fix phpcs
truongwp 04932ce
Ignore deprecated function for now (Psalm)
Crabcyborg d7e0ad7
Merge branch 'master' into antispam-improvements
Crabcyborg d052044
Fix e2e test
Crabcyborg 21bf0ff
Fix another e2e test line
Crabcyborg 1a4e7ea
Fix unit tests
truongwp ceda63a
Use esc_html()
truongwp 1ee99e0
Move honeypot field to the top of fields
truongwp a9be6ff
Remove unnecessary for attribute
truongwp 62e0972
Revert moving honeypot field
truongwp 276bc20
Add more doc comments
truongwp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
| /** | ||
| * Anti-spam controller | ||
| * | ||
| * @package Formidable | ||
| * @since x.x | ||
| */ | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| die( 'You are not allowed to call this page directly.' ); | ||
| } | ||
|
|
||
| class FrmAntiSpamController { | ||
|
|
||
| /** | ||
| * Checks if given entry values is spam. | ||
| * | ||
| * @param array $values Entry values. | ||
| * | ||
| * @return bool|string Return spam message if is spam or `false` if is not spam. | ||
| */ | ||
| public static function is_spam( $values ) { | ||
| $methods = array( | ||
| 'contains_wp_disallowed_words', | ||
| 'is_denylist_spam', | ||
| 'is_stopforumspam_spam', | ||
| 'is_wp_comment_spam', | ||
| ); | ||
|
|
||
| foreach ( $methods as $method ) { | ||
| if ( ! is_callable( array( __CLASS__, $method ) ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $is_spam = call_user_func( array( __CLASS__, $method ), $values ); | ||
| if ( $is_spam ) { | ||
| return $is_spam; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Checks spam using stopforumspam API. | ||
| * | ||
| * @param array $values Entry values. | ||
| * | ||
| * @return bool|string Return spam message if is spam or `false` if is not spam. | ||
| */ | ||
| private static function is_stopforumspam_spam( $values ) { | ||
| $spam_check = new FrmSpamCheckStopForumSpam( $values ); | ||
| return $spam_check->is_spam(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks spam using WordPress spam comments. | ||
| * | ||
| * @param array $values Entry values. | ||
| * | ||
| * @return bool|string Return spam message if is spam or `false` if is not spam. | ||
| */ | ||
| private static function is_wp_comment_spam( $values ) { | ||
| $spam_check = new FrmSpamCheckUseWPComments( $values ); | ||
| return $spam_check->is_spam(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks spam using WordPress disallowed words. | ||
| * | ||
| * @param array $values Entry values. | ||
| * | ||
| * @return bool|string Return spam message if is spam or `false` if is not spam. | ||
| */ | ||
| public static function contains_wp_disallowed_words( $values ) { | ||
| $spam_check = new FrmSpamCheckWPDisallowedWords( $values ); | ||
| return $spam_check->is_spam(); | ||
| } | ||
|
|
||
| /** | ||
| * Checks spam using denylist. | ||
| * | ||
| * @param array $values Entry values. | ||
| * | ||
| * @return bool|string Return spam message if is spam or `false` if is not spam. | ||
| */ | ||
| public static function is_denylist_spam( $values ) { | ||
| $spam_check = new FrmSpamCheckDenylist( $values ); | ||
| return $spam_check->is_spam(); | ||
| } | ||
|
|
||
| /** | ||
| * Gets spam message. | ||
| * | ||
| * @return string | ||
| */ | ||
| public static function get_default_spam_message() { | ||
| return __( 'Your entry appears to be spam!', 'formidable' ); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts email addresses from values. | ||
| * | ||
| * @param array $values Values to check. | ||
| * @return string[] | ||
| */ | ||
| public static function extract_emails_from_values( $values ) { | ||
| $values = FrmAppHelper::maybe_json_encode( $values ); | ||
| preg_match_all( '/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i', $values, $matches ); | ||
| return $matches[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Gets allowed IP addresses. | ||
| * | ||
| * @return string[] | ||
| */ | ||
| public static function get_allowed_ips() { | ||
| /** | ||
| * Filter the allowed IP addresses. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @params string[] $allowed_ips Allowed IP addresses. | ||
| */ | ||
| return apply_filters( 'frm_allowed_ips', array( '', '127.0.0.1', '::1' ) ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.