Skip to content

Neue Standard-Werte für Timing#89

Merged
AWqxKAWERbXo merged 2 commits intomainfrom
alxndr-w-patch-1
Jun 23, 2025
Merged

Neue Standard-Werte für Timing#89
AWqxKAWERbXo merged 2 commits intomainfrom
alxndr-w-patch-1

Conversation

@AWqxKAWERbXo
Copy link
Contributor

@AWqxKAWERbXo AWqxKAWERbXo commented Jun 23, 2025

Praxiswerte erprobt von @Pixeldaniel

Summary by CodeRabbit

  • New Features

    • Integrated StopForumSpam API check to enhance spam protection, blocking submissions from flagged IP addresses if enabled in settings.
  • Bug Fixes

    • Improved reliability of spam protection timers by updating default configuration values.
  • Style

    • Applied consistent code formatting and spacing across templates and configuration files.
  • Documentation

    • Minor formatting adjustments in documentation and settings pages for clarity.

@AWqxKAWERbXo AWqxKAWERbXo self-assigned this Jun 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 23, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce a StopForumSpam API integration to the spam protection logic, update code formatting for consistency across several files, and adjust default configuration values and versioning in the package manifest. No public interfaces or method signatures were altered, and no logic changes were made outside the spam protection enhancement.

Changes

File(s) Change Summary
lib/yform/value/spam_protection.php Code style improvements; adds StopForumSpam API check to block flagged IPs during spam validation.
package.yml Version updated to 1.2.6; increases default timer values for spam protection.
boot.php Adds a blank line after the opening PHP tag.
pages/yform.spam_protection.docs.php Switches double to single quotes in title assignment.
pages/yform.spam_protection.settings.php Removes extra blank line, switches to single quotes for checkbox option, trims whitespace.
ytemplates/bootstrap/value.spam_protection.tpl.php Adjusts PHP formatting for nonce output, spaces in method calls and concatenation.
ytemplates/classic/value.spam_protection.tpl.php Same as above: formatting and spacing improvements for nonce output in PHP code.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Form
    participant SpamProtection
    participant StopForumSpamAPI

    User->>Form: Submits form
    Form->>SpamProtection: Validate submission
    SpamProtection->>SpamProtection: Perform honeypot, timing, IP checks
    alt use_stopforumspam enabled
        SpamProtection->>StopForumSpamAPI: Query IP status
        StopForumSpamAPI-->>SpamProtection: Return XML response
        alt IP appears as spam
            SpamProtection->>Form: Set warning, block submission
            SpamProtection->>SpamProtection: Log event
        else IP not flagged
            SpamProtection->>Form: Continue validation
        end
    else
        SpamProtection->>Form: Continue validation
    end
    Form-->>User: Show result
Loading

Poem

A hop and a skip, we check for spam,
With StopForumSpam, we tighten the dam.
Timers tick longer, the bots feel the squeeze,
Formatting neat, code’s now a breeze.
Version hops forward, protection anew—
From this rabbit to you: safe forms, woohoo! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f127a9 and 69b97d3.

📒 Files selected for processing (7)
  • boot.php (1 hunks)
  • lib/yform/value/spam_protection.php (1 hunks)
  • package.yml (2 hunks)
  • pages/yform.spam_protection.docs.php (1 hunks)
  • pages/yform.spam_protection.settings.php (1 hunks)
  • ytemplates/bootstrap/value.spam_protection.tpl.php (2 hunks)
  • ytemplates/classic/value.spam_protection.tpl.php (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@AWqxKAWERbXo AWqxKAWERbXo added the enhancement New feature or request label Jun 23, 2025
@AWqxKAWERbXo AWqxKAWERbXo merged commit eb4ef0f into main Jun 23, 2025
1 check was pending
@AWqxKAWERbXo AWqxKAWERbXo deleted the alxndr-w-patch-1 branch June 23, 2025 15:36
Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f127a9 and 69b97d3.

📒 Files selected for processing (7)
  • boot.php (1 hunks)
  • lib/yform/value/spam_protection.php (1 hunks)
  • package.yml (2 hunks)
  • pages/yform.spam_protection.docs.php (1 hunks)
  • pages/yform.spam_protection.settings.php (1 hunks)
  • ytemplates/bootstrap/value.spam_protection.tpl.php (2 hunks)
  • ytemplates/classic/value.spam_protection.tpl.php (2 hunks)
🔇 Additional comments (11)
boot.php (1)

2-2: Skip formatting change
The added blank line is a non-functional formatting adjustment.

package.yml (1)

29-30: Updated default timing values applied
The new standard defaults for timer_session (5) and timer_form (10) align with the tested values from the PR objectives.

pages/yform.spam_protection.docs.php (1)

15-15: Consistent quoting style
Changed to single quotes for the title string to match project-wide style conventions.

pages/yform.spam_protection.settings.php (1)

64-68: Stylistic updates for StopForumSpam checkbox
The checkbox field strings now consistently use single quotes, and trailing whitespace was cleaned up. Logic remains unchanged.

ytemplates/bootstrap/value.spam_protection.tpl.php (2)

15-17: Nonce attribute formatting consistency
Refactored to use spaced concatenation for the nonce attribute. Behavior is unchanged.


34-36: Nonce attribute formatting consistency
Mirrored the same formatting improvements for the <script> tag.

ytemplates/classic/value.spam_protection.tpl.php (2)

15-16: LGTM! Style improvement for consistency.

The added spacing after commas in the method_exists call improves readability and maintains consistent code style.


34-35: LGTM! Consistent style formatting.

Good consistency with the previous method_exists call formatting.

lib/yform/value/spam_protection.php (3)

9-13: LGTM! Improved code style consistency.

The spacing improvements around type casts and string concatenation enhance readability.


20-20: LGTM! Consistent null comparison style.

Using null !== follows consistent comparison patterns.


28-29: LGTM! Improved string comparison consistency.

Using strict equality (===) and consistent string formatting is good practice.

Comment on lines +74 to 86
if (trim((string) rex_config::get('yform_spam_protection', 'use_stopforumspam'), '|')) {
$result = file_get_contents('http://api.stopforumspam.org/api?ip=' . $_SERVER['REMOTE_ADDR']);
if ($result) {
$doc = new DOMDocument();
$doc->loadXML($result);
if ('yes' == $doc->getElementsByTagName('appears')[0]->nodeValue) {
$this->params['warning'][$this->getId()] = $this->params['error_class'];
$this->params['warning_messages'][$this->getId()] = '{{ use_stopforumspam_ip_is_locked }}';
$log[] = 'Die IP Adresse ist gesperrt.' . rex_request($this->getFieldId());
rex_logger::factory()->log('info', 'Stop Forum Spam' . $_SERVER['REMOTE_ADDR'], [], __FILE__, __LINE__);
}
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider implementing caching for StopForumSpam API responses.

The current implementation makes an API call on every form submission, which could impact performance and may hit rate limits. Consider implementing a caching mechanism to store results for a reasonable time period (e.g., 1 hour).

Consider adding a caching layer:

// Check cache first
$cache_key = 'stopforumspam_' . md5($_SERVER['REMOTE_ADDR']);
$cached_result = rex_config::get('yform_spam_protection', $cache_key);
$cache_time = rex_config::get('yform_spam_protection', $cache_key . '_time', 0);

if ($cache_time > (time() - 3600)) { // 1 hour cache
    $is_spam = $cached_result;
} else {
    // Make API call and cache result
    // ... API call logic ...
    rex_config::set('yform_spam_protection', $cache_key, $is_spam);
    rex_config::set('yform_spam_protection', $cache_key . '_time', time());
}
🤖 Prompt for AI Agents
In lib/yform/value/spam_protection.php around lines 74 to 86, the code calls the
StopForumSpam API on every form submission, which can degrade performance and
risk hitting rate limits. To fix this, implement a caching mechanism that stores
the API response for each IP address for about one hour. First, generate a cache
key based on the IP, then check if a cached result exists and is still valid
(within the last hour). If valid, use the cached result; otherwise, perform the
API call, parse the response, and store the result and current timestamp in the
cache for future use.

⚠️ Potential issue

Critical security and performance issues in StopForumSpam integration.

The StopForumSpam API integration has several concerning issues:

  1. Security: Using HTTP instead of HTTPS exposes requests to interception
  2. Reliability: file_get_contents() lacks timeout configuration and proper error handling
  3. Performance: Blocking HTTP requests during form validation will slow down user experience
  4. XML Security: No validation before parsing potentially malicious XML content
  5. Error Handling: Missing error handling for network failures and malformed responses

Apply this diff to address the security and reliability concerns:

-                    if (trim((string) rex_config::get('yform_spam_protection', 'use_stopforumspam'), '|')) {
-                        $result = file_get_contents('http://api.stopforumspam.org/api?ip=' . $_SERVER['REMOTE_ADDR']);
-                        if ($result) {
-                            $doc = new DOMDocument();
-                            $doc->loadXML($result);
-                            if ('yes' == $doc->getElementsByTagName('appears')[0]->nodeValue) {
-                                $this->params['warning'][$this->getId()] = $this->params['error_class'];
-                                $this->params['warning_messages'][$this->getId()] = '{{ use_stopforumspam_ip_is_locked }}';
-                                $log[] = 'Die IP Adresse ist gesperrt.' . rex_request($this->getFieldId());
-                                rex_logger::factory()->log('info', 'Stop Forum Spam' . $_SERVER['REMOTE_ADDR'], [], __FILE__, __LINE__);
-                            }
-                        }
+                    if (trim((string) rex_config::get('yform_spam_protection', 'use_stopforumspam'), '|')) {
+                        $context = stream_context_create([
+                            'http' => [
+                                'timeout' => 5,
+                                'method' => 'GET',
+                                'user_agent' => 'YForm-SpamProtection/1.0'
+                            ]
+                        ]);
+                        
+                        $result = @file_get_contents('https://api.stopforumspam.org/api?ip=' . urlencode($_SERVER['REMOTE_ADDR']), false, $context);
+                        if ($result !== false && !empty($result)) {
+                            try {
+                                $doc = new DOMDocument();
+                                libxml_use_internal_errors(true);
+                                if ($doc->loadXML($result)) {
+                                    $appears = $doc->getElementsByTagName('appears');
+                                    if ($appears->length > 0 && 'yes' === $appears[0]->nodeValue) {
+                                        $this->params['warning'][$this->getId()] = $this->params['error_class'];
+                                        $this->params['warning_messages'][$this->getId()] = '{{ use_stopforumspam_ip_is_locked }}';
+                                        $log[] = 'Die IP Adresse ist gesperrt.';
+                                        rex_logger::factory()->log('info', 'Stop Forum Spam blocked IP: ' . $_SERVER['REMOTE_ADDR'], [], __FILE__, __LINE__);
+                                    }
+                                }
+                            } catch (Exception $e) {
+                                rex_logger::factory()->log('error', 'StopForumSpam API error: ' . $e->getMessage(), [], __FILE__, __LINE__);
+                            }
+                        }
                     }
📝 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
if (trim((string) rex_config::get('yform_spam_protection', 'use_stopforumspam'), '|')) {
$result = file_get_contents('http://api.stopforumspam.org/api?ip=' . $_SERVER['REMOTE_ADDR']);
if ($result) {
$doc = new DOMDocument();
$doc->loadXML($result);
if ('yes' == $doc->getElementsByTagName('appears')[0]->nodeValue) {
$this->params['warning'][$this->getId()] = $this->params['error_class'];
$this->params['warning_messages'][$this->getId()] = '{{ use_stopforumspam_ip_is_locked }}';
$log[] = 'Die IP Adresse ist gesperrt.' . rex_request($this->getFieldId());
rex_logger::factory()->log('info', 'Stop Forum Spam' . $_SERVER['REMOTE_ADDR'], [], __FILE__, __LINE__);
}
}
}
if (trim((string) rex_config::get('yform_spam_protection', 'use_stopforumspam'), '|')) {
$context = stream_context_create([
'http' => [
'timeout' => 5,
'method' => 'GET',
'user_agent' => 'YForm-SpamProtection/1.0',
],
]);
$result = @file_get_contents(
'https://api.stopforumspam.org/api?ip=' . urlencode($_SERVER['REMOTE_ADDR']),
false,
$context
);
if ($result !== false && !empty($result)) {
try {
$doc = new DOMDocument();
libxml_use_internal_errors(true);
if ($doc->loadXML($result)) {
$appears = $doc->getElementsByTagName('appears');
if ($appears->length > 0 && 'yes' === $appears[0]->nodeValue) {
$this->params['warning'][$this->getId()] = $this->params['error_class'];
$this->params['warning_messages'][$this->getId()] = '{{ use_stopforumspam_ip_is_locked }}';
$log[] = 'Die IP Adresse ist gesperrt.';
rex_logger::factory()->log(
'info',
'Stop Forum Spam blocked IP: ' . $_SERVER['REMOTE_ADDR'],
[],
__FILE__,
__LINE__
);
}
}
} catch (Exception $e) {
rex_logger::factory()->log(
'error',
'StopForumSpam API error: ' . $e->getMessage(),
[],
__FILE__,
__LINE__
);
}
}
}
🤖 Prompt for AI Agents
In lib/yform/value/spam_protection.php lines 74 to 86, replace the HTTP URL with
HTTPS to secure the API request, switch from file_get_contents() to a cURL
request with a timeout and error handling to avoid blocking and improve
reliability, validate the XML response before parsing to prevent XML injection
attacks, and add try-catch or conditional checks to handle network failures and
malformed responses gracefully without breaking the form validation flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants