Skip to content

New filter frm_recaptcha_verify_domain#2180

Closed
Crabcyborg wants to merge 1 commit into
masterfrom
new_filter_frm_recaptcha_verify_domain
Closed

New filter frm_recaptcha_verify_domain#2180
Crabcyborg wants to merge 1 commit into
masterfrom
new_filter_frm_recaptcha_verify_domain

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Dec 12, 2024

Related ticket https://secure.helpscout.net/conversation/2790461247/217923

Example usage,

add_filter(
	'frm_recaptcha_verify_domain',
	function() {
		return 'https://www.recaptcha.net';
	}
);

Pre-release
formidable-6.16.4b.zip

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 12, 2024

Walkthrough

The pull request modifies the set_endpoint method in the FrmRecaptchaSettings class to implement a filtering mechanism for the reCAPTCHA endpoint domain. A hardcoded URL is replaced with a dynamic construction that allows external code to modify the domain through a filter. The final endpoint is built by appending a specific path to the filtered domain, enhancing the flexibility of the configuration.

Changes

File Change Summary
classes/models/FrmRecaptchaSettings.php Modified the set_endpoint method to include a filtering mechanism for the reCAPTCHA endpoint domain.

Possibly related PRs

Suggested reviewers

  • garretlaxton
  • truongwp
  • AbdiTolesa

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
classes/models/FrmRecaptchaSettings.php (1)

19-24: Complete the filter documentation

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9e744e1 and d344e26.

📒 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:

  1. Properly validates that the filtered value is a string
  2. Uses HTTPS by default
  3. 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

Comment on lines +17 to +29
$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';
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';

@Crabcyborg Crabcyborg closed this Dec 13, 2024
@Crabcyborg
Copy link
Copy Markdown
Contributor Author

Crabcyborg commented Dec 13, 2024

It looks like we might not need this filter.

@Crabcyborg Crabcyborg deleted the new_filter_frm_recaptcha_verify_domain branch December 13, 2024 12:58
@Crabcyborg Crabcyborg removed this from the 6.17 milestone Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant