New filter frm_recaptcha_verify_domain#2180
Conversation
WalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
classes/models/FrmRecaptchaSettings.php (1)
19-24: Complete the filter documentationThe docblock needs the actual version number and better documentation of the filter's purpose and return value.
Update the docblock as follows:
/** - * @since x.x + * @since 6.x.x * + * Filters the domain used for reCAPTCHA verification requests. + * Useful for regions where Google services may be restricted. + * * @param string $domain The domain for reCAPTCHA verification (default: 'https://www.google.com') + * @return string The filtered domain. Must be a valid URL. */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
classes/models/FrmRecaptchaSettings.php(1 hunks)
🔇 Additional comments (1)
classes/models/FrmRecaptchaSettings.php (1)
17-29: Verify compatibility with recaptcha.net domain
The implementation should work with the alternative domain mentioned in the PR description.
Let's verify the filter usage with the example domain:
✅ Verification successful
Implementation is compatible with recaptcha.net domain
The implementation allows customization of the reCAPTCHA verification domain through the frm_recaptcha_verify_domain filter. The code:
- Properly validates that the filtered value is a string
- Uses HTTPS by default
- Maintains the correct endpoint path structure
Additionally, the codebase shows:
- No hardcoded dependencies on google.com domain
- Existing filter infrastructure for reCAPTCHA customization (e.g.,
frm_recaptcha_js_url,frm_recaptcha_lang) - Clean separation of domain and endpoint path
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if the codebase already uses recaptcha.net domain
# This helps verify if the new filter is needed and works as expected
# Search for any existing usage of recaptcha.net
rg -l 'recaptcha\.net'
# Search for any existing filters that might conflict
ast-grep --pattern 'apply_filters( $_, "recaptcha" )'
Length of output: 80
Script:
#!/bin/bash
# Let's try a broader search to understand reCAPTCHA implementation
# Search for reCAPTCHA related files
fd -t f -e php recaptcha
# Search for any reCAPTCHA related constants or configurations
rg -i "recaptcha" -g "*.php" -A 2
# Search for any existing filters related to reCAPTCHA with broader pattern
ast-grep --pattern 'apply_filters( "frm_recaptcha'
Length of output: 17399
| $domain = 'https://www.google.com'; | ||
|
|
||
| /** | ||
| * @since x.x | ||
| * | ||
| * @param string $domain | ||
| */ | ||
| $filtered_domain = apply_filters( 'frm_recaptcha_verify_domain', $domain ); | ||
| if ( is_string( $filtered_domain ) ) { | ||
| $domain = $filtered_domain; | ||
| } | ||
|
|
||
| $this->endpoint = $domain . '/recaptcha/api/siteverify'; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add URL validation and trailing slash handling
The implementation should validate the filtered domain URL and handle trailing slashes to prevent malformed URLs.
Consider this improved implementation:
- $domain = 'https://www.google.com';
+ $domain = 'https://www.google.com';
/**
* @since x.x
*
* @param string $domain
*/
$filtered_domain = apply_filters( 'frm_recaptcha_verify_domain', $domain );
- if ( is_string( $filtered_domain ) ) {
+ if ( is_string( $filtered_domain ) && filter_var( $filtered_domain, FILTER_VALIDATE_URL ) ) {
$domain = $filtered_domain;
}
- $this->endpoint = $domain . '/recaptcha/api/siteverify';
+ $this->endpoint = rtrim($domain, '/') . '/recaptcha/api/siteverify';📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| $domain = 'https://www.google.com'; | |
| /** | |
| * @since x.x | |
| * | |
| * @param string $domain | |
| */ | |
| $filtered_domain = apply_filters( 'frm_recaptcha_verify_domain', $domain ); | |
| if ( is_string( $filtered_domain ) ) { | |
| $domain = $filtered_domain; | |
| } | |
| $this->endpoint = $domain . '/recaptcha/api/siteverify'; | |
| $domain = 'https://www.google.com'; | |
| /** | |
| * @since x.x | |
| * | |
| * @param string $domain | |
| */ | |
| $filtered_domain = apply_filters( 'frm_recaptcha_verify_domain', $domain ); | |
| if ( is_string( $filtered_domain ) && filter_var( $filtered_domain, FILTER_VALIDATE_URL ) ) { | |
| $domain = $filtered_domain; | |
| } | |
| $this->endpoint = rtrim($domain, '/') . '/recaptcha/api/siteverify'; |
|
It looks like we might not need this filter. |
Related ticket https://secure.helpscout.net/conversation/2790461247/217923
Example usage,
Pre-release
formidable-6.16.4b.zip