Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion classes/models/FrmRecaptchaSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ class FrmRecaptchaSettings extends FrmFieldCaptchaSettings {
* @return void
*/
protected function set_endpoint() {
$this->endpoint = 'https://www.google.com/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 ) ) {
$domain = $filtered_domain;
}

$this->endpoint = $domain . '/recaptcha/api/siteverify';
Comment on lines +17 to +29
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Suggested change
$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';

}

/**
Expand Down